Пример #1
0
    def test_get_strategy(self):
        settings = fake_settings(
            MITHRIL_STRATEGY='mithril.tests.fake_strategy.FakeStrategy'
        )

        middleware = WhitelistMiddleware()
        strategy = middleware.get_strategy(settings)
        self.assertTrue(isinstance(strategy, FakeStrategy)) 
Пример #2
0
    def test_process_view_delegates_to_strategy(self):
        strategy = FakeStrategy()
        expected = random.randint(0, 10)

        def collect(*a, **kw):
            strategy.args = a
            strategy.kwargs = kw
            return expected

        strategy.process_view = collect

        mw = WhitelistMiddleware()
        mw.get_strategy = lambda *a: strategy

        result = mw.process_view(expected, expected, [], {})

        self.assertEqual(result, expected)
        self.assertEqual(strategy.args, (expected, expected))
        self.assertEqual(strategy.kwargs, {})