Skip to content

Commit

Permalink
Merge pull request #52 from waggle-sensor/add-fields
Browse files Browse the repository at this point in the history
Added fields to api/v-beta/nodes/
  • Loading branch information
FranciscoLozCoding authored May 23, 2024
2 parents 25ffdca + 7681d55 commit 3d70805
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 6 deletions.
2 changes: 1 addition & 1 deletion manifests/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,8 @@ class NodeAdmin(nested_admin.NestedModelAdmin):
"phase",
"type",
"project",
"partner",
"focus",
"partner",
"notes",
"tags",
"registered_at",
Expand Down
6 changes: 6 additions & 0 deletions manifests/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -444,6 +444,7 @@ class Meta:
def serialize_compute(c):
return {
"name": c.name,
"serial_no": c.serial_no,
"hw_model": c.hardware.hw_model,
"manufacturer": c.hardware.manufacturer,
"capabilities": [cap.capability for cap in c.hardware.capabilities.all()],
Expand All @@ -468,6 +469,11 @@ def get_sensors(self, obj: NodeData):
for s in obj.nodesensor_set.all():
results.append(self.serialize_common_sensor(s))

# add all compute sensors
for c in obj.compute_set.all():
for s in c.computesensor_set.all():
results.append(self.serialize_common_sensor(s))

# add all lorawan sensors
for s in obj.lorawanconnections.all():
results.append(self.serialize_common_sensor(s.lorawan_device))
Expand Down
20 changes: 16 additions & 4 deletions manifests/tests/ManifestHelp_fx.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ def createPartner(partner):
name=item['name']
)

def createSite(site):
def createSite(site: list):
"""
Helper function which populates site test data.
"""
Expand All @@ -82,7 +82,7 @@ def createSite(site):
id=item['id'], description=item['description']
)

def createAddress(address):
def createAddress(address: list):
"""
Helper function which populates address test data.
"""
Expand All @@ -106,7 +106,7 @@ def createAddress(address):
locality=Locality.objects.get(postal_code=item['postal_code'])
)

def createModem(modem):
def createModem(modem: list):
"""
Helper function which populates modem test data.
"""
Expand All @@ -117,7 +117,18 @@ def createModem(modem):
model=item['model'],sim_type=item['sim_type']
)

def createManifests(manifests):
def createComputeSensor(cs: list):
"""
Helper function which populates Compute Sensor data.
"""
for item in cs:
ComputeSensor.objects.create(
name=item['name'],
hardware=SensorHardware.objects.get(hw_model=item['hw_model']),
scope=Compute.objects.get(name=item["scope"])
)

def createManifests(manifests: list):
"""
Helper function which populates manifest test data.
"""
Expand Down Expand Up @@ -161,4 +172,5 @@ def createManifests(manifests):
node=node_obj,
hardware=ComputeHardware.objects.get(hw_model=compute["hw_model"]),
name=compute["name"],
serial_no=compute["serial_no"],
)
23 changes: 22 additions & 1 deletion manifests/tests/test_manifest.py
Original file line number Diff line number Diff line change
Expand Up @@ -479,18 +479,21 @@ def setUp(self):
"computes": [
{
"name": "nxcore",
"serial_no": "48B02D5BFE93",
"hw_model": "xavierNX",
"manufacturer": "ConnectTech",
"capabilities": ["gpu", "cuda102", "arm64"],
},
{
"name": "rpi",
"serial_no": "58C12D5BDE52",
"hw_model": "RPI4B",
"manufacturer": "Raspberry Pi",
"capabilities": ["arm64", "poe"],
},
{
"name": "rpi.lorawan",
"serial_no": "12302A5BFE93",
"hw_model": "RPI4B",
"manufacturer": "Raspberry Pi",
"capabilities": ["arm64", "poe"],
Expand Down Expand Up @@ -543,12 +546,14 @@ def setUp(self):
"computes": [
{
"name": "nxcore",
"serial_no": "48B02D5BFE93",
"hw_model": "xavierNX",
"manufacturer": "ConnectTech",
"capabilities": ["gpu", "cuda102", "arm64"],
},
{
"name": "rpi",
"name": "rpi 2",
"serial_no": "58C12D5BDE52",
"hw_model": "RPI4B",
"manufacturer": "Raspberry Pi",
"capabilities": ["arm64", "poe"],
Expand All @@ -558,6 +563,22 @@ def setUp(self):

createManifests([self.W123_data, self.W021_data])

#add compute sensor to W123
ComputeSensor = {
"name": "bme680",
"hw_model": "BME680",
"manufacturer": "Bosch",
"capabilities": [],
"scope": "rpi",
}
createComputeSensor([ComputeSensor])
ComputeSensor.pop("scope")
self.W123_data["sensors"].append(ComputeSensor)

#swap bme680 with CSU_soil_sensor, order matters with the tests
sensors = self.W123_data["sensors"]
sensors[-1], sensors[-2] = sensors[-2], sensors[-1]

def test_retrieve_node(self):
"""Test node view's happy path for retrieving a record"""
r = self.client.get("/api/v-beta/nodes/W123/")
Expand Down
1 change: 1 addition & 0 deletions manifests/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,7 @@ class NodesViewSet(ReadOnlyModelViewSet):
"lorawanconnections__lorawan_device__hardware__capabilities",
"compute_set__hardware__capabilities",
"nodesensor_set__hardware__capabilities",
"compute_set__computesensor_set__hardware__capabilities",
"project",
)
.order_by("vsn")
Expand Down

0 comments on commit 3d70805

Please sign in to comment.