def test_active_country_gets_program(self): active_country = w_factories.CountryFactory( country="Active", code="AT", ) inactive_country = w_factories.CountryFactory(country="Inactive", code="IT") country_access_active = w_factories.CountryAccessFactory( country=active_country, tolauser=self.tola_user) country_access_inactive = w_factories.CountryAccessFactory( country=inactive_country, tolauser=self.tola_user) self.tola_user.countryaccess_set.add(country_access_active, country_access_inactive) self.tola_user.active_country = active_country self.tola_user.save() active_program = w_factories.ProgramFactory(funding_status="Funded", ) active_program.country.set([active_country]) inactive_program = w_factories.ProgramFactory(funding_status="Funded") inactive_program.country.clear() inactive_program.country.set([inactive_country]) response = self.client.get('/') self.assertEqual(response.status_code, 200) self.assertEqual(len(response.context['programs']), 1) self.assertEqual(response.context['programs'][0].id, active_program.id) # test selected country overrides: response = self.client.get('/{pk}/'.format(pk=inactive_country.id)) self.assertEqual(response.status_code, 200) self.assertEqual(len(response.context['programs']), 1) self.assertEqual(response.context['programs'][0].id, inactive_program.id) self.tola_user.refresh_from_db() self.assertEqual(self.tola_user.active_country, inactive_country)
def test_template_renders_no_program_links_for_zero_indicator_programs( self): """per github ticket #855""" active_country = w_factories.CountryFactory( country="Active", code="AT", ) self.tola_user.active_country = active_country self.tola_user.save() two_id, one_id, zero_id = get_programs_for_country(active_country) response = self.client.get('/') self.assertEqual(response.status_code, 200) self.assertEqual(len(response.context['programs']), 3) soup = BeautifulSoup(response.content, features="lxml") program_list = soup.find("section", class_="home__program-list") articles = program_list.find_all("article", class_="program-list__program") self.assertEqual(len(articles), 3) link_ids = [] for article in articles: link = article.find('h4').find('a') if link: href = link.attrs['href'] pk = int(href.lstrip('/program/')[:-5]) link_ids.append(pk) text_list = article.find('ul', class_='nav--text-list') if link: self.assertIsNotNone(text_list) self.assertEqual(len(text_list.find_all('li')), 2) else: self.assertIsNone(text_list) self.assertEqual(set(link_ids), set([two_id, one_id])) self.assertIsNone(soup.find(href='/program/{0}/0/0/'.format(zero_id)))
def setUp(self): country = w_factories.CountryFactory() self.program = w_factories.RFProgramFactory(tiers=True, levels=2) self.program.country.add(country) for level in self.program.levels.all(): i_factories.RFIndicatorFactory(program=self.program, level=level, targets=500, results=400) tola_user = w_factories.TolaUserFactory(country=country) w_factories.grant_program_access(tola_user, self.program, country, 'high') self.client.force_login(tola_user.user)
def setUp(self): country = w_factories.CountryFactory() self.program = w_factories.RFProgramFactory(migrated=False) self.program.country.add(country) for _, level in Indicator.OLD_LEVELS: i_factories.RFIndicatorFactory(program=self.program, old_level=level, targets=500, results=400) tola_user = w_factories.TolaUserFactory(country=country) w_factories.grant_program_access(tola_user, self.program, country, 'high') self.client.force_login(tola_user.user)
def setUp(self): country = w_factories.CountryFactory() self.program = w_factories.RFProgramFactory(migrated=False) self.program.country.add(country) self.indicator = i_factories.RFIndicatorFactory( program=self.program, target_frequency=Indicator.ANNUAL, targets=500, results=True) tola_user = w_factories.TolaUserFactory(country=country) w_factories.grant_program_access(tola_user, self.program, country, 'high') self.client.force_login(tola_user.user)
def setUp(self): country = w_factories.CountryFactory() self.program_empty = w_factories.RFProgramFactory() self.program_empty.country.add(country) self.program_full = w_factories.RFProgramFactory(tiers=True, levels=1) self.program_full.country.add(country) for level in self.program_full.levels.all(): indicator = i_factories.RFIndicatorFactory(program=self.program_full, level=level, targets=True) site = w_factories.SiteProfileFactory(country=country) result = i_factories.ResultFactory(indicator=indicator, achieved=100) result.site.set([site]) self.site = site tola_user = w_factories.TolaUserFactory(country=country) w_factories.grant_program_access(tola_user, self.program_empty, country, 'high') self.client.force_login(tola_user.user)
def test_programs_have_indicator_counts(self): active_country = w_factories.CountryFactory( country="Active", code="AT", ) self.tola_user.active_country = active_country self.tola_user.save() two_id, one_id, zero_id = get_programs_for_country(active_country) response = self.client.get('/') self.assertEqual(len(response.context['programs']), 3) indicator_counts = {} for program in response.context['programs']: indicator_counts[program.id] = program.indicator_count self.assertEqual(indicator_counts[two_id], 2) self.assertEqual(indicator_counts[one_id], 1) self.assertEqual(indicator_counts[zero_id], 0)
def setUp(self): country = w_factories.CountryFactory() self.program = w_factories.RFProgramFactory( migrated=True, tiers=[u'Spécîal Chåracters1', u'###!@#$', 'asdf'], levels=2) self.program.country.add(country) self.indicator = i_factories.RFIndicatorFactory( program=self.program, target_frequency=Indicator.ANNUAL, targets=500, results=True, level=self.program.levels.all()[3]) tola_user = w_factories.TolaUserFactory(country=country) w_factories.grant_program_access(tola_user, self.program, country, 'high') self.client.force_login(tola_user.user)
def setUpTestData(cls): cls.country = w_factories.CountryFactory() cls.user = w_factories.TolaUserFactory() cls.user.countries.add(cls.country) for case in cls.expected_cases: program = w_factories.ProgramFactory( reporting_period_start=cls.program_start_date, reporting_period_end=cls.program_end_date, funding_status='Funded', name=case['name']) program.country.add(cls.country) for c in range(case['indicator_count']): data_count = 0 indicator = do_add_indicator(program) if c < case['targets_defined']: do_add_defined_target(indicator) if c < case['reported_results']: collect_date = cls.collect_date + datetime.timedelta( days=data_count) data_count += 1 result = do_add_reported_result(indicator, collect_date, program) if c < case['results_evidence']: do_add_evidence(result, program)
def init(self): self.home_country = w_factories.CountryFactory(country='HOME country', code='HM') self.in_country = w_factories.CountryFactory(country='IN country', code='IN') self.out_country = w_factories.CountryFactory(country='OUT country', code='OUT') self.program_in_country = w_factories.ProgramFactory( name='program in IN country', gaitid='inpr', country=self.in_country, reporting_period_start=datetime.date(2016, 1, 1), reporting_period_end=datetime.date(2016, 12, 31)) self.program_in_country.country.add(self.in_country) self.program_out_of_country = w_factories.ProgramFactory( name='program in OUT country', gaitid='outpr', country=self.out_country, reporting_period_start=datetime.date(2016, 1, 1), reporting_period_end=datetime.date(2016, 12, 31)) self.program_out_of_country.country.clear() self.program_out_of_country.country.add(self.out_country) self.add_indicators() self.add_results() if Organization.objects.filter(pk=1).count() == 1: self.mercy_corps_organization = Organization.objects.get(pk=1) else: self.mercy_corps_organization = w_factories.OrganizationFactory( pk=1) self.partner_organization = w_factories.OrganizationFactory( name="Partner Org") user = d_factories.UserFactory(first_name='mercy corps', last_name='country low') self.mercy_corps_country_low = w_factories.TolaUserFactory( name="mercy corps country low", organization=self.mercy_corps_organization, country=self.home_country, user=user) w_factories.grant_country_access(self.mercy_corps_country_low, self.in_country, COUNTRY_ROLE_CHOICES[0][0]) user = d_factories.UserFactory(first_name='mercy corps', last_name='country admin') self.mercy_corps_country_admin = w_factories.TolaUserFactory( name="mercy corps country admin", organization=self.mercy_corps_organization, country=self.home_country, user=user) w_factories.grant_country_access(self.mercy_corps_country_admin, self.in_country, COUNTRY_ROLE_CHOICES[1][0]) user = d_factories.UserFactory(first_name='mercy corps', last_name='program low') self.mercy_corps_low = w_factories.TolaUserFactory( name="mercy corps low", organization=self.mercy_corps_organization, country=self.home_country, user=user) w_factories.grant_program_access(self.mercy_corps_low, self.program_in_country, self.in_country, PROGRAM_ROLE_CHOICES[0][0]) user = d_factories.UserFactory(first_name='mercy corps', last_name='program medium') self.mercy_corps_medium = w_factories.TolaUserFactory( name="mercy corps medium", organization=self.mercy_corps_organization, country=self.home_country, user=user) w_factories.grant_program_access(self.mercy_corps_medium, self.program_in_country, self.in_country, PROGRAM_ROLE_CHOICES[1][0]) user = d_factories.UserFactory(first_name='mercy corps', last_name='program high') self.mercy_corps_high = w_factories.TolaUserFactory( name="mercy corps high", organization=self.mercy_corps_organization, country=self.home_country, user=user) w_factories.grant_program_access(self.mercy_corps_high, self.program_in_country, self.in_country, PROGRAM_ROLE_CHOICES[2][0]) user = d_factories.UserFactory(first_name='mercy corps', last_name='super admin') self.mercy_corps_super_admin = w_factories.TolaUserFactory( name="mercy corps super admin", organization=self.mercy_corps_organization, country=self.home_country, user=user) self.mercy_corps_super_admin.user.is_superuser = True self.mercy_corps_super_admin.user.save() user = d_factories.UserFactory(first_name='non mercy corps', last_name='program low') self.non_mercy_corps_low = w_factories.TolaUserFactory( name="non-MC low", organization=self.partner_organization, country=self.home_country, user=user) w_factories.grant_program_access(self.non_mercy_corps_low, self.program_in_country, self.in_country, PROGRAM_ROLE_CHOICES[0][0]) user = d_factories.UserFactory(first_name='non mercy corps', last_name='program medium') self.non_mercy_corps_medium = w_factories.TolaUserFactory( name="non-MC medium", organization=self.partner_organization, country=self.home_country, user=user) w_factories.grant_program_access(self.non_mercy_corps_medium, self.program_in_country, self.in_country, PROGRAM_ROLE_CHOICES[1][0]) user = d_factories.UserFactory(first_name='non mercy corps', last_name='program high') self.non_mercy_corps_high = w_factories.TolaUserFactory( name="non-MC medium", organization=self.partner_organization, country=self.home_country, user=user) w_factories.grant_program_access(self.non_mercy_corps_high, self.program_in_country, self.in_country, PROGRAM_ROLE_CHOICES[2][0]) self.external_service = i_factories.ExternalServiceFactory()