コード例 #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
ファイル: test_twitter.py プロジェクト: Podiant/loda
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
ファイル: test_twitter.py プロジェクト: Podiant/loda
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
ファイル: test_twitter.py プロジェクト: Podiant/loda
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
ファイル: test_twitter.py プロジェクト: Podiant/loda
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
ファイル: test_twitter.py プロジェクト: Podiant/loda
def test_rt():
    actor = Actor(LocalMemoryEngine(), [], {})
    args, func = actor.match('rt 1221106159907680256')
    data = func(*args)
    assert data['id_str'] == '1221131656481923073'
コード例 #16
0
ファイル: test_twitter.py プロジェクト: Podiant/loda
def test_follow_limited():
    actor = Actor(LocalMemoryEngine(), [], {})
    args, func = actor.match('follow @jack')
    assert not any(list(func(*args)))
コード例 #17
0
ファイル: test_twitter.py プロジェクト: Podiant/loda
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
ファイル: test_twitter.py プロジェクト: Podiant/loda
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
ファイル: test_twitter.py プロジェクト: Podiant/loda
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')