1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49
|
from unittest import TestCase
from django.conf import settings
from django_dynamic_fixture import decorators
class SkipForDatabaseTest(TestCase):
def setUp(self):
self.it_was_executed = False
def tearDown(self):
# It is important to do not break others tests: global and shared variable
decorators.DATABASE_ENGINE = settings.DATABASES['default']['ENGINE']
@decorators.only_for_database(decorators.POSTGRES)
def method_postgres(self):
self.it_was_executed = True
def test_annotated_method_only_for_postgres(self):
decorators.DATABASE_ENGINE = decorators.SQLITE3
self.method_postgres()
assert self.it_was_executed is False
decorators.DATABASE_ENGINE = decorators.POSTGRES
self.method_postgres()
assert self.it_was_executed
class OnlyForDatabaseTest(TestCase):
def setUp(self):
self.it_was_executed = False
def tearDown(self):
# It is important to do not break others tests: global and shared variable
decorators.DATABASE_ENGINE = settings.DATABASES['default']['ENGINE']
@decorators.skip_for_database(decorators.SQLITE3)
def method_sqlite3(self):
self.it_was_executed = True
def test_annotated_method_skip_for_sqlite3(self):
decorators.DATABASE_ENGINE = decorators.SQLITE3
self.method_sqlite3()
assert self.it_was_executed is False
decorators.DATABASE_ENGINE = decorators.POSTGRES
self.method_sqlite3()
assert self.it_was_executed
|