def test_init(self): inst = test_models.TestModel1(var1='Test') assert inst.var1 == 'Test' for field in inst._meta.declared_fields: if field.name != 'var1': assert getattr(inst, field.name) == field.default
def test_save_1(self, client): inst = test_models.TestModel1('Args1', 'Args2') inst.save() assert len(inst.Key) == 0 assert inst._meta.get_field_names() == ['var1', 'var2'] assert inst._meta.get_declared_field_names() == ['var1', 'var2'] assert inst._meta.get_discovered_field_names() == []
def test_add_key_1(self): inst = test_models.TestModel1('Args1', 'Args2') inst.add_id('Company1', 'client', 'key') assert len(inst.Key) == 1 assert inst.Key[0].company == 'Company1' assert inst.Key[0].client == 'client' assert inst.Key[0].id == 'key'
def test_populate_attrs_with_same_fields(self): response = utils.Response(keylist=self.keylist, dict=self.data) inst = test_models.TestModel1() inst.populate_attrs(response) for field in inst._meta.declared_fields: assert getattr(inst, field.name) == self.data[field.name] assert len(inst._meta.discovered_fields) == 0
def test_populate_attrs_with_extra_fields(self): data = self.data data.update(var3='Test') keylist = self.keylist keylist.append('var3') response = utils.Response(keylist=keylist, dict=data) inst = test_models.TestModel1() inst.populate_attrs(response) for field in inst._meta.declared_fields: assert getattr(inst, field.name) == self.data[field.name] assert len(inst._meta.discovered_fields) == 1 assert hasattr(inst, 'var3')
def test_eq_2(self): inst1 = test_models.TestModel1('Args1') inst2 = test_models.TestModel1('Args2') assert inst1 != inst2
def test_get_keys_1(self): inst = test_models.TestModel1('Args1', 'Args2') inst.add_id('Company1', 'client', 'key') assert inst.get_id() == ['key']
def test_remove_key_1(self): inst = test_models.TestModel1('Args1', 'Args2') inst.add_id('Company1', 'client', 'key') inst.remove_id('key') assert len(inst.Key) == 0
def test_init_with_kwargs_2(self): with pytest.raises(TypeError): inst = test_models.TestModel1(var='Args1')
def test_init_with_kwargs_1(self): inst = test_models.TestModel1(var1='Args1', var2='Args2') assert inst.var1 == 'Args1' assert inst.var2 == 'Args2'
def test_init_with_fields_attr_and_args_3(self): with pytest.raises(TypeError): inst = test_models.TestModel1('Args1', 'Args2', 'Args3')
def test_init_with_fields_attr_and_args_2(self): inst = test_models.TestModel1('Args1', 'Args2') assert inst.var1 == 'Args1' assert inst.var2 == 'Args2'