Exemplo n.º 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()
Exemplo n.º 2
0
 def test_notices_cyclic_dependencies(self):
     fm = FixturesManager()
     self.assertRaises(
         depgraph.HasACycle,
         fm.load,
         './charlatan/tests/data/cyclic_dependencies.yaml'
     )
Exemplo n.º 3
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'
Exemplo n.º 4
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)
Exemplo n.º 5
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)})
Exemplo n.º 6
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()
Exemplo n.º 7
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')
Exemplo n.º 8
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)
Exemplo n.º 9
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')
Exemplo n.º 10
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,
        })
Exemplo n.º 11
0
 def test_uninstall_non_installed_fixture(self):
     manager = FixturesManager()
     manager.load(
         './charlatan/tests/data/relationships_without_models.yaml')
     manager.uninstall_fixture('simple_dict')
Exemplo n.º 12
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})
Exemplo n.º 13
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'
Exemplo n.º 14
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
Exemplo n.º 15
0
 def test_get_all_fixtures(self):
     manager = FixturesManager()
     manager.load('./charlatan/tests/data/simple.yaml')
     assert len(manager.get_all_fixtures()) == 1
Exemplo n.º 16
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)
Exemplo n.º 17
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
Exemplo n.º 18
0
 def test_set_hook(self):
     """Verify that we can set a hook."""
     manager = FixturesManager()
     manager.set_hook("before_save", lambda p: p)
Exemplo n.º 19
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)
Exemplo n.º 20
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()
Exemplo n.º 21
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()), [])
Exemplo n.º 22
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
Exemplo n.º 23
0
 def setUp(self):
     self.fm = FixturesManager()
     self.fm.load('./charlatan/tests/data/lists.yaml')