Ejemplo n.º 1
0
def test_set_key_prefix():
    bm2 = Bitmapist(client, prefix='HELLO')
    bm2.delete_all()
    bm2.mark_attribute('paid_user', 123)
    assert 'HELLO:at:paid_user' in \
        client.keys()
    bm.delete_all()
Ejemplo n.º 2
0
def test_set_divider():
    bm2 = Bitmapist(client, divider='_')
    bm2.delete_all()
    bm2.mark_attribute('paiduser', 123)
    assert 'trackist_at_paiduser' in \
        client.keys()
    bm.delete_all()
Ejemplo n.º 3
0
def test_set_key_prefix():
    bm2 = Bitmapist(client, prefix='HELLO')
    bm2.delete_all()
    bm2.mark_attribute('paid_user', 123)
    assert 'HELLO:at:paid_user' in \
        client.keys()
    bm.delete_all()
Ejemplo n.º 4
0
def test_set_divider():
    bm2 = Bitmapist(client, divider='_')
    bm2.delete_all()
    bm2.mark_attribute('paiduser', 123)
    assert 'trackist_at_paiduser' in \
        client.keys()
    bm.delete_all()
Ejemplo n.º 5
0
def test_bit_operation_with_expiration():
    # Given that temporary bitop keys are set to expire in 1 second
    bm_expire = Bitmapist(client, temp_ttl=1)
    bm_expire.delete_all()

    # When a temporary bit op is created (this one with the NOT bitop)
    bm_expire.mark_attribute('paid_user', 4)
    non_paid = bm_expire.bit_op_not(bm_expire.get_attribute('paid_user'))

    # It exists at first
    assert 5 in non_paid

    # But after 1 second, i.e. the TTL, has passed
    time.sleep(1)

    # Then the bitmap doesn't exist anymore
    assert len(non_paid) == 0
Ejemplo n.º 6
0
def test_bit_operation_with_expiration():
    # Given that temporary bitop keys are set to expire in 1 second
    bm_expire = Bitmapist(client, temp_ttl=1)
    bm_expire.delete_all()

    # When a temporary bit op is created (this one with the NOT bitop)
    bm_expire.mark_attribute('paid_user', 4)
    non_paid = bm_expire.bit_op_not(bm_expire.get_attribute('paid_user'))

    # It exists at first
    assert 5 in non_paid

    # But after 1 second, i.e. the TTL, has passed
    time.sleep(1)

    # Then the bitmap doesn't exist anymore
    assert len(non_paid) == 0
Ejemplo n.º 7
0
# -*- coding: utf-8 -*-
from datetime import datetime, timedelta

from bitmapist import Bitmapist, MixinCounts
import redis
import time

client = redis.Redis('localhost')
bm = Bitmapist(client)


def test_convert_start_bits_to_btye():
    counter = MixinCounts()
    assert counter._convert_to_start_byte(-16) == -2
    assert counter._convert_to_start_byte(-15) == -1
    assert counter._convert_to_start_byte(-10) == -1
    assert counter._convert_to_start_byte(-9) == -1
    assert counter._convert_to_start_byte(-8) == -1
    assert counter._convert_to_start_byte(-7) == MixinCounts.ERROR
    assert counter._convert_to_start_byte(-1) == MixinCounts.ERROR
    assert counter._convert_to_start_byte(0) == 0
    assert counter._convert_to_start_byte(1) == 1
    assert counter._convert_to_start_byte(2) == 1
    assert counter._convert_to_start_byte(7) == 1
    assert counter._convert_to_start_byte(8) == 1
    assert counter._convert_to_start_byte(9) == 2
    assert counter._convert_to_start_byte(120) == 15
    assert counter._convert_to_start_byte(122) == 16
    assert counter._convert_to_start_byte(127) == 16
    assert counter._convert_to_start_byte(128) == 16