def test_pull_from_data_pipes(create_bldgs, update_pipe, data_pipes_batch, home_timeline_response): api_results = [home_timeline_response, []] with patch('mies.data_pipes.twitter_social_feed.web_fetcher.tweepy.API.home_timeline', side_effect=api_results): pull_from_data_pipes(data_pipes_batch) assert create_bldgs.call_count == 1 target_flr = data_pipes_batch[0]["connectedBldg"] + "-l0" keys = [p.id for p in home_timeline_response] create_bldgs.assert_has_calls([ call(TWITTER_SOCIAL_POST, keys, ANY, target_flr), call().apply_async()]) update_pipe.assert_called_once_with(data_pipes_batch[0]["_id"], {'latestId': home_timeline_response[1].id})
def invoke(): """ * Reads in pages all connected & active data-pipes from the DB * Each read page of data-pipes is sent to the web_fetcher service in a REST call """ logging.info("Invoking data-pipes...") count = 0 criteria = {"type": PERSONAL_TWITTER_FEED} for page in load_data_pipes(criteria=criteria): count += web_fetcher.pull_from_data_pipes(page) return "{} posts fetched..".format(count)