def test_no_data(self, _, crawler_task_mock, pipeline): factories.InstagramProfileFactory() factories.InstagramProfileFactory( friends_count=pipeline.DEFAULT_MINIMUM_FRIENDS_COUNT - 1) profiles_to_use = [ factories.InstagramProfileFactory( friends_count=pipeline.DEFAULT_MINIMUM_FRIENDS_COUNT), factories.InstagramProfileFactory( friends_count=pipeline.DEFAULT_MINIMUM_FRIENDS_COUNT + 1), ] pipeline.run_pipeline() assert crawler_task_mock.call_count == len(profiles_to_use) for run in range(len(profiles_to_use)): crawler_task_mock.assert_any_call( queue='test_queue_name', kwargs={ 'klass_name': 'KeywordClassifier', 'profile_id': profiles_to_use[run].id, 'task_type': 'pipeline', 'route': [ 'KeywordClassifier', 'DescriptionLengthClassifier', 'OnlyBloggersProcessor', ] })
def test_undecided_profiles(self, crawler_task_mock, profile_config, was_processed): profile = factories.InstagramProfileFactory(**profile_config) reprocess_instagram_profiles(friends_lower_bound=50000, period_weeks=0) assert crawler_task_mock.called is was_processed assert InstagramProfile.objects.get( id=profile.id ).reprocess_tries_count == profile.reprocess_tries_count + int( was_processed)
def test_matching_influencers(self, find_influencers_mock, *args): url = 'http://google.com' existing_influencers = {url: debra_factories.InfluencerFactory()} find_influencers_mock.return_value = existing_influencers, (url, ) instagram_profile = factories.InstagramProfileFactory() assert create_influencer_from_instagram(instagram_profile.id, False) == ( False, existing_influencers, )
def test_newly_created_profiles(self, crawler_task_mock, date_created, was_processed): profile = factories.InstagramProfileFactory( friends_count=50000, tags='lifestyle undecided', reprocess_tries_count=2, ) profile.date_created = date_created profile.save() reprocess_instagram_profiles(friends_lower_bound=50000, period_weeks=2) assert crawler_task_mock.called is was_processed assert InstagramProfile.objects.get( id=profile.id ).reprocess_tries_count == profile.reprocess_tries_count + int( was_processed)
def instagram_profile(self): return factories.InstagramProfileFactory( username='******', friends_count=51, followers_count=924, post_count=38, last_post_time=datetime(2016, 3, 2, 18, 43), api_data={ u'biography': u"I don't know what to write", u'full_name': u'Anonymous', }, api_data_history=[ { '2015-10-01': { u'biography': u"I don't know what to write", u'full_name': u'Anonymous', }, }, ])
def test_id_as_data(self, _, crawler_task_mock, pipeline, input_type): instagram_profile = factories.InstagramProfileFactory() pipeline.run_pipeline(data=input_type(instagram_profile.id)) assert crawler_task_mock.call_count == 1 assert crawler_task_mock.call_args[1] == { 'queue': 'test_queue_name', 'kwargs': { 'klass_name': 'KeywordClassifier', 'profile_id': instagram_profile.id, 'task_type': 'pipeline', 'route': [ 'KeywordClassifier', 'DescriptionLengthClassifier', 'OnlyBloggersProcessor', ] } }
def test_create_influencer(self, find_influencers_mock, create_influencer_platform_mock, create_platform_for_influencer_mock, *args): valid_url = 'https://twitter.com/JimCarrey' find_influencers_mock.return_value = dict(), (valid_url, ) def fake_create_influencer_platform(url, *args, **kwargs): influencer = debra_factories.InfluencerFactory() debra_factories.PlatformFactory(influencer=influencer, url=url) return influencer create_influencer_platform_mock.side_effect = ( fake_create_influencer_platform) def fake_create_platform_for_influencer(url, inf, *args, **kwargs): return debra_factories.PlatformFactory(url=url, influencer=inf) create_platform_for_influencer_mock.side_effect = ( fake_create_platform_for_influencer) instagram_profile = factories.InstagramProfileFactory() result = create_influencer_from_instagram(instagram_profile.id, False) assert Influencer.objects.count() == 1 assert result == (True, Influencer.objects.all()[0])
def test_profile_has_no_tags(self, processor, tags, expected_result): profile = factories.InstagramProfileFactory(tags=tags) assert processor.proceed(profile.id) is expected_result
def test_no_pipeline(self, _, crawler_task_mock, pipeline): pipeline.PIPELINE_ROUTE = None instagram_profile = factories.InstagramProfileFactory() pipeline.run_pipeline(data=instagram_profile.id) pipeline.run_pipeline() assert not crawler_task_mock.called
def test_default_api_data_history(self): instagram_profile = factories.InstagramProfileFactory() assert instagram_profile.api_data_history == []
def test_get_data_from_api_history(self, api_data_history, keys, expected_data): instagram_profile = factories.InstagramProfileFactory( api_data_history=api_data_history) assert instagram_profile._get_data_from_api_history( keys=keys) == expected_data
def test_get_url_from_api(self, api_data, expected_url): instagram_profile = factories.InstagramProfileFactory( api_data=api_data) assert instagram_profile.get_url_from_api() == (expected_url)