Ejemplo n.º 1
0
 def get(data_fixture):
     if data_fixture == 'static_sequential':
         return SequentialDataFixture()
     elif data_fixture == 'sequential':
         return SequentialDataFixture()
     elif data_fixture == 'random':
         return RandomDataFixture()
     return data_fixture
Ejemplo n.º 2
0
 def test_custom_one(self):
     from django_dynamic_fixture.fixture_algorithms.sequential_fixture import SequentialDataFixture
     instance = N('django_dynamic_fixture.ModelWithNumbers',
                  data_fixture=SequentialDataFixture())
     assert instance is not None
     instance = G('django_dynamic_fixture.ModelWithNumbers',
                  data_fixture=SequentialDataFixture())
     assert instance is not None
Ejemplo n.º 3
0
def get_data_fixture(default='sequential'):
    # It must be 'sequential', 'static_sequential', 'global_sequential', 'random' or 'path.to.CustomDataFixtureClass'
    try:
        INTERNAL_DATA_FIXTURES = {
            'sequential': SequentialDataFixture(),
            'static_sequential': StaticSequentialDataFixture(),
            'global_sequential': GlobalSequentialDataFixture(),
            'random': RandomDataFixture()
        }
        if hasattr(settings, 'DDF_DEFAULT_DATA_FIXTURE'):
            if settings.DDF_DEFAULT_DATA_FIXTURE in INTERNAL_DATA_FIXTURES.keys(
            ):
                return INTERNAL_DATA_FIXTURES[
                    settings.DDF_DEFAULT_DATA_FIXTURE]
            else:
                # path.to.CustomDataFixtureClass
                mod_name, obj_name = get_mod_func(
                    settings.DDF_DEFAULT_DATA_FIXTURE)
                module = import_module(mod_name)
                custom_data_fixture = getattr(module, obj_name)
                return custom_data_fixture()
        else:
            return INTERNAL_DATA_FIXTURES[default]
    except:
        six.reraise(
            DDFImproperlyConfigured,
            DDFImproperlyConfigured(
                "DDF_DEFAULT_DATA_FIXTURE (%s) must be 'sequential', 'static_sequential', 'global_sequential', 'random' or 'path.to.CustomDataFixtureClass'."
                % settings.DDF_DEFAULT_DATA_FIXTURE),
            sys.exc_info()[2])
class SequentialDataFixtureTestCase(TestCase, DataFixtureTestCase):
    def setUp(self):
        self.fixture = SequentialDataFixture()

    def test_it_must_fill_integer_fields_sequencially_by_attribute(self):
        self.assertEquals(1, self.fixture.generate_data(models.IntegerField()))
        field = models.IntegerField()
        field.name = 'x'
        self.assertEquals(1, self.fixture.generate_data(field))
        self.assertEquals(2, self.fixture.generate_data(field))

    def test_it_must_fill_string_with_sequences_of_numbers_by_attribute(self):
        self.assertEquals('1', self.fixture.generate_data(models.CharField(max_length=1)))
        field = models.CharField(max_length=1)
        field.name = 'x'
        self.assertEquals('1', self.fixture.generate_data(field))
        self.assertEquals('2', self.fixture.generate_data(field))
class SequentialDataFixtureTestCase(TestCase, DataFixtureTestCase):
    def setUp(self):
        self.fixture = SequentialDataFixture()

    def test_it_must_fill_integer_fields_sequencially_by_attribute(self):
        self.assertEquals(1, self.fixture.generate_data(models.IntegerField()))
        field = models.IntegerField()
        field.name = 'x'
        self.assertEquals(1, self.fixture.generate_data(field))
        self.assertEquals(2, self.fixture.generate_data(field))

    def test_it_must_fill_string_with_sequences_of_numbers_by_attribute(self):
        self.assertEquals(
            '1', self.fixture.generate_data(models.CharField(max_length=1)))
        field = models.CharField(max_length=1)
        field.name = 'x'
        self.assertEquals('1', self.fixture.generate_data(field))
        self.assertEquals('2', self.fixture.generate_data(field))
 def setUp(self):
     self.fixture = SequentialDataFixture()
Ejemplo n.º 7
0
        return getattr(settings, config_name) if hasattr(
            settings, config_name) else default
    except DDFImproperlyConfigured:
        six.reraise(
            DDFImproperlyConfigured,
            DDFImproperlyConfigured(
                "%s (%s) must be True or False." %
                (config_name, getattr(settings, config_name))),
            sys.exc_info()[2])


# DDF_DEFAULT_DATA_FIXTURE default = 'sequential'
# It must be 'sequential', 'static_sequential', 'global_sequential', 'random' or 'path.to.CustomDataFixtureClass'
try:
    INTERNAL_DATA_FIXTURES = {
        'sequential': SequentialDataFixture(),
        'static_sequential': StaticSequentialDataFixture(),
        'global_sequential': GlobalSequentialDataFixture(),
        'random': RandomDataFixture()
    }
    if hasattr(settings, 'DDF_DEFAULT_DATA_FIXTURE'):
        if settings.DDF_DEFAULT_DATA_FIXTURE in INTERNAL_DATA_FIXTURES.keys():
            DDF_DEFAULT_DATA_FIXTURE = INTERNAL_DATA_FIXTURES[
                settings.DDF_DEFAULT_DATA_FIXTURE]
        else:
            # path.to.CustomDataFixtureClass
            mod_name, obj_name = get_mod_func(
                settings.DDF_DEFAULT_DATA_FIXTURE)
            module = import_module(mod_name)
            custom_data_fixture = getattr(module, obj_name)
            DDF_DEFAULT_DATA_FIXTURE = custom_data_fixture()
# -*- coding: utf-8 -*-
from django.test import TestCase
import pytest

from django_dynamic_fixture.models_test import *
from django_dynamic_fixture.ddf import *
from django_dynamic_fixture.fixture_algorithms.sequential_fixture import SequentialDataFixture

data_fixture = SequentialDataFixture()


class DDFTestCase(TestCase):
    def setUp(self):
        self.ddf = DynamicFixture(data_fixture)


class CopyTest(DDFTestCase):
    def test_it_should_copy_from_model_fields(self):
        instance = self.ddf.get(ModelForCopy, int_a=Copier('int_b'), int_b=3)
        assert instance.int_a == 3

    def test_simple_scenario(self):
        instance = self.ddf.get(ModelForCopy, int_b=Copier('int_a'))
        assert instance.int_b == instance.int_a

    def test_order_of_attributes_must_be_superfluous(self):
        instance = self.ddf.get(ModelForCopy, int_a=Copier('int_b'))
        assert instance.int_a == instance.int_b

    def test_it_should_deal_with_multiple_copiers(self):
        instance = self.ddf.get(ModelForCopy,
 def setUp(self):
     self.fixture = SequentialDataFixture()
Ejemplo n.º 10
0

def get_boolean_config(config_name, default=False):
    try:
        if hasattr(settings, config_name) and getattr(settings, config_name) not in [True, False]:
            # to educate users to use this property correctly.
            raise DDFImproperlyConfigured()
        return getattr(settings, config_name) if hasattr(settings, config_name) else default
    except DDFImproperlyConfigured:
        six.reraise(DDFImproperlyConfigured, DDFImproperlyConfigured("%s (%s) must be True or False." % (config_name, getattr(settings, config_name))), sys.exc_info()[2])


# DDF_DEFAULT_DATA_FIXTURE default = 'sequential'
# It must be 'sequential', 'static_sequential', 'global_sequential', 'random' or 'path.to.CustomDataFixtureClass'
try:
    INTERNAL_DATA_FIXTURES = {'sequential': SequentialDataFixture(),
                              'static_sequential': StaticSequentialDataFixture(),
                              'global_sequential': GlobalSequentialDataFixture(),
                              'random': RandomDataFixture()}
    if hasattr(settings, 'DDF_DEFAULT_DATA_FIXTURE'):
        if settings.DDF_DEFAULT_DATA_FIXTURE in INTERNAL_DATA_FIXTURES.keys():
            DDF_DEFAULT_DATA_FIXTURE = INTERNAL_DATA_FIXTURES[settings.DDF_DEFAULT_DATA_FIXTURE]
        else:
            # path.to.CustomDataFixtureClass
            mod_name, obj_name = get_mod_func(settings.DDF_DEFAULT_DATA_FIXTURE)
            module = import_module(mod_name)
            custom_data_fixture = getattr(module, obj_name)
            DDF_DEFAULT_DATA_FIXTURE = custom_data_fixture()
    else:
        DDF_DEFAULT_DATA_FIXTURE = INTERNAL_DATA_FIXTURES['sequential']
except:
 def setUp(self):
     self.ddf = DynamicFixture(SequentialDataFixture())