Exemplo n.º 1
0
    def test_raises_if_key_not_found(self):
        storage = InMemoryStorage()
        girl = Materializer(storage=storage)

        try:
            girl.get("test")
        except ValueError:
            err = sys.exc_info()[1]
            expect(err).to_have_an_error_message_of(
                'Key test not found in materials. Maybe you forgot to call "add_material" for this key?'
            )
        else:
            assert False, "Should not have gotten this far"

        try:
            girl.is_expired("test")
        except ValueError:
            err = sys.exc_info()[1]
            expect(err).to_have_an_error_message_of(
                'Key test not found in materials. Maybe you forgot to call "add_material" for this key?'
            )
        else:
            assert False, "Should not have gotten this far"

        try:
            girl.expire("test")
        except ValueError:
            err = sys.exc_info()[1]
            expect(err).to_have_an_error_message_of(
                'Key test not found in materials. Maybe you forgot to call "add_material" for this key?'
            )
        else:
            assert False, "Should not have gotten this far"
Exemplo n.º 2
0
    def test_can_get_value_if_material_girl_not_run(self):
        storage = InMemoryStorage()
        girl = Materializer(storage=storage)

        girl.add_material("test", lambda: "woot")

        value = girl.get("test")
        expect(value).to_equal("woot")
Exemplo n.º 3
0
    def test_can_miss_the_cache(self):
        storage = Mock(retrieve=Mock(return_value=None))

        girl = Materializer(storage=storage, load_on_cachemiss=False)
        girl.add_material("test", lambda: "woot")

        girl.run()
        value = girl.get("test")

        expect(value).to_be_null()
        expect(storage.acquire_lock.call_count).to_equal(1)
        storage.store.assert_called_once_with("test", "woot", expiration=10, grace_period=0)
    def test_can_get_value_after_material_girl_run(self):
        storage = InMemoryStorage()
        girl = Materializer(storage=storage)

        girl.add_material(
            'test',
            lambda: 'woot'
        )

        girl.run()

        value = girl.get('test')
        expect(value).to_equal('woot')