class ServiceAccount(HashMapModel, metaclass=CamelCaseMeta): user_id = StringIdField(read_only=True) """ User identifier on service. """ first_name = StringField() """ User first name on service. """ last_name = StringField() """ User last name on service. """ user_name = StringIdField(read_only=True) """ User username on service. """ personalities = HashMapField(field_type=ModelField( model_class=Personality)) """
def test_set_initialised_list(self): test_list = ListModel([2, 3, "4", 6], field_type=StringField()) test_list[2] = {} test_list[3] = "hi" test_list.append("hi") self.assertEqual(test_list.__modified_data__, ["2", "3", "4", "hi", "hi"])
def test_string_field(self): list_model = ListModel(['aaaa', 'bbbb', 'cccc'], field_type=StringField()) list_model.flat_data() list_model.pop() self._assert_equal_after_pickle(list_model)
def test_pop_element(self): test_list = ListModel([2, 3, "4", 6], field_type=StringField()) test_list.pop(1) self.assertEqual(test_list.__modified_data__, ["2", "4", "6"]) test_list.flat_data() test_list.pop(1) self.assertEqual(test_list.__modified_data__, ["2", "6"]) self.assertEqual(test_list.__original_data__, ["2", "4", "6"])
class User(PersistentModel): user_name = StringIdField(read_only=True) """ User username on platform. """ first_name = StringField() """ User first name on platform. """ last_name = StringField() """ User lasr name on platform. """ service_accounts = HashMapField(field_type=ModelField( model_class=ServiceAccount)) """
class Room(PersistentModel): service_id = StringIdField(read_only=True) """ Service where is room. """ room_id = StringIdField(read_only=True) """ Room identifier on service. """ title = StringField() """ Room title. """ type = StringIdField() """ Room type """ assistants = ArrayField(field_type=StringIdField(), read_only=True) """
def test_iter_flattered(self): initial_list = [2, 3, "4", 6] test_list = ListModel(initial_list, field_type=StringField()) test_list.flat_data() for x in test_list: self.assertEquals(x, str(initial_list[test_list.index(x)]))
def test_delete_item_flattered(self): test_list = ListModel([2, 3, "4", 6], field_type=StringField()) test_list.flat_data() del test_list[0] self.assertEqual(test_list[0], "3")
def test_get_items_flattered_list(self): test_list = ListModel([2, 3, "4", 6], field_type=StringField()) test_list.flat_data() self.assertEqual(test_list[0], "2")
def test_get_items(self): test_list = ListModel([2, 3, "4", 6], field_type=StringField()) self.assertEqual(test_list[0], "2")
def test_index_exception(self): test_list = ListModel([2, 3, "4", 6], field_type=StringField()) self.assertRaises(ValueError, test_list.index, 7)
def test_extend_with_invalid_elements(self): test_list = ListModel([2, 3, "4", 6], field_type=StringField()) test_list.extend([{}, 3.4]) self.assertEqual(test_list.__modified_data__, ["2", "3", "4", "6", "3.4"])
def test_list_field_conversion(self): test_list = ListModel([2, 3, "4", 6], field_type=StringField()) self.assertEqual(test_list.__modified_data__, ["2", "3", "4", "6"])
def test_reverse(self): test_list = ListModel(["one", "two", "three", []], field_type=StringField()) test_list.reverse() self.assertEqual(["three", "two", "one"], list(test_list))
class Personality(BaseModel): first_name = StringField() last_name = StringField()