當前位置: 首頁>>代碼示例>>Python>>正文


Python FixturesManager.install_fixture方法代碼示例

本文整理匯總了Python中charlatan.FixturesManager.install_fixture方法的典型用法代碼示例。如果您正苦於以下問題:Python FixturesManager.install_fixture方法的具體用法?Python FixturesManager.install_fixture怎麽用?Python FixturesManager.install_fixture使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在charlatan.FixturesManager的用法示例。


在下文中一共展示了FixturesManager.install_fixture方法的9個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: TestListOfFixtures

# 需要導入模塊: from charlatan import FixturesManager [as 別名]
# 或者: from charlatan.FixturesManager import install_fixture [as 別名]
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]
開發者ID:jvrsantacruz,項目名稱:charlatan,代碼行數:27,代碼來源:test_lists_of_fixtures.py

示例2: test_overrides_and_in_cache

# 需要導入模塊: from charlatan import FixturesManager [as 別名]
# 或者: from charlatan.FixturesManager import install_fixture [as 別名]
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'
開發者ID:rtoussaint,項目名稱:charlatan,代碼行數:9,代碼來源:test_fixtures_manager.py

示例3: test_uninstall_fixture

# 需要導入模塊: from charlatan import FixturesManager [as 別名]
# 或者: from charlatan.FixturesManager import install_fixture [as 別名]
    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')
開發者ID:rtoussaint,項目名稱:charlatan,代碼行數:13,代碼來源:test_fixtures_manager.py

示例4: TestSqlalchemyFixtures

# 需要導入模塊: from charlatan import FixturesManager [as 別名]
# 或者: from charlatan.FixturesManager import install_fixture [as 別名]
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)
開發者ID:rtoussaint,項目名稱:charlatan,代碼行數:60,代碼來源:test_sqlalchemy.py

示例5: test_install_fixture_with_now

# 需要導入模塊: from charlatan import FixturesManager [as 別名]
# 或者: from charlatan.FixturesManager import install_fixture [as 別名]
 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)})
開發者ID:rtoussaint,項目名稱:charlatan,代碼行數:10,代碼來源:test_fixtures_manager.py

示例6: TestSqlalchemyFixtures

# 需要導入模塊: from charlatan import FixturesManager [as 別名]
# 或者: from charlatan.FixturesManager import install_fixture [as 別名]
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)
開發者ID:joegilley,項目名稱:charlatan,代碼行數:37,代碼來源:test_sqlalchemy.py

示例7: test_install_fixture

# 需要導入模塊: from charlatan import FixturesManager [as 別名]
# 或者: from charlatan.FixturesManager import install_fixture [as 別名]
    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,
        })
開發者ID:rtoussaint,項目名稱:charlatan,代碼行數:14,代碼來源:test_fixtures_manager.py

示例8: test_uninstall_fixture

# 需要導入模塊: from charlatan import FixturesManager [as 別名]
# 或者: from charlatan.FixturesManager import install_fixture [as 別名]
    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,
        })
開發者ID:joegilley,項目名稱:charlatan,代碼行數:26,代碼來源:test_fixtures_manager.py

示例9: test_install_fixture_override

# 需要導入模塊: from charlatan import FixturesManager [as 別名]
# 或者: from charlatan.FixturesManager import install_fixture [as 別名]
 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})
開發者ID:rtoussaint,項目名稱:charlatan,代碼行數:8,代碼來源:test_fixtures_manager.py


注:本文中的charlatan.FixturesManager.install_fixture方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。