async def test_unique(self): author = Author(**{'name': 'Mnemonic', 'age': 73}) await author.save() # author name is unique, will raise an exception author2 = Author(**{'name': 'Mnemonic', 'age': 73}) with self.assertRaises(ModelError) as exc: await author2.save() self.assertEqual('The model violates a unique constraint', exc.exception.args[0])
async def create_author(x): author = Author(**{ 'name': 'foo_boy {}'.format(str(x)), 'age': 23, }) await author.save()
def test_class__init__(self): # classmethods tests # no matter how you import them they are the same object self.assertTrue(Author is Author2) self.assertTrue(Book is Book2) self.assertEqual(Book().cls_tablename(), 'library') self.assertEqual(Author().cls_tablename(), 'Author')
async def test_serialize_wrong_model(self): # complains if we try to serialize an incorrect model with self.assertRaises(SerializerError) as exc: author = Author() BookSerializer().serialize(author) self.assertIn('That object is not an instance of', exc.exception.args[0])
def test_get_fields_with_changed_db_column(self): fields = Author.get_fields() self.assertEqual(len(fields), 5) self.assertEqual( sorted(list(fields.keys())), sorted(["na", "name", "age", "publisher", "email"]), )
def setUp(self): super().setUp() Author.objects.bulk_create([Author(id=i + 1) for i in range(10)])
def test_instantiated__init__with_changed_db_column(self): author = Author() self.assertEqual(author.db_pk, 'uid') self.assertEqual(author.orm_pk, 'na')
def test_get_fields_with_changed_db_column(self): fields = Author.get_fields() self.assertEqual(len(fields), 5) self.assertEqual(sorted(list(fields.keys())), sorted(['na', 'name', 'age', 'publisher', 'email']))
async def create_author(x): author = Author(**{"name": "foo_boy {}".format(str(x)), "age": 23}) await author.save()
def setUp(self): super(SmartIteratorTests, self).setUp() Author.objects.bulk_create([Author(id=i + 1) for i in range(10)])
def setUp(self): super(ApproximateCountTests, self).setUp() Author.objects.bulk_create([Author() for i in range(10)])
def setUp(self): super(FoundRowsTests, self).setUp() Author.objects.bulk_create([Author() for i in range(10)])
def setUpTestData(cls): super().setUpTestData() Author.objects.bulk_create([Author(id=i + 1) for i in range(10)])