Example #1
0
    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])
Example #2
0
async def create_author(x):
    author = Author(**{
        'name': 'foo_boy {}'.format(str(x)),
        'age': 23,
    })

    await author.save()
Example #3
0
    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')
Example #4
0
    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])
Example #5
0
 def setUp(self):
     super().setUp()
     Author.objects.bulk_create([Author(id=i + 1) for i in range(10)])
Example #6
0
    def test_instantiated__init__with_changed_db_column(self):
        author = Author()

        self.assertEqual(author.db_pk, 'uid')
        self.assertEqual(author.orm_pk, 'na')
Example #7
0
async def create_author(x):
    author = Author(**{"name": "foo_boy {}".format(str(x)), "age": 23})

    await author.save()
Example #8
0
 def setUp(self):
     super(SmartIteratorTests, self).setUp()
     Author.objects.bulk_create([Author(id=i + 1) for i in range(10)])
Example #9
0
 def setUp(self):
     super(ApproximateCountTests, self).setUp()
     Author.objects.bulk_create([Author() for i in range(10)])
Example #10
0
 def setUp(self):
     super(FoundRowsTests, self).setUp()
     Author.objects.bulk_create([Author() for i in range(10)])
Example #11
0
 def setUpTestData(cls):
     super().setUpTestData()
     Author.objects.bulk_create([Author(id=i + 1) for i in range(10)])