def test_view_submitted_assessment_report_by_grantee(self):
        self.grantee = UserFactory.create(password=self.password)
        assign_role(self.grantee, "admin")
        assign_role(self.user, "admin")

        self.survey = SurveyFactory.create()

        self.survey_response = SurveyResponseFactory.create(
            organisation=self.grantee.organisation,
            survey=self.survey,
            level=1,
            submitted=timezone.now())
        self.section = SurveySectionFactory.create(number=1, )
        self.question = SurveyQuestionFactory.create(survey=self.survey,
                                                     level=1,
                                                     section=self.section)
        self.answer = SurveyAnswerFactory.create(response=self.survey_response,
                                                 question=self.question)
        self.invitation = InvitationFactory.create(
            survey=self.survey,
            grantee=self.survey_response.organisation,
            status=3,
            accepted=True,
            grantor=self.user.organisation)

        grantor_org = self.user.organisation
        order = OrderFactory.create(organisation=grantor_org,
                                    status=Order.STATUS_APPROVED)

        SubscriptionFactory.create(order=order)
        package = AssessmentPackageFactory.create(number_included=1,
                                                  price=900.00)
        AssessmentPurchaseFactory.create(
            package=package,
            order=order,
            order__organisation=grantor_org,
            order__status=Order.STATUS_APPROVED,
            number_included=1,
        )

        self.login(self.user.email, self.password)

        self.click_and_wait_for_page_load(
            self.browser.find_element_by_link_text("Invitations"), )
        self.assertTrue(EC.presence_of_element_located((By.LINK_TEXT, "View")))
        view_submitted_survey = self.browser.find_element_by_link_text("View")
        self.click_and_wait_for_page_load(view_submitted_survey)

        self.assertTrue(
            self.browser_wait.until(
                lambda browser: browser.find_element_by_link_text(
                    "Print report").is_enabled()))
        completion_percentage = self.browser_wait.until(
            lambda browser: self.browser.find_element_by_css_selector(
                ".number._700"))
        report_header = self.browser.find_element_by_tag_name("h2").text
        self.assertEquals(completion_percentage.text, "100%")
        self.assertIn("Full report", report_header)
예제 #2
0
 def test_with_submitted_response_id_not_submitted(self):
     response = SurveyResponseFactory.create(submitted=None, )
     invitation = InvitationFactory.create(
         survey=response.survey,
         grantee=response.organisation,
     )
     invitations = self.manager.with_submitted_response_id()
     self.assertSequenceEqual(invitations, [invitation])
     self.assertIsNone(invitations[0].response_id)
    def test_survey_continue_url(self):
        survey_response = SurveyResponseFactory.create(
            survey=self.survey,
            organisation=self.user.organisation,
        )

        request = self.create_request('get', user=self.user)
        view = self.view.as_view()
        response = view(request)
        self.assertEqual(response.status_code, 200)

        unexpected_url = reverse('survey-start', kwargs={'pk': self.survey.pk})
        expected_url = reverse('survey-progress', kwargs={'pk': survey_response.pk})
        self.assertContains(response, expected_url)
        self.assertNotContains(response, unexpected_url)
    def test_user_cannot_view_assessments_with_expired_subscription(self):
        self.grantor_org = self.user.organisation
        order = OrderFactory.create(organisation=self.grantor_org,
                                    status=Order.STATUS_APPROVED)

        current_date = date.today()
        SubscriptionFactory.create(order=order, end_date=current_date)

        self.grantee = UserFactory.create(password=self.password)
        assign_role(self.user, "admin")

        self.survey = SurveyFactory.create()

        self.survey_response = SurveyResponseFactory.create(
            organisation=self.grantee.organisation,
            survey=self.survey,
            level=1,
            submitted=timezone.now())
        self.section = SurveySectionFactory.create(number=1, )
        self.question = SurveyQuestionFactory.create(survey=self.survey,
                                                     level=1,
                                                     section=self.section)
        self.answer = SurveyAnswerFactory.create(response=self.survey_response,
                                                 question=self.question)
        self.invitation = InvitationFactory.create(
            survey=self.survey,
            grantee=self.survey_response.organisation,
            status=3,
            accepted=True,
            grantor=self.user.organisation)

        with self.wait_for_page_load():
            self.browser.find_element_by_link_text("Assessments").click()

        renew_subscription_field = self.browser.find_element_by_link_text(
            "Renew subscription")
        self.assertTrue(renew_subscription_field.is_enabled())

        assessment_notification = self.browser.find_element_by_class_name(
            "notification-header.pjax-update").text

        view_assessments_info_text = "Your subscription expires in 0 days"

        self.assertIn(view_assessments_info_text, assessment_notification)
    def test_get_survey_started(self):
        survey_response = SurveyResponseFactory.create(
            survey=self.survey,
            organisation=self.grantee.organisation,
        )
        surveys = list(self.get_context_data(self.grantee)['surveys'])
        self.assertSequenceEqual(surveys, [self.survey, self.empty_survey])

        self.assertEqual(surveys[0].survey_response, survey_response)
        progress = surveys[0].survey_response.progress
        expected_progress = {
            'slug': 'not-started',
            'is_complete': False,
            'label': 'Not yet started',
            'total': 1,
            'count': 0,
            'percentage': 0,
            'ratio': 0.0,
        }
        self.assertEqual(progress, expected_progress)
    def test_user_can_view_assessments_with_active_subscription(self):
        self.grantor_org = self.user.organisation
        order = OrderFactory.create(organisation=self.grantor_org,
                                    status=Order.STATUS_APPROVED)
        print("Order is", order)
        SubscriptionFactory.create(order=order)

        self.grantee = UserFactory.create(password=self.password)
        assign_role(self.user, "admin")

        self.survey = SurveyFactory.create()

        self.survey_response = SurveyResponseFactory.create(
            organisation=self.grantee.organisation,
            survey=self.survey,
            level=1,
            submitted=timezone.now())
        print("Survey response is", self.survey_response)
        self.section = SurveySectionFactory.create(number=1, )
        print("Section is", self.section)
        self.question = SurveyQuestionFactory.create(survey=self.survey,
                                                     level=1,
                                                     section=self.section)
        print("Queston is", self.question)
        self.answer = SurveyAnswerFactory.create(response=self.survey_response,
                                                 question=self.question)
        print("Answer is", self.answer)
        self.invitation = InvitationFactory.create(
            survey=self.survey,
            grantee=self.survey_response.organisation,
            status=3,
            accepted=True,
            grantor=self.user.organisation)
        print("Invitation is", self.invitation)
        with self.wait_for_page_load():
            self.browser.find_element_by_link_text("Assessments").click()
        import time
        time.sleep(10)
        self.assertTrue(EC.presence_of_element_located((By.LINK_TEXT, "View")))
        view_submitted_survey = self.browser.find_element_by_link_text("View")
        self.assertTrue(view_submitted_survey.is_enabled())
    def test_func_submit_assessment_received_by_grantee(self):

        survey_area = SurveyAreaFactory.create(name="Financial management",
                                               number=5)

        survey_section = SurveySectionFactory.create(
            area=survey_area, name="Financial management", number=1)

        que = SurveyQuestionFactory.create(survey=self.survey_list,
                                           section=survey_section)

        assign_role(self.user1, "admin")
        self.login(self.user1.email, self.password)

        self.click_and_wait_for_page_load(
            self.browser.find_element_by_css_selector(
                "a[href='/survey/view/assessment']"))
        self.browser.find_element_by_xpath(
            "//a[contains(text(),'Start assessment')]").click()

        q1 = self.browser.find_elements_by_css_selector(
            "label[class='ui-check']")
        self.click_button(q1[0])

        time.sleep(50)
        view_summary = self.browser.find_element_by_xpath(
            "//a[contains(text(),'View summary')]")
        self.click_button(view_summary)

        submit = self.browser.find_element_by_xpath(
            "//div[@class='d-flex']//button[contains(text(),'Submit')]")
        self.click_button(submit)

        self.browser_wait.until(lambda browser: EC.new_window_is_opened(
            browser.current_window_handle))

        self.browser.switch_to.window(self.browser.window_handles[0])
        confirm = self.browser_wait.until(
            lambda browser: browser.find_element_by_xpath(
                "//button[@type='submit']"))
        self.click_button(confirm)

        expected_msg = "Assessment published successfully"
        actual_msg = self.browser.find_element_by_xpath(
            "//div[contains(text(),'Assessment published successfully')]").text
        self.assertEqual(expected_msg, actual_msg)

        self.logout()

        res = SurveyResponseFactory.create(survey=self.survey_list,
                                           organisation=self.grantee,
                                           level=1)

        InvitationFactory.create(survey=self.survey_list,
                                 grantor=self.grantor,
                                 grantee=self.grantee,
                                 accepted=True,
                                 level=1,
                                 status=3,
                                 purchase=self.assess)

        SurveyAnswerFactory.create(response=res, question=que)

        assign_role(self.user, 'admin')
        self.login(self.user.email, self.password)

        self.click_and_wait_for_page_load(
            self.browser.find_element_by_xpath("//a[@href='/survey/invite']"))

        org_names = self.browser.find_elements_by_css_selector(
            "table tbody tr td div[class='text-bold']")

        self.assertEqual(str(self.grantee), org_names[-1].text)

        self.browser.find_element_by_xpath(
            "//a[contains(text(),'View')]").click()

        expected_completion_percentage = "100%"

        actual_completion_percentage = self.browser.find_element_by_xpath(
            "//span[@class='number _700 primary-font-color']").text

        self.assertEqual(expected_completion_percentage,
                         actual_completion_percentage)
 def create_response(self, **kwargs):
     defaults = {'level': 1, 'survey': self.survey}
     defaults.update(kwargs)
     return SurveyResponseFactory.create(**defaults)
예제 #9
0
 def test_with_submitted_response_id_other_survey(self):
     response = SurveyResponseFactory.create(submitted=timezone.now(), )
     invitation = InvitationFactory.create(grantee=response.organisation, )
     invitations = self.manager.with_submitted_response_id()
     self.assertSequenceEqual(invitations, [invitation])
     self.assertIsNone(invitations[0].response_id)