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 50 51 52 53 54 55 56 57 58 59 60 61 62
|
from datetime import datetime
from django.db import models
from django.test import TestCase
from django_dynamic_fixture.fixture_algorithms.default_fixture import PostgresFixtureMixin
from django_dynamic_fixture.fixture_algorithms.sequential_fixture import SequentialDataFixture, StaticSequentialDataFixture
from django_dynamic_fixture.fixture_algorithms.random_fixture import RandomDataFixture
from django_dynamic_fixture.fixture_algorithms.unique_random_fixture import UniqueRandomDataFixture
try:
import psycopg2
from django.contrib.postgres.fields import ArrayField
class PostgresDataFixtureTestMixin:
def test_arrayfield_integer_config(self):
data = self.fixture.generate_data(ArrayField(models.IntegerField()))
assert isinstance(data, list)
assert isinstance(data[0], int)
def test_arrayfield_char_config(self):
data = self.fixture.generate_data(ArrayField(models.CharField()))
assert isinstance(data, list)
assert isinstance(data[0], str)
def test_arrayfield_datetime_config(self):
data = self.fixture.generate_data(ArrayField(models.DateTimeField()))
assert isinstance(data, list)
assert isinstance(data[0], datetime)
def test_arrayfield_email_config(self):
data = self.fixture.generate_data(ArrayField(models.EmailField(max_length=100)))
assert isinstance(data, list)
assert isinstance(data[0], str)
class PostgresSequentialDataFixtureTestCase(TestCase, PostgresDataFixtureTestMixin):
def setUp(self):
class CustomFixture(SequentialDataFixture, PostgresFixtureMixin):
pass
self.fixture = CustomFixture()
class PostgresStaticSequentialDataFixtureTestCase(TestCase, PostgresDataFixtureTestMixin):
def setUp(self):
class CustomFixture(StaticSequentialDataFixture, PostgresFixtureMixin):
pass
self.fixture = CustomFixture()
class PostgresRandomDataFixtureTestCase(TestCase, PostgresDataFixtureTestMixin):
def setUp(self):
class CustomFixture(RandomDataFixture, PostgresFixtureMixin):
pass
self.fixture = CustomFixture()
class PostgresUniqueRandomDataFixtureTestCase(TestCase, PostgresDataFixtureTestMixin):
def setUp(self):
class CustomFixture(UniqueRandomDataFixture, PostgresFixtureMixin):
pass
self.fixture = CustomFixture()
except (ImportError, ModuleNotFoundError):
print('Skipping Postgres tests because psycopg2 has not been installed.')
|