Beispiel #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
Beispiel #3
0
    def test_contains(self):
        config = Parameters.from_json(
            "{ \"value1\": 123, \"value2\": { \"value21\": 111, \"value22\": 222 } }"
        )

        has = config.contains_key("")
        assert False == has

        has = config.contains_key("value1")
        assert True == has

        has = config.contains_key("value2")
        assert True == has

        has = config.contains_key("value3")
        assert False == has

        has = config.contains_key("value2.value21")
        assert True == has

        has = config.contains_key("value2.value31")
        assert False == has

        has = config.contains_key("value2.value21.value211")
        assert False == has

        has = config.contains_key("valueA.valueB.valueC")
        assert False == has
 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'
Beispiel #5
0
    def test_override_with_nulls(self):
        result = Parameters.from_json("{ \"value1\": 123, \"value2\": 234 }")
        result = result.override(None, True)

        assert 2 == len(result)
        assert 123 == result.get("value1")
        assert 234 == result.get("value2")
Beispiel #6
0
    def test_get(self):
        config = Parameters.from_json(
            "{ \"value1\": 123, \"value2\": { \"value21\": 111, \"value22\": 222 } }"
        )

        value = config.get("")
        assert None == value

        value = config.get("value1")
        assert 123 == value

        value = config.get("value2")
        assert None != value

        value = config.get("value3")
        assert None == value

        value = config.get("value2.value21")
        assert 111 == value

        value = config.get("value2.value31")
        assert None == value

        value = config.get("value2.value21.value211")
        assert None == value

        value = config.get("valueA.valueB.valueC")
        assert None == value
Beispiel #7
0
 def test_assign_to(self):
     value = ClassTest(None, None)
     new_values = Parameters.from_json(
         "{ \"value1\": 123, \"value2\": \"ABC\", \"value3\": 456 }")
     new_values.assign_to(value)
     assert value.value1 is not None
     assert value.value1 == 123
     assert value.value2 is not None
     assert value.value2 == 'ABC'
Beispiel #8
0
    def test_override_recursive(self):
        result = Parameters.from_json(
            "{ \"value1\": 123, \"value2\": { \"value21\": 111, \"value22\": 222 } }"
        )
        defaults = Parameters.from_json(
            "{ \"value2\": { \"value22\": 777, \"value23\": 333 }, \"value3\": 345 }"
        )
        result = result.set_defaults(defaults, True)

        assert 3 == len(result)
        assert 123 == result.get("value1")
        assert 345 == result.get("value3")

        deep_result = result.get_as_map("value2")
        assert 3 == len(deep_result)
        assert 111 == deep_result.get("value21")
        assert 222 == deep_result.get("value22")
        assert 333 == deep_result.get("value23")
Beispiel #9
0
    def test_from_config(self):
        config = ConfigParams.from_tuples("field1.field11", 123, "field2",
                                          "ABC", "field1.field12", "XYZ")

        params = Parameters.from_config(config)
        assert 2 == len(params)
        assert "ABC" == params.get("field2")
        value = params.get_as_map("field1")
        assert 2 == len(value)
        assert "123" == value.get("field11")
        assert "XYZ" == value.get("field12")
 def handler():
     params = self._get_data()
     correlation_id = self._get_correlation_id()
     args = Parameters.from_value(params)
     timing = self._instrument(
         correlation_id, self._base_route + '.' + command.get_name())
     try:
         result = command.execute(correlation_id, args)
         return self.send_result(result)
     finally:
         timing.end_timing()
    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
Beispiel #12
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
 def handler(correlation_id: Optional[str], args: Parameters):
     entity = args.get("dummy")
     if isinstance(entity, dict):
         entity = Dummy.from_json(entity)
     return self._controller.update(correlation_id, entity)
Beispiel #15
0
    def test_put(self):
        config = Parameters(self)

        config.put(None, 123)
        assert 0 == len(config)

        config.put("field1", 123)
        assert 1 == len(config)
        assert 123 == config.get("field1")

        config.put("field2", "ABC")
        assert 2 == len(config)
        assert "ABC" == config.get("field2")

        config.put("field2.field1", 123)
        assert "ABC" == config.get("field2")

        config.put("field3.field31", 456)
        assert 3 == len(config)
        sub_config = config.get_as_map("field3")
        assert None != sub_config
        assert 456 == sub_config.get("field31")

        config.put("field3.field32", "XYZ")
        assert "XYZ" == config.get("field3.field32")
 def handler(correlation_id: Optional[str], args: Parameters):
     filter = FilterParams.from_value(args.get("filter"))
     paging = PagingParams.from_value(args.get("paging"))
     page = self._controller.get_page_by_filter(correlation_id, filter,
                                                paging)
     return page
 def handler(correlation_id: Optional[str], args: Parameters):
     id = args.get_as_string("dummy_id")
     return self._controller.delete_by_id(correlation_id, id)
Beispiel #18
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