def test_get(memory_store: MemoryStore) -> None: key = Key(KeyType.DIMENSION, 'user1', 'state') assert memory_store.get(key) == { 'variable_1': 1, 'variable_a': 'a', 'variable_true': True } date = datetime(2018, 3, 7, 19, 35, 31, 0, timezone.utc) key = Key(KeyType.TIMESTAMP, 'user1', 'session', [], date) assert memory_store.get(key) == { 'events': 1, '_start_time': date.isoformat() }
def test_get_range_start_end_time_no_dimensions_match( memory_store: MemoryStore) -> None: key = Key(KeyType.DIMENSION, 'user1', 'session_dim', ['dimC']) blocks = memory_store.get_range( key, datetime(2018, 3, 7, 19, 35, 31, 0, timezone.utc), datetime(2018, 3, 7, 22, 38, 31, 0, timezone.utc)) assert len(blocks) == 0
def test_get_range_count_negative_partial_dimensions_match( memory_store: MemoryStore) -> None: key = Key(KeyType.DIMENSION, 'user1', 'session_dim', ['dimA']) blocks = memory_store.get_range( key, datetime(2018, 3, 7, 22, 38, 31, 0, timezone.utc), None, -2) assert len(blocks) == 2 assert blocks[0][1]['_start_time'] == datetime(2018, 3, 7, 19, 35, 31, 0, timezone.utc).isoformat()
def test_get_range_count_negative_from_first_element( memory_store: MemoryStore, key_type_and_group) -> None: """ Tests that the range get does not include the blocks that lie on the boundary """ key = Key(key_type_and_group[0], 'user1', key_type_and_group[1]) blocks = memory_store.get_range( key, datetime(2018, 3, 7, 19, 35, 31, 0, timezone.utc), None, -2) assert len(blocks) == 0
def test_get_range_end_count(memory_store: MemoryStore) -> None: """ Tests that the range get does not include the blocks that lie on the boundary """ end = Key('user1', 'session', datetime(2018, 3, 7, 22, 38, 31, 0, timezone.utc)) blocks = memory_store.get_range(end, None, -2) assert len(blocks) == 2 assert blocks[0][1]['_start_time'] == datetime(2018, 3, 7, 20, 35, 35, 0, timezone.utc).isoformat()
def test_get_range_count_positive(memory_store: MemoryStore, key_type_and_group) -> None: """ Tests that the range get does not include the blocks that lie on the boundary """ key = Key(key_type_and_group[0], 'user1', key_type_and_group[1]) blocks = memory_store.get_range( key, datetime(2018, 3, 7, 19, 35, 31, 0, timezone.utc), None, 2) assert len(blocks) == 2 assert blocks[0][1]['_start_time'] == datetime(2018, 3, 7, 20, 35, 35, 0, timezone.utc).isoformat()
def init_memory_store(store: MemoryStore) -> None: store.save(Key('user1', 'state'), { 'variable_1': 1, 'variable_a': 'a', 'variable_true': True }) date = datetime(2018, 3, 7, 19, 35, 31, 0, timezone.utc) store.save(Key('user1', 'session', date), { 'events': 1, '_start_time': date.isoformat() }) date = datetime(2018, 3, 7, 20, 35, 35, 0, timezone.utc) store.save(Key('user1', 'session', date), { 'events': 2, '_start_time': date.isoformat() }) date = datetime(2018, 3, 7, 21, 36, 31, 0, timezone.utc) store.save(Key('user1', 'session', date), { 'events': 3, '_start_time': date.isoformat() }) date = datetime(2018, 3, 7, 22, 38, 31, 0, timezone.utc) store.save(Key('user1', 'session', date), { 'events': 4, '_start_time': date.isoformat() }) date = datetime(2018, 3, 7, 23, 40, 31, 0, timezone.utc) store.save(Key('user1', 'session', date), { 'events': 5, '_start_time': date.isoformat() }) date = datetime(2018, 3, 8, 23, 40, 31, 0, timezone.utc) store.save(Key('user1', 'session'), { 'events': 6, '_start_time': date.isoformat() })
def init_memory_store(store: MemoryStore) -> None: store.save( Key(KeyType.DIMENSION, 'user1', 'state'), { 'variable_1': 1, 'variable_a': 'a', 'variable_true': True }) date = datetime(2018, 3, 7, 19, 35, 31, 0, timezone.utc) store.save( Key(KeyType.TIMESTAMP, 'user1', 'session', [], date), { 'events': 1, '_start_time': date.isoformat() }) store.save( Key(KeyType.DIMENSION, 'user1', 'session_dim', ['dimA', 'session1']), { 'events': 1, '_start_time': date.isoformat() }) date = datetime(2018, 3, 7, 20, 35, 35, 0, timezone.utc) store.save( Key(KeyType.TIMESTAMP, 'user1', 'session', [], date), { 'events': 2, '_start_time': date.isoformat() }) store.save( Key(KeyType.DIMENSION, 'user1', 'session_dim', ['dimB', 'session2']), { 'events': 2, '_start_time': date.isoformat() }) date = datetime(2018, 3, 7, 21, 36, 31, 0, timezone.utc) store.save( Key(KeyType.TIMESTAMP, 'user1', 'session', [], date), { 'events': 3, '_start_time': date.isoformat() }) store.save( Key(KeyType.DIMENSION, 'user1', 'session_dim', ['dimA', 'session3']), { 'events': 3, '_start_time': date.isoformat() }) date = datetime(2018, 3, 7, 22, 38, 31, 0, timezone.utc) store.save( Key(KeyType.TIMESTAMP, 'user1', 'session', [], date), { 'events': 4, '_start_time': date.isoformat() }) store.save( Key(KeyType.DIMENSION, 'user1', 'session_dim', ['dimB', 'session4']), { 'events': 4, '_start_time': date.isoformat() }) date = datetime(2018, 3, 7, 23, 40, 31, 0, timezone.utc) store.save( Key(KeyType.TIMESTAMP, 'user1', 'session', [], date), { 'events': 5, '_start_time': date.isoformat() }) store.save( Key(KeyType.DIMENSION, 'user1', 'session_dim', ['dimA', 'session5']), { 'events': 5, '_start_time': date.isoformat() }) date = datetime(2018, 3, 8, 23, 40, 31, 0, timezone.utc) store.save( Key(KeyType.TIMESTAMP, 'user1', 'session', [], date), { 'events': 6, '_start_time': date.isoformat() }) store.save( Key(KeyType.DIMENSION, 'user1', 'session_dim', ['dimB', 'session6']), { 'events': 6, '_start_time': date.isoformat() })
def test_get_all(memory_store: MemoryStore) -> None: assert len(memory_store.get_all('user1')) == 13