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

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

        self.assertEqual(author.db_pk, 'uid')
        self.assertEqual(author.orm_pk, 'na')
コード例 #8
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']))
コード例 #9
0
async def create_author(x):
    author = Author(**{"name": "foo_boy {}".format(str(x)), "age": 23})

    await author.save()
コード例 #10
0
ファイル: test_models.py プロジェクト: ygdmxy/django-mysql
 def setUp(self):
     super(SmartIteratorTests, self).setUp()
     Author.objects.bulk_create([Author(id=i + 1) for i in range(10)])
コード例 #11
0
ファイル: test_models.py プロジェクト: ygdmxy/django-mysql
 def setUp(self):
     super(ApproximateCountTests, self).setUp()
     Author.objects.bulk_create([Author() for i in range(10)])
コード例 #12
0
ファイル: test_models.py プロジェクト: ygdmxy/django-mysql
 def setUp(self):
     super(FoundRowsTests, self).setUp()
     Author.objects.bulk_create([Author() for i in range(10)])
コード例 #13
0
 def setUpTestData(cls):
     super().setUpTestData()
     Author.objects.bulk_create([Author(id=i + 1) for i in range(10)])