Пример #1
0
 def setUp(self):
     self.fixtures_manager = FixturesManager()
     self.fixtures_manager.load(
         './charlatan/tests/data/relationships_without_models.yaml')
     self.install_fixtures([
         'dict_with_nest', 'simple_dict', 'list_of_relationships'])
     self.init_fixtures()
Пример #2
0
class TestRelationshipsWithoutModels(testing.TestCase,
                                     testcase.FixturesManagerMixin):

    def setUp(self):
        self.fixtures_manager = FixturesManager()
        self.fixtures_manager.load(
            './charlatan/tests/data/relationships_without_models.yaml')
        self.install_fixtures([
            'dict_with_nest', 'simple_dict', 'list_of_relationships'])
        self.init_fixtures()

    def test_dictionaries_nest(self):
        self.assertEqual(self.dict_with_nest['simple_dict'], self.simple_dict)

    def test_relationships_list(self):
        self.assertEqual([self.dict_with_nest, self.simple_dict],
                         self.list_of_relationships)

    def test_nested_list_of_relationships(self):
        nested_list_of_relationships = self.install_fixture(
            'nested_list_of_relationships')

        self.assertEqual(nested_list_of_relationships, {
            'dicts': [
                [self.dict_with_nest],
                [self.simple_dict],
            ]
        })

    def test_relationships_dict_attribute(self):
        parent = self.install_fixture('parent_dict.object1')
        child = self.install_fixture('child_dict.object1')

        self.assertEquals(child['field1'], parent['field1'])
Пример #3
0
def get_collection(collection):
    """Return FixtureCollection.

    :param str collection: name of collection to import
    """
    manager = FixturesManager()
    manager.load("docs/examples/collection.yaml")
    return manager.collection.get(collection)
Пример #4
0
 def test_install_fixture_with_now(self):
     """Verify that we can install a fixture with !now tag."""
     manager = FixturesManager()
     manager.load('./charlatan/tests/data/simple.yaml')
     fixture = manager.install_fixture('fixture')
     self.assertEqual(fixture,
                      {'now': datetime(2014, 12, 30, 11, 0,
                                       tzinfo=pytz.utc)})
Пример #5
0
 def test_dependency_parsing(self):
     fm = FixturesManager()
     fm.load(
         './charlatan/tests/data/dependencies.yaml'
     )
     assert fm.depgraph.has_edge_between('fixture1', 'fixture2')
     assert fm.depgraph.has_edge_between('fixture1', 'fixture3')
     assert fm.depgraph.has_edge_between('fixture4', 'fixture3')
     assert fm.depgraph.has_edge_between('fixture2', 'fixture4')
Пример #6
0
 def test_dependency_parsing(self):
     fm = FixturesManager()
     fm.load(
         './charlatan/tests/data/dependencies.yaml'
     )
     assert fm.depgraph.has_edge_between('fixture1', 'fixture2')
     assert fm.depgraph.has_edge_between('fixture1', 'fixture3')
     assert fm.depgraph.has_edge_between('fixture4', 'fixture3')
     assert fm.depgraph.has_edge_between('fixture2', 'fixture4')
Пример #7
0
 def test_constructs_ancestors(self):
     fm = FixturesManager()
     fm.load(
         './charlatan/tests/data/dependencies.yaml'
     )
     assert not fm.cache
     # loading fixture3 should load fixture1 and fixture2 also
     fm.get_fixture('fixture3')
     self.assertIn('fixture1', fm.cache)
     self.assertIn('fixture4', fm.cache)
Пример #8
0
class TestSqlalchemyFixtures(testing.TestCase):

    def setUp(self):
        self.session = Session()
        self.manager = FixturesManager(db_session=self.session)
        self.manager.load("./charlatan/tests/data/relationships.yaml")

        Base.metadata.create_all(engine)

    def tearDown(self):
        Base.metadata.drop_all(engine)
        self.session.close()

    def test_double_install(self):
        """Verify that there's no double install."""
        self.manager.install_fixture("model")
        self.manager.install_fixture("relationship_alone")

        self.assertEqual(self.session.query(Toaster).count(), 1)
        self.assertEqual(self.session.query(Color).count(), 1)

    def test_getting_from_database(self):
        """Verify that we can get from the database."""
        installed = Toaster(id=1)
        self.session.add(installed)
        self.session.commit()

        toaster = self.manager.install_fixture("from_database")
        self.assertEqual(toaster.id, 1)

    def test_installing_collection(self):
        """Verify that a collection of fixtures is in the database"""
        self.manager.install_fixture("model_list")

        self.assertEqual(self.session.query(Toaster).count(), 2)
Пример #9
0
    def test_install_fixture(self):
        """install_fixture should return the fixture."""
        manager = FixturesManager()
        manager.load(
            './charlatan/tests/data/relationships_without_models.yaml')

        fixture = manager.install_fixture('simple_dict')

        self.assertEqual(fixture, {
            'field1': 'lolin',
            'field2': 2,
        })
Пример #10
0
    def test_uninstall_non_installed_fixture(self):
        """uninstall_fixture should return None.

        The method returns None since the fixture has not been previously
        installed.
        """

        fixtures_manager = FixturesManager()
        fixtures_manager.load(
            './charlatan/tests/data/relationships_without_models.yaml')

        fixture = fixtures_manager.uninstall_fixture('simple_dict')
        self.assertEqual(fixture, None)
Пример #11
0
 def test_notices_cyclic_dependencies(self):
     fm = FixturesManager()
     self.assertRaises(
         depgraph.HasACycle,
         fm.load,
         './charlatan/tests/data/cyclic_dependencies.yaml'
     )
class TestRelationshipsWithoutModels(testing.TestCase,
                                     testcase.FixturesManagerMixin):

    fixtures = ('dict_with_nest', 'simple_dict', 'list_of_relationships',)

    def setUp(self):
        self.fixtures_manager = FixturesManager()
        self.fixtures_manager.load(
            './charlatan/tests/data/relationships_without_models.yaml')
        self.init_fixtures()

    def test_dictionaries_nest(self):
        self.assertEqual(self.dict_with_nest['simple_dict'], self.simple_dict)

    def test_relationships_list(self):
        self.assertEqual([self.dict_with_nest, self.simple_dict],
                         self.list_of_relationships)
Пример #13
0
def test_overrides_and_in_cache():
    manager = FixturesManager()
    manager.load('./docs/examples/simple_fixtures.yaml')
    # Add it to the cache
    manager.install_fixture("toaster")
    toaster = manager.install_fixture("toaster", overrides={"color": "blue"})
    assert toaster.color == 'blue'
Пример #14
0
 def test_load_two_files(self):
     """Verify we can load two files."""
     manager = FixturesManager()
     manager.load(
         './charlatan/tests/data/relationships_without_models.yaml')
     manager.load(
         './charlatan/tests/data/simple.yaml')
     assert 'simple_dict' in manager.keys()
class TestListOfFixtures(testing.TestCase):

    def setUp(self):
        self.fm = FixturesManager()
        self.fm.load('./charlatan/tests/data/lists.yaml')

    def test_get_list_by_name(self):
        """Verify that lists of fixtures returns lists"""

        fixtures = self.fm.install_fixture('fixture_list')
        self.assertIsInstance(fixtures, list)

    def test_one_to_many_relationship(self):
        """Verify that relations to lists of fixtures work"""
        fixture = self.fm.install_fixture('related_fixture')
        self.assertEqual(
            fixture['elements'],
            self.fm.install_fixture('fixture_list')
        )

    def test_override(self):
        """Verify that we can override attributes on a list of fixtures."""
        fixtures = self.fm.install_fixture('fixture_list',
                                           overrides={"field1": 12})
        assert list(map(op.itemgetter('field1'), fixtures)) == [12, 12]
Пример #16
0
 def test_constructs_ancestors(self):
     fm = FixturesManager()
     fm.load(
         './charlatan/tests/data/dependencies.yaml'
     )
     assert not fm.cache
     # loading fixture3 should load fixture1 and fixture2 also
     fm.get_fixture('fixture3')
     self.assertIn('fixture1', fm.cache)
     self.assertIn('fixture4', fm.cache)
Пример #17
0
    def test_uninstall_fixtures(self):
        """uninstall_fixtures should return the list of installed fixtures."""
        fixtures_manager = FixturesManager()
        fixtures_manager.load(
            './charlatan/tests/data/relationships_without_models.yaml')

        fixture_keys = ('simple_dict', 'dict_with_nest')

        fixtures_manager.install_fixtures(fixture_keys)
        self.assertEqual(len(fixtures_manager.cache.keys()), 2)

        fixtures = fixtures_manager.uninstall_fixtures(fixture_keys)
        self.assertEqual(len(fixtures), 2)
        self.assertEqual(len(fixtures_manager.cache.keys()), 0)

        # uninstalling non-exiting fixtures should not raise an exception
        fixtures = fixtures_manager.uninstall_fixtures(fixture_keys)
        self.assertEqual(len(fixtures), 0)
        self.assertEqual(len(fixtures_manager.cache.keys()), 0)
Пример #18
0
    def test_uninstall_fixture(self):
        """uninstall_fixture should return the fixture."""

        fixtures_manager = FixturesManager()
        fixtures_manager.load(
            './charlatan/tests/data/relationships_without_models.yaml')

        fixtures_manager.install_fixture('simple_dict')
        fixture = fixtures_manager.uninstall_fixture('simple_dict')
        self.assertEqual(fixture, {
            'field1': 'lolin',
            'field2': 2,
        })

        # verify we are forgiving with list inputs
        fixtures = fixtures_manager.install_fixtures('simple_dict')
        self.assertEqual(len(fixtures), 1)

        fixtures = fixtures_manager.uninstall_fixtures('simple_dict')
        self.assertEqual(len(fixtures), 1)
        self.assertEqual(fixtures[0], {
            'field1': 'lolin',
            'field2': 2,
        })
Пример #19
0
class TestListOfFixtures(testing.TestCase):
    def setUp(self):
        self.fm = FixturesManager()
        self.fm.load('./charlatan/tests/data/lists.yaml')

    def test_get_list_by_name(self):
        """Verify that lists of fixtures returns lists."""
        fixtures = self.fm.install_fixture('fixture_list')
        self.assertIsInstance(fixtures, list)

    def test_one_to_many_relationship(self):
        """Verify that relations to lists of fixtures work."""
        fixture = self.fm.install_fixture('related_fixture')
        self.assertEqual(fixture['elements'],
                         self.fm.install_fixture('fixture_list'))

    def test_override(self):
        """Verify that we can override attributes on a list of fixtures."""
        fixtures = self.fm.install_fixture('fixture_list',
                                           overrides={"field1": 12})
        assert list(map(op.itemgetter('field1'), fixtures)) == [12, 12]
 def setUp(self):
     self.fm = FixturesManager()
     self.fm.load('./charlatan/tests/data/lists.yaml')
Пример #21
0
 def test_invalid_hook(self):
     """Verify that can't set an invalid hook."""
     manager = FixturesManager()
     with pytest.raises(KeyError):
         manager.set_hook("invalid", lambda p: p)
Пример #22
0
 def test_uninstall_non_installed_fixture(self):
     manager = FixturesManager()
     manager.load(
         './charlatan/tests/data/relationships_without_models.yaml')
     manager.uninstall_fixture('simple_dict')
Пример #23
0
 def test_set_hook(self):
     """Verify that we can set a hook."""
     manager = FixturesManager()
     manager.set_hook("before_save", lambda p: p)
Пример #24
0
class TestSqlalchemyFixtures(testing.TestCase):
    def setUp(self):
        self.session = Session()
        self.manager = FixturesManager(db_session=self.session)
        self.manager.load("./charlatan/tests/data/relationships.yaml")

        Base.metadata.create_all(engine)

    def tearDown(self):
        Base.metadata.drop_all(engine)
        self.session.close()

    def test_double_install(self):
        """Verify that there's no double install."""
        self.manager.install_fixture("model")
        self.manager.install_fixture("color")

        self.assertEqual(self.session.query(Toaster).count(), 1)
        self.assertEqual(self.session.query(Color).count(), 1)

    def test_getting_from_database(self):
        """Verify that we can get from the database."""
        installed = Toaster(id=1)
        self.session.add(installed)
        self.session.commit()

        toaster = self.manager.install_fixture("from_database")
        self.assertEqual(toaster.id, 1)

    def test_installing_collection(self):
        """Verify that a collection of fixtures is in the database."""
        self.manager.install_fixture("model_list")

        self.assertEqual(self.session.query(Toaster).count(), 2)

    def test_inheritance_and_relationship(self):
        """Verify that inheritance works with relationships."""
        model, model_1 = self.manager.install_fixtures(('model', 'model_1'))

        self.assertTrue(isinstance(model.color, Color))
        self.assertTrue(isinstance(model_1.color, Color))

    def test_explicit_foreign_key(self):
        """Verify that we can get a db-computed foreign key explicitely."""
        model = self.manager.install_fixture('model_with_explicit_fk')
        assert model.color_id is not None

    def test_uninstall_deletes_fixtures(self):
        """Verify uninstalling a fixture drops it from the database."""
        self.manager.install_fixture("color")

        # sanity check
        self.assertEqual(self.session.query(Color).count(), 1)

        self.manager.uninstall_fixture("color")

        self.assertEqual(self.session.query(Color).count(), 0)
Пример #25
0
def test_custom_builder():
    manager = FixturesManager(get_builder=DictBuilder())
    manager.load('./charlatan/tests/example/data/custom_builder.yaml')
    assert manager.get_fixture('toaster').slots == 3
Пример #26
0
 def test_uninstall_all_fixtures(self):
     manager = FixturesManager()
     manager.load('./charlatan/tests/data/simple.yaml')
     assert len(manager.install_all_fixtures()) == 1
     manager.uninstall_all_fixtures()
     assert len(manager.installed_keys) == 0
Пример #27
0
from __future__ import absolute_import

import mock

from charlatan import testcase
from charlatan import testing
from charlatan import FixturesManager
from charlatan.builder import Builder


fixtures_manager = FixturesManager()
fixtures_manager.load(
    './charlatan/tests/data/relationships_without_models.yaml')


class TestTestCase(testing.TestCase, testcase.FixturesManagerMixin):

    def _pre_setup(self):
        self.fixtures_manager = fixtures_manager
        self.init_fixtures()
        self.install_fixtures(('simple_dict', 'dict_with_nest'))

    def _post_teardown(self):
        self.uninstall_all_fixtures()

    def test_install_fixture(self):
        """Verify install_fixture should return the installed fixture."""
        self.uninstall_all_fixtures()

        simple_dict = self.install_fixture('simple_dict')
        self.assertEqual(simple_dict['field1'], 'lolin')
Пример #28
0
class TestSqlalchemyFixtures(testing.TestCase):

    def setUp(self):
        self.session = Session()
        self.manager = FixturesManager(db_session=self.session)
        self.manager.load("./charlatan/tests/data/relationships.yaml")

        Base.metadata.create_all(engine)

    def tearDown(self):
        Base.metadata.drop_all(engine)
        self.session.close()

    def test_double_install(self):
        """Verify that there's no double install."""
        self.manager.install_fixture("model")
        self.manager.install_fixture("color")

        self.assertEqual(self.session.query(Toaster).count(), 1)
        self.assertEqual(self.session.query(Color).count(), 1)

    def test_getting_from_database(self):
        """Verify that we can get from the database."""
        installed = Toaster(id=1)
        self.session.add(installed)
        self.session.commit()

        toaster = self.manager.install_fixture("from_database")
        self.assertEqual(toaster.id, 1)

    def test_installing_collection(self):
        """Verify that a collection of fixtures is in the database."""
        self.manager.install_fixture("model_list")

        self.assertEqual(self.session.query(Toaster).count(), 2)

    def test_inheritance_and_relationship(self):
        """Verify that inheritance works with relationships."""
        model, model_1 = self.manager.install_fixtures(('model', 'model_1'))

        self.assertTrue(isinstance(model.color, Color))
        self.assertTrue(isinstance(model_1.color, Color))

    def test_explicit_foreign_key(self):
        """Verify that we can get a db-computed foreign key explicitely."""
        model = self.manager.install_fixture('model_with_explicit_fk')
        assert model.color_id is not None

    def test_uninstall_deletes_fixtures(self):
        """Verify uninstalling a fixture drops it from the database."""
        self.manager.install_fixture("color")

        # sanity check
        self.assertEqual(self.session.query(Color).count(), 1)

        self.manager.uninstall_fixture("color")

        self.assertEqual(self.session.query(Color).count(), 0)
Пример #29
0
 def test_install_fixture_override(self):
     """Verify that we can override a fixture field."""
     manager = FixturesManager()
     manager.load('./charlatan/tests/data/simple.yaml')
     fixture = manager.install_fixture('fixture', overrides={'now': None})
     self.assertEqual(fixture, {'now': None})
Пример #30
0
from bootcamp.bootcamp import make_app
from charlatan import FixturesManager
from clay import config

import pytest

fixtures_manager = FixturesManager()


@pytest.fixture(scope='session', autouse=True)
def init_test():
    fixtures_manager.load(
        config.get('fixtures'),
        models_package='bootcamp.models',
    )


@pytest.fixture
def app():
    print 'making app'
    return make_app()
Пример #31
0
def test_deep_inherit():
    manager = FixturesManager()
    manager.load('./charlatan/tests/example/data/deep_inherit.yaml')
    toaster2 = manager.get_fixture('toaster2')
    assert toaster2['toasts']['toast1']['price'] == 10
    assert toaster2['toasts']['toast1']['weight'] == 20
Пример #32
0
 def setUp(self):
     self.fm = FixturesManager()
     self.fm.load('./charlatan/tests/data/lists.yaml')
Пример #33
0
    def test_invalid_hook(self):
        """Verify that can't set an invalid hook."""

        manager = FixturesManager()
        with pytest.raises(KeyError):
            manager.set_hook("invalid", lambda p: p)
Пример #34
0
 def test_get_all_fixtures(self):
     manager = FixturesManager()
     manager.load('./charlatan/tests/data/simple.yaml')
     assert len(manager.get_all_fixtures()) == 1
Пример #35
0
 def test_set_hook(self):
     """Verify that we can set a hook."""
     manager = FixturesManager()
     manager.set_hook("before_save", lambda p: p)
Пример #36
0
    def setUp(self):
        self.session = Session()
        self.manager = FixturesManager(db_session=self.session)
        self.manager.load("./charlatan/tests/data/relationships.yaml")

        Base.metadata.create_all(engine)
Пример #37
0
    def setUp(self):
        self.session = Session()
        self.manager = FixturesManager(db_session=self.session)
        self.manager.load("./charlatan/tests/data/relationships.yaml")

        Base.metadata.create_all(engine)
 def setUp(self):
     self.fixtures_manager = FixturesManager()
     self.fixtures_manager.load(
         './charlatan/tests/data/relationships_without_models.yaml')
     self.init_fixtures()
Пример #39
0
from charlatan import testing
from charlatan import FixturesManager
from charlatan.tests.fixtures.models import Session, Base, engine
from charlatan.tests.fixtures.models import Toaster

session = Session()
manager = FixturesManager(db_session=session)
manager.load("./charlatan/tests/example/data/sqlalchemy.yaml")


class TestSqlalchemyFixtures(testing.TestCase):
    def setUp(self):
        self.manager = manager

        # There's a lot of different patterns to setup and teardown the
        # database. This is the simplest possibility.
        Base.metadata.create_all(engine)

    def tearDown(self):
        Base.metadata.drop_all(engine)
        session.close()

    def test_double_install(self):
        """Verify that there's no double install."""
        self.manager.install_fixture('toaster')

        toaster = session.query(Toaster).one()
        assert toaster.color.name == 'red'
Пример #40
0
 def test_load_empty_file(self):
     """Verify we can load a emtpy file."""
     manager = FixturesManager()
     manager.load('./charlatan/tests/data/empty.yaml')
     self.assertEqual(list(manager.keys()), [])
Пример #41
0
from charlatan import testing
from charlatan import FixturesManager
from charlatan.tests.fixtures.models import Session, Base, engine
from charlatan.tests.fixtures.models import Toaster

session = Session()
manager = FixturesManager(db_session=session)
manager.load("./charlatan/tests/example/data/sqlalchemy.yaml")


class TestSqlalchemyFixtures(testing.TestCase):

    def setUp(self):
        self.manager = manager

        # There's a lot of different patterns to setup and teardown the
        # database. This is the simplest possibility.
        Base.metadata.create_all(engine)

    def tearDown(self):
        Base.metadata.drop_all(engine)
        session.close()

    def test_double_install(self):
        """Verify that there's no double install."""
        self.manager.install_fixture('toaster')

        toaster = session.query(Toaster).one()
        assert toaster.color.name == 'red'
Пример #42
0
    def test_uninstall_fixture(self):
        manager = FixturesManager()
        manager.load(
            './charlatan/tests/data/relationships_without_models.yaml')

        manager.install_fixture('simple_dict')
        manager.uninstall_fixture('simple_dict')

        # verify we are forgiving with list inputs
        manager.install_fixtures('simple_dict')
        manager.uninstall_fixtures('simple_dict')