예제 #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']
예제 #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
예제 #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
예제 #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')
예제 #5
0
def test_refresh_token():
    actor = Actor(LocalMemoryEngine(), [], {})

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

    actor.refresh_token()
예제 #6
0
파일: test_pick.py 프로젝트: Podiant/loda
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
예제 #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'
예제 #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'
예제 #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')
예제 #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
예제 #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
예제 #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'
    }]
예제 #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
예제 #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}']
예제 #15
0
def test_rt():
    actor = Actor(LocalMemoryEngine(), [], {})
    args, func = actor.match('rt 1221106159907680256')
    data = func(*args)
    assert data['id_str'] == '1221131656481923073'
예제 #16
0
def test_follow_limited():
    actor = Actor(LocalMemoryEngine(), [], {})
    args, func = actor.match('follow @jack')
    assert not any(list(func(*args)))
예제 #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'
예제 #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
예제 #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'
예제 #20
0
def test_fail():
    engine = LocalMemoryEngine()
    actor = ActorBase(engine, [], {})

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