def test_set_properties(self): obj = JsonConverter.to_map( "{ \"value1\": 123, \"value2\": { \"value21\": 111, \"value22\": 222 }, \"value3\": [ 444, " "{ \"value311\": 555 } ] } " ) values = AnyValueMap.from_tuples( "value1", "AAA", "value2", "BBB", "value3.1.value312", "CCC", "value3.3", "DDD", "value4.1", "EEE" ) RecursiveObjectWriter.set_properties(obj, values) values = RecursiveObjectReader.get_properties(obj) assert 8 == len(values) assert "AAA" == values["value1"] assert "BBB", values["value2"] assert 444 == values["value3.0"] assert 555 == values["value3.1.value311"] assert "CCC", values["value3.1.value312"] assert None is values["value3.2"] assert "DDD" == values["value3.3"] assert "EEE" == values["value4.1"]
def test_crud_operations(self): # Create one dummy dummy1 = self._persistence.create(None, DUMMY1) assert dummy1 != None assert dummy1['id'] != None assert DUMMY1['key'] == dummy1['key'] assert DUMMY1['content'] == dummy1['content'] # Create another dummy dummy2 = self._persistence.create(None, DUMMY2) assert dummy2 != None assert dummy2['id'] != None assert DUMMY2['key'] == dummy2['key'] assert DUMMY2['content'] == dummy2['content'] # Get all dummies dummies = self._persistence.get_page_by_filter(None, None, None) assert dummies != None assert 2 == len(dummies.data) # Update the dummy dummy1['content'] = "Updated Content 1"; dummy = self._persistence.update( None, dummy1 ) # Partially update the dummy dummy = self._persistence.update_partially( None, dummy1['id'], AnyValueMap.from_tuples( 'content', 'Partually Updated Content 1' ) ) assert dummy != None assert dummy1['id'] == dummy['id'] assert dummy1['key'] == dummy['key'] assert "Partually Updated Content 1" == dummy['content'] # Get the dummy by Id result = self._persistence.get_one_by_id(None, dummy1['id']) assert result is not None assert result['id'] == dummy1['id'] assert result['key'] == result['key'] # Delete the dummy self._persistence.delete_by_id(None, dummy1['id']) # Try to get deleted dummy dummy = self._persistence.get_one_by_id(None, dummy1['id']) assert dummy == None
def test_crud_operations(self): # Create one dummy dummy1 = self._persistence.create(None, DUMMY1) assert dummy1 is not None assert dummy1.id is not None assert DUMMY1.key == dummy1.key assert DUMMY1.content == dummy1.content # Create another dummy dummy2 = self._persistence.create(None, DUMMY2) assert dummy2 is not None assert dummy2.id is not None assert DUMMY2.key == dummy2.key assert DUMMY2.content == dummy2.content # Get all dummies dummies = self._persistence.get_page_by_filter(None, None, None) assert dummies is not None assert 2 == len(dummies.data) # Update the dummy dummy1.content = "Updated Content 1" dummy = self._persistence.update( None, dummy1 ) # Partially update the dummy dummy = self._persistence.update_partially( None, dummy1.id, AnyValueMap.from_tuples( 'content', 'Partially Updated Content 1' ) ) assert dummy is not None assert dummy1.id == dummy.id assert dummy1.key == dummy.key assert "Partially Updated Content 1" == dummy.content # Get the dummy by Id result = self._persistence.get_one_by_id(None, dummy1.id) assert result is not None assert result.id == dummy1.id assert result.key == dummy1.key # Delete the dummy self._persistence.delete_by_id(None, dummy1.id) # Try to get deleted dummy dummy = self._persistence.get_one_by_id(None, dummy1.id) assert dummy is None
def test_set_map_property(self): map = AnyValueMap.from_tuples("key1", 123, "key2", "ABC") ObjectWriter.set_property(map, "key3", "AAAA") assert "AAAA" == map.get("key3") ObjectWriter.set_property(map, "Key1", 5555) assert 5555 == map.get("key1") ObjectWriter.set_property(map, "Key2", "BBBB") assert "BBBB" == map.get("key2")
def test_get_map_property(self): map = AnyValueMap.from_tuples("key1", 123, "key2", "ABC") value = ObjectReader.get_property(map, "key3") assert None == value value = ObjectReader.get_property(map, "Key1") assert 123 == value value = ObjectReader.get_property(map, "KEY2") assert "ABC" == value
def test_get_map_properties(self): map = AnyValueMap.from_tuples("key1", 123, "key2", "ABC") names = ObjectReader.get_property_names(map) assert 2 == len(names) assert "key1" in names assert "key2" in names values = ObjectReader.get_properties(map) assert 2 == len(values) assert 123 == values["key1"] assert "ABC" == values["key2"]
def test_config_from_object(self): value = AnyValueMap.from_tuples( "field1", ConfigParams.from_string("field11=123;field12=ABC"), "field2", AnyValueArray.from_values( 123, "ABC", ConfigParams.from_string("field21=543;field22=XYZ")), "field3", True) config = ConfigParams.from_value(value) assert 7 == len(config) assert 123 == config.get_as_integer("field1.field11") assert "ABC" == config.get_as_string("field1.field12") assert 123 == config.get_as_integer("field2.0") assert "ABC" == config.get_as_string("field2.1") assert 543 == config.get_as_integer("field2.2.field21") assert "XYZ" == config.get_as_string("field2.2.field22") assert True == config.get_as_boolean("field3")
def test_get_as_string(self): message = AnyValueMap.from_tuples("key1", 123, "key2", "ABC") assert len(message) == 2 assert message.get_as_integer("key1") == 123 assert message.get_as_string("key2") == "ABC"