Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix unit tests: Use TransactionTestCase instead of TestCase as base for MigrationTestCase #61

Merged
merged 1 commit into from
Feb 19, 2019

Conversation

ajhodges
Copy link
Contributor

Fixes issue with unit tests described in #60. I currently get the following output when running unit tests in my environment:

================================================================================ test session starts ================================================================================
platform linux -- Python 3.6.5, pytest-3.9.2, py-1.7.0, pluggy-0.8.1
rootdir: /home/adam/PycharmProjects/django-rest-framework-simplejwt, inifile: tox.ini
plugins: django-3.4.3, cov-2.6.0
collected 121 items                                                                                                                                                                 

tests/test_authentication.py .....                                                                                                                                            [  4%]
tests/test_backends.py ...............                                                                                                                                        [ 16%]
tests/test_integration.py .....                                                                                                                                               [ 20%]
tests/test_models.py ....................                                                                                                                                     [ 37%]
tests/test_serializers.py ..................                                                                                                                                  [ 52%]
tests/test_token_blacklist.py ......F                                                                                                                                         [ 57%]
tests/test_tokens.py ..........................                                                                                                                               [ 79%]
tests/test_utils.py .....                                                                                                                                                     [ 83%]
tests/test_views.py ....................                                                                                                                                      [100%]

===================================================================================== FAILURES ======================================================================================
____________________________________________________ TestPopulateJtiHexMigration.test_jti_field_should_contain_uuid_hex_strings _____________________________________________________
tests/test_token_blacklist.py:174: in setUp
    super(TestPopulateJtiHexMigration, self).setUp()
tests/utils.py:95: in setUp
    executor.migrate(self.migrate_from)
../../.pyenv/versions/3.6.5/envs/django-rest-framework-simplejwt/lib/python3.6/site-packages/django/db/migrations/executor.py:121: in migrate
    state = self._migrate_all_backwards(plan, full_plan, fake=fake)
../../.pyenv/versions/3.6.5/envs/django-rest-framework-simplejwt/lib/python3.6/site-packages/django/db/migrations/executor.py:196: in _migrate_all_backwards
    self.unapply_migration(states[migration], migration, fake=fake)
../../.pyenv/versions/3.6.5/envs/django-rest-framework-simplejwt/lib/python3.6/site-packages/django/db/migrations/executor.py:261: in unapply_migration
    with self.connection.schema_editor(atomic=migration.atomic) as schema_editor:
../../.pyenv/versions/3.6.5/envs/django-rest-framework-simplejwt/lib/python3.6/site-packages/django/db/backends/sqlite3/schema.py:25: in __enter__
    'SQLite schema editor cannot be used while foreign key '
E   django.db.utils.NotSupportedError: SQLite schema editor cannot be used while foreign key constraint checks are enabled. Make sure to disable them before entering a transaction.atomic() context because SQLite3 does not support disabling them in the middle of a multi-statement transaction.
======================================================================= 1 failed, 120 passed in 2.21 seconds ========================================================================

This fix resolves this issue by using the TransactionTestCase as the base for MigrationTestCase (TransactionTestCase does not use transaction.atomic(), which avoids this issue).

@ajhodges ajhodges changed the title Use TransactionTestCase instead of TestCase as base for MigrationTestCase Fix unit tests: Use TransactionTestCase instead of TestCase as base for MigrationTestCase Jan 15, 2019
@jnegro
Copy link

jnegro commented Feb 7, 2019

I've confirmed this patch works. Unfortunately this allowable failure will occur if you re-run the checks as noted in #73

@davesque davesque merged commit df927ed into jazzband:master Feb 19, 2019
@ajhodges ajhodges deleted the fix-sqlite-unit-tests branch September 19, 2019 16:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants