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']
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
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
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')
def test_refresh_token(): actor = Actor(LocalMemoryEngine(), [], {}) with patch('requests.post', mock_response('inoreader.refresh_token')): actor.refresh_token() actor.refresh_token()
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
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'
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'
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')
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
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
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' }]
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
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}']
def test_rt(): actor = Actor(LocalMemoryEngine(), [], {}) args, func = actor.match('rt 1221106159907680256') data = func(*args) assert data['id_str'] == '1221131656481923073'
def test_follow_limited(): actor = Actor(LocalMemoryEngine(), [], {}) args, func = actor.match('follow @jack') assert not any(list(func(*args)))
def test_follow_username(): actor = Actor(LocalMemoryEngine(), [], {}) args, func = actor.match('follow @jack') for account in func(*args): assert account['screen_name'] == 'jack'
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
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'
def test_fail(): engine = LocalMemoryEngine() actor = ActorBase(engine, [], {}) with pytest.raises(PerformanceError): actor.fail('Failure')
def test_future(): engine = LocalMemoryEngine() bucket = engine.bucket('loda.actors.builtin.hold') bucket.put('foo', 1577923200) helper = HoldingHelper(engine) assert helper['foo']
def test_push(): engine = LocalMemoryEngine() actor = ActorBase(engine, [], {}) actor.push('foo', 1) assert actor.get('foo') == [1]
def test_delete(): engine = LocalMemoryEngine() actor = ActorBase(engine, [], {}) actor.put('foo', True) actor.delete('foo') assert actor.get('foo') is None
def test_pull(): engine = LocalMemoryEngine() actor = ActorBase(engine, [], {}) actor.push('foo', 1) assert list(actor.pull('foo')) == [1]
def test_get(): engine = LocalMemoryEngine() actor = ActorBase(engine, [], {}) assert not actor.get('foo')