Exemplo n.º 1
0
def test_expired():
    engine = LocalMemoryEngine()
    bucket = engine.bucket('loda.actors.builtin.hold')
    bucket.put('foo', 1577836800)
    helper = HoldingHelper(engine)
    assert not helper['foo']
    assert not helper['foo']
Exemplo n.º 2
0
def test_hold_value_for():
    engine = LocalMemoryEngine()
    actor = Actor(engine, [], {})

    args, func = actor.match('hold foo for 1 minute')
    func(*args)

    bucket = engine.bucket('loda.actors.builtin.hold')
    assert bucket.get('foo') == 1577836860
Exemplo n.º 3
0
def test_hold_value_until():
    engine = LocalMemoryEngine()
    actor = Actor(engine, [], {})

    args, func = actor.match('hold foo for until tomorrow')
    func(*args)

    bucket = engine.bucket('loda.actors.builtin.hold')
    assert bucket.get('foo') == 1577923200
Exemplo n.º 4
0
def test_release():
    engine = LocalMemoryEngine()
    bucket = engine.bucket('loda.actors.builtin.hold')
    bucket.put('foo', 0)
    actor = Actor(engine, [], {})

    args, func = actor.match('release foo')
    func(*args)
    assert not bucket.has('foo')
Exemplo n.º 5
0
def test_refresh_token():
    actor = Actor(LocalMemoryEngine(), [], {})

    with patch('requests.post', mock_response('inoreader.refresh_token')):
        actor.refresh_token()

    actor.refresh_token()
Exemplo n.º 6
0
def test_first():
    engine = LocalMemoryEngine()
    actor = Actor(engine, {'list': [1, 2, 3]}, {})

    args, func = actor.match('pick 2 from list')
    result = list(func(*args))
    count = sum(result)
    assert count == 3
Exemplo n.º 7
0
def test_search_rate_limited():
    actor = Actor(LocalMemoryEngine(), [], {})
    args, func = actor.match('find tweets frmo:jack')

    with pytest.raises(PerformanceError) as ctx:
        list(func(*args))

    assert ctx.value.args[0] == 'Rate limit exceeded'
Exemplo n.º 8
0
def test_follow_error():
    actor = Actor(LocalMemoryEngine(), [], {})
    args, func = actor.match('follow @jack')

    with pytest.raises(PerformanceError) as ctx:
        list(func(*args))

    assert ctx.value.args[0] == 'Internal error'
Exemplo n.º 9
0
def test():
    engine = LocalMemoryEngine()
    bucket = engine.bucket('foo')
    bucket.put('foo', 'bar')

    bucket = engine.bucket('foo')
    assert bucket.has('foo')
    assert bucket.get('foo') == 'bar'

    bucket.push('items', 'one')
    assert list(bucket.pull('items')) == ['one']
    assert bucket.has('items', 'one')
    bucket.pop('items', 'one')
    assert not bucket.has('items', 'one')

    bucket.delete('items')
    assert not bucket.has('items')
Exemplo n.º 10
0
def test_search():
    actor = Actor(LocalMemoryEngine(), [], {})
    args, func = actor.match('find tweets frmo:jack')
    tweets = []

    for data in func(*args):
        tweets.append(data)

    assert len(tweets) == 1
Exemplo n.º 11
0
def test_follow_topic():
    actor = Actor(LocalMemoryEngine(), [], {})
    args, func = actor.match('follow podcasting')
    accounts = []

    for data in func(*args):
        accounts.append(data)

    assert len(accounts) == 2
Exemplo n.º 12
0
def test_tagged_articles():
    actor = Actor(LocalMemoryEngine(), [], {})
    args, func = actor.match('get latest articles tagged #loda')
    articles = []

    for article in func(*args):
        articles.append(article)

    assert articles == [{
        'title': 'Podcast listening without the app',
        'url': 'https://podnews.net/update/podinstall-launches'
    }]
Exemplo n.º 13
0
def test_articles_in_folder():
    actor = Actor(LocalMemoryEngine(), [], {})
    args, func = actor.match('get latest articles in Podcasting folder')
    articles = []

    for article in func(*args):
        articles.append(article)

    assert len(articles) == 2
    assert {
        'title': 'Deezer adds podcasting to its app in Colombia',
        'url': 'https://podnews.net/update/deezer-colombia'
    } in articles
Exemplo n.º 14
0
def _log(logger_method, actor_method=None):
    if not actor_method:
        actor_method = logger_method

    logs = []
    engine = LocalMemoryEngine()
    actor = ActorBase(engine, [], {})
    func = getattr(actor, actor_method)

    with patch('logging.Logger.%s' % logger_method, logs.append):
        func({'foo': 'bar'})

    assert logs == ['{\n    "foo": "bar"\n}']
Exemplo n.º 15
0
def test_rt():
    actor = Actor(LocalMemoryEngine(), [], {})
    args, func = actor.match('rt 1221106159907680256')
    data = func(*args)
    assert data['id_str'] == '1221131656481923073'
Exemplo n.º 16
0
def test_follow_limited():
    actor = Actor(LocalMemoryEngine(), [], {})
    args, func = actor.match('follow @jack')
    assert not any(list(func(*args)))
Exemplo n.º 17
0
def test_follow_username():
    actor = Actor(LocalMemoryEngine(), [], {})
    args, func = actor.match('follow @jack')
    for account in func(*args):
        assert account['screen_name'] == 'jack'
Exemplo n.º 18
0
def test_rate_limited():
    actor = Actor(LocalMemoryEngine(), [], {})
    args, func = actor.match('tweet the cat sat on the mat')
    data = func(*args)
    assert data is None
Exemplo n.º 19
0
def test_tweet():
    actor = Actor(LocalMemoryEngine(), [], {})
    args, func = actor.match('tweet the cat sat on the mat')
    data = func(*args)
    assert data['id_str'] == '1221133422271389697'
Exemplo n.º 20
0
def test_fail():
    engine = LocalMemoryEngine()
    actor = ActorBase(engine, [], {})

    with pytest.raises(PerformanceError):
        actor.fail('Failure')
Exemplo n.º 21
0
def test_future():
    engine = LocalMemoryEngine()
    bucket = engine.bucket('loda.actors.builtin.hold')
    bucket.put('foo', 1577923200)
    helper = HoldingHelper(engine)
    assert helper['foo']
Exemplo n.º 22
0
def test_push():
    engine = LocalMemoryEngine()
    actor = ActorBase(engine, [], {})
    actor.push('foo', 1)
    assert actor.get('foo') == [1]
Exemplo n.º 23
0
def test_delete():
    engine = LocalMemoryEngine()
    actor = ActorBase(engine, [], {})
    actor.put('foo', True)
    actor.delete('foo')
    assert actor.get('foo') is None
Exemplo n.º 24
0
def test_pull():
    engine = LocalMemoryEngine()
    actor = ActorBase(engine, [], {})
    actor.push('foo', 1)
    assert list(actor.pull('foo')) == [1]
Exemplo n.º 25
0
def test_get():
    engine = LocalMemoryEngine()
    actor = ActorBase(engine, [], {})
    assert not actor.get('foo')