Пример #1
0
 def test_defaults(self):
     result = Parameters.from_tuples("value1", 123, "value2", 234)
     defaults = Parameters.from_tuples("value2", 432, "value3", 345)
     result = result.set_defaults(defaults, False)
     assert 3 == len(result)
     assert 123 == result.get("value1")
     assert 234 == result.get("value2")
     assert 345 == result.get("value3")
    def test_crud_operations(self):
        time.sleep(2)
        # Create the first beacon
        beacon1 = self.invoke("/v1/beacons/create_beacon",
                              Parameters.from_tuples("beacon", PropertyReflector.get_properties(BEACON1)))

        assert beacon1 is not None
        assert beacon1['id'] == BEACON1.id
        assert beacon1['site_id'] == BEACON1.site_id
        assert beacon1['udi'] == BEACON1.udi
        assert beacon1['type'] == BEACON1.type
        assert beacon1['label'] == BEACON1.label
        assert beacon1['center'] is not None

        # Create the second beacon
        beacon2 = self.invoke("/v1/beacons/create_beacon",
                              Parameters.from_tuples("beacon", PropertyReflector.get_properties(BEACON2)))

        assert beacon2 is not None
        assert beacon2['id'] == BEACON2.id
        assert beacon2['site_id'] == BEACON2.site_id
        assert beacon2['udi'] == BEACON2.udi
        assert beacon2['type'] == BEACON2.type
        assert beacon2['label'] == BEACON2.label
        assert beacon2['center'] is not None

        # Get all beacons
        page = self.invoke("/v1/beacons/get_beacons", Parameters.from_tuples("beacons"))
        assert page is not None
        assert len(page['data']) == 2

        beacon1 = page['data'][0]

        # Update the beacon
        beacon1['label'] = "ABC"
        beacon = self.invoke("/v1/beacons/update_beacon", Parameters.from_tuples("beacon", beacon1))
        assert beacon is not None
        assert beacon1['id'] == beacon['id']
        assert "ABC" == beacon['label']

        # Get beacon by udi
        beacon = self.invoke("/v1/beacons/get_beacon_by_udi", Parameters.from_tuples("udi", beacon1['udi']))
        assert beacon is not None
        assert beacon['id'] == beacon1['id']

        # Calculate position for one beacon
        position = self.invoke("/v1/beacons/calculate_position",
                               Parameters.from_tuples("site_id", '1', "udis", ['00001']))
        assert position is not None
        assert "Point" == position["type"]
        assert 2 == len(position["coordinates"])
        assert 0 == position["coordinates"][0]
        assert 0 == position["coordinates"][1]

        # Delete beacon
        self.invoke("/v1/beacons/delete_beacon_by_id", Parameters.from_tuples("id", beacon1['id']))

        # Try to get deleted beacon
        beacon = self.invoke("/v1/beacons/get_beacon_by_id", Parameters.from_tuples("id", beacon1['id']))
        assert not beacon
 def test_beacons_operations(self):
     # create one beacon
     beacon1 = self.rest.post('/api/1.0/create_beacon',
                              Parameters.from_tuples("beacons", BEACON1))
     assert beacon1 is not None
     assert 400 > beacon1.status_code
     assert beacon1.reason == 'Created'
    def test_crud_operations(self):
        # Create one dummy
        response = self.invoke(
            "/dummy/create_dummy",
            Parameters.from_tuples("dummy", DUMMY1.to_json()))

        dummy1 = Dummy.from_json(response)

        assert dummy1 is not None
        assert DUMMY1.key == dummy1.key
        assert DUMMY1.content == dummy1.content

        # Create another dummy
        response = self.invoke(
            "/dummy/create_dummy",
            Parameters.from_tuples("dummy", DUMMY2.to_json()))

        dummy2 = Dummy.from_json(response)

        assert dummy2 is not None
        assert DUMMY2.key == dummy2.key
        assert DUMMY2.content == dummy2.content

        # Get all dummies
        response = self.invoke("/dummy/get_dummies",
                               Parameters.from_tuples("dummies"))
        page = DataPage(
            [Dummy.from_json(item) for item in response.get('data', [])],
            response.get('total'))

        assert page is not None
        assert 2 == len(page.data)

        # Update the dummy
        dummy1.content = "Updated Content 1"
        response = self.invoke(
            "/dummy/update_dummy",
            Parameters.from_tuples("dummy", dummy1.to_json()))

        dummy = Dummy.from_json(response)

        assert dummy is not None
        assert dummy1.id == dummy.id
        assert dummy1.key == dummy.key
        assert "Updated Content 1" == dummy.content

        # Delete the dummy
        self.invoke("/dummy/delete_dummy",
                    Parameters.from_tuples("dummy_id", dummy1.id))

        # Try to get deleted dummy
        get_dummy = self.invoke("/dummy/get_dummy_by_id",
                                Parameters.from_tuples("dummy_id", dummy1.id))
        assert get_dummy is None
Пример #5
0
    def status(self):
        _id = self._context_info.context_id if not (
            self._context_info is None) else ""
        name = self._context_info.name if not (
            self._context_info is None) else "unknown"
        description = self._context_info.description if not (
            self._context_info is None) else ""
        uptime = (datetime.datetime.now() -
                  self._start_time).total_seconds() * 1000
        properties = self._context_info.properties if not (
            self._context_info is None) else ""

        components = []
        if not (self._references2 is None):
            for locator in self._references2.get_all_locators():
                components.append(locator.__str__())

        status = Parameters.from_tuples(
            "id", _id, "name", name, "description", description, "start_time",
            StringConverter.to_string(self._start_time), "current_time",
            StringConverter.to_string(datetime.datetime.now()), "uptime",
            uptime, "properties", properties, "components", components)
        self.send_result(status)
    def test_crud_operations(self):
        # Create one dummy
        dummy1 = self.invoke("/dummy/create_dummy",
                             Parameters.from_tuples("dummy", DUMMY1))

        assert None != dummy1
        assert DUMMY1['key'] == dummy1['key']
        assert DUMMY1['content'] == dummy1['content']

        # Create another dummy
        dummy2 = self.invoke("/dummy/create_dummy",
                             Parameters.from_tuples("dummy", DUMMY2))

        assert None != dummy2
        assert DUMMY2['key'] == dummy2['key']
        assert DUMMY2['content'] == dummy2['content']

        # Get all dummies
        dummies = self.invoke("/dummy/get_dummies",
                              Parameters.from_tuples("dummies"))

        assert None != dummies
        assert 2 == len(dummies['data'])

        # Update the dummy
        dummy1['content'] = "Updated Content 1"
        dummy = self.invoke("/dummy/update_dummy",
                            Parameters.from_tuples("dummy", dummy1))

        assert None != dummy
        assert dummy1['id'] == dummy['id']
        assert dummy1['key'] == dummy['key']
        assert "Updated Content 1" == dummy['content']

        # Delete the dummy
        self.invoke("/dummy/delete_dummy_by_id",
                    Parameters.from_tuples("dummy_id", dummy1['id']))

        # Try to get deleted dummy
        get_dummy = self.invoke(
            "/dummy/get_dummy_by_id",
            Parameters.from_tuples("dummy_id", dummy1['id']))
        assert False == get_dummy
Пример #7
0
    def test_crud_operations(self):
        time.sleep(1)
        # Create the first beacon
        response = self.invoke(
            "/v1/beacons/create_beacon",
            Parameters.from_tuples("beacon",
                                   PropertyReflector.get_properties(BEACON1)))

        beacon1 = BeaconV1(**response)

        assert beacon1 is not None
        assert beacon1.id == BEACON1.id
        assert beacon1.site_id == BEACON1.site_id
        assert beacon1.udi == BEACON1.udi
        assert beacon1.type == BEACON1.type
        assert beacon1.label == BEACON1.label
        assert beacon1.center is not None

        # Create the second beacon
        response = self.invoke(
            "/v1/beacons/create_beacon",
            Parameters.from_tuples("beacon",
                                   PropertyReflector.get_properties(BEACON2)))
        beacon2 = BeaconV1(**response)

        assert beacon2 is not None
        assert beacon2.id == BEACON2.id
        assert beacon2.site_id == BEACON2.site_id
        assert beacon2.udi == BEACON2.udi
        assert beacon2.type == BEACON2.type
        assert beacon2.label == BEACON2.label
        assert beacon2.center is not None

        # Get all beacons
        page = self.invoke("/v1/beacons/get_beacons",
                           Parameters.from_tuples("beacons"))
        assert page is not None
        assert len(page['data']) == 2

        beacon1 = BeaconV1(**page['data'][0])

        # Update the beacon
        beacon1.label = "ABC"
        response = self.invoke(
            "/v1/beacons/update_beacon",
            Parameters.from_tuples("beacon",
                                   PropertyReflector.get_properties(beacon1)))

        beacon = BeaconV1(**response)
        assert beacon is not None
        assert beacon1.id == beacon.id
        assert "ABC" == beacon.label

        # Get beacon by udi
        response = self.invoke("/v1/beacons/get_beacon_by_udi",
                               Parameters.from_tuples("udi", beacon1.udi))
        beacon = BeaconV1(**response)
        assert beacon is not None
        assert beacon.id == beacon1.id

        # Calculate position for one beacon
        position = self.invoke(
            "/v1/beacons/calculate_position",
            Parameters.from_tuples("site_id", '1', "udis", ['00001']))
        assert position is not None
        assert "Point" == position["type"]
        assert 2 == len(position["coordinates"])
        assert 0 == position["coordinates"][0]
        assert 0 == position["coordinates"][1]

        # Delete beacon
        self.invoke("/v1/beacons/delete_beacon_by_id",
                    Parameters.from_tuples("id", beacon1.id))

        # Try to get deleted beacon
        beacon = self.invoke("/v1/beacons/get_beacon_by_id",
                             Parameters.from_tuples("id", beacon1.id))
        assert beacon is False