def test_clear(self): """Test clear method.""" storage = InMemoryImpressionStorage(100) storage.put( [Impression('key1', 'feature1', 'on', 'l1', 123456, 'b1', 321654)]) assert storage._impressions.qsize() == 1 storage.clear() assert storage._impressions.qsize() == 0
def test_queue_full_hook(self, mocker): """Test queue_full_hook is executed when the queue is full.""" storage = InMemoryImpressionStorage(100) queue_full_hook = mocker.Mock() storage.set_queue_full_hook(queue_full_hook) impressions = [ Impression('key%d' % i, 'feature1', 'on', 'l1', 123456, 'b1', 321654) for i in range(0, 101) ] storage.put(impressions) assert queue_full_hook.mock_calls == mocker.call()
def test_push_pop_impressions(self): """Test pushing and retrieving impressions.""" storage = InMemoryImpressionStorage(100) storage.put([Impression('key1', 'feature1', 'on', 'l1', 123456, 'b1', 321654)]) storage.put([Impression('key2', 'feature1', 'on', 'l1', 123456, 'b1', 321654)]) storage.put([Impression('key3', 'feature1', 'on', 'l1', 123456, 'b1', 321654)]) # Assert impressions are retrieved in the same order they are inserted. assert storage.pop_many(1) == [ Impression('key1', 'feature1', 'on', 'l1', 123456, 'b1', 321654) ] assert storage.pop_many(1) == [ Impression('key2', 'feature1', 'on', 'l1', 123456, 'b1', 321654) ] assert storage.pop_many(1) == [ Impression('key3', 'feature1', 'on', 'l1', 123456, 'b1', 321654) ] # Assert inserting multiple impressions at once works and maintains order. impressions = [ Impression('key1', 'feature1', 'on', 'l1', 123456, 'b1', 321654), Impression('key2', 'feature1', 'on', 'l1', 123456, 'b1', 321654), Impression('key3', 'feature1', 'on', 'l1', 123456, 'b1', 321654) ] assert storage.put(impressions) # Assert impressions are retrieved in the same order they are inserted. assert storage.pop_many(1) == [ Impression('key1', 'feature1', 'on', 'l1', 123456, 'b1', 321654) ] assert storage.pop_many(1) == [ Impression('key2', 'feature1', 'on', 'l1', 123456, 'b1', 321654) ] assert storage.pop_many(1) == [ Impression('key3', 'feature1', 'on', 'l1', 123456, 'b1', 321654) ]