def test_program_view(self):
        # Create 3 reports, 1 tied to a different user
        for i in range(2):
            PinnedReportFactory(
                tola_user=self.tola_user,
                program=self.program,
            )

        other_user = UserFactory(first_name='Other',
                                 last_name='User',
                                 username='******')
        other_tola_user = TolaUserFactory(user=other_user)
        PinnedReportFactory(
            tola_user=other_tola_user,
            program=self.program,
        )

        response = self.client.get(self.program.program_page_url)

        self.assertEqual(response.status_code, 200)
        pinned_reports = response.context['pinned_reports']
        self.assertEquals(len(pinned_reports), 3)  # 2 + 1 default

        # verify ordering - pinned reports should be sorted newest to oldest
        self.assertTrue(
            pinned_reports[0].creation_date > pinned_reports[1].creation_date)
    def setUp(self):
        self.user = UserFactory(first_name="Indicator",
                                last_name="CreateTest",
                                username="******")
        self.user.set_password('password')
        self.user.save()
        self.tola_user = TolaUserFactory(user=self.user)

        self.country = self.tola_user.country

        self.program = ProgramFactory(funding_status='Funded',
                                      reporting_period_start='2016-03-01',
                                      reporting_period_end='2020-05-01')
        self.program.country.add(self.country)
        self.program.save()
        self.indicator = IndicatorFactory(
            program=self.program,
            unit_of_measure_type=Indicator.NUMBER,
            is_cumulative=False,
            direction_of_change=Indicator.DIRECTION_OF_CHANGE_NONE,
            target_frequency=Indicator.ANNUAL)

        self.request_factory = RequestFactory()
        self.client = Client()
        self.client.login(username="******", password='******')
    def setUp(self):
        self.user = UserFactory(first_name="PeterPeter", last_name="PumpkinEater", username="******")
        self.user.set_password('orangethumb')
        self.user.save()
        self.tola_user = TolaUserFactory(user=self.user)
        self.country = self.tola_user.country
        self.program = ProgramFactory(
            funding_status='Funded', reporting_period_start='2016-03-01', reporting_period_end='2020-05-01')
        self.program.country.add(self.country)
        self.program.save()

        # TolaUser not available on User if not logged in
        self.client.login(username=self.user.username, password='******')
    def test_delete_of_pinned_report_not_owned_by_user(self):
        other_user = UserFactory(first_name='Other', last_name='User', username='******')
        other_tola_user = TolaUserFactory(user=other_user)
        pr = PinnedReportFactory(
            tola_user=other_tola_user,
            program=self.program,
        )

        self.assertEquals(models.PinnedReport.objects.count(), 1)

        data = {
            'pinned_report_id': pr.id,
        }

        response = self.client.post(reverse('delete_pinned_report'), data=data)

        self.assertEqual(response.status_code, 200)

        # nothing deleted!
        self.assertEquals(models.PinnedReport.objects.count(), 1)
 def setUpTestData(cls):
     super().setUpTestData()
     user = UserFactory(username="******")
     user.set_password("12345")
     user.save()
     cls.tola_user = TolaUserFactory(user=user)