class SubmissionTypeTest(TestCase, CaseTestMixin):
    fixtures = get_case_fixtures()

    def setUp(self):
        self.setup_test()
        self.hearing_request_type = SubmissionType.objects.get(
            id=SUBMISSION_TYPE_HEARING_REQUEST)

    @freeze_time("2019-01-10 10:00:00")
    def test_get_available_submission_types_for_case(self):
        direction_kwargs = {
            "direction__in": [DIRECTION_BOTH, DIRECTION_PUBLIC_TO_TRA]
        }

        test_data = [
            ("SOME_KEY", None, False),
            ("PROV_FACTS_HEARINGS_TIMER", datetime(2019, 1, 9), False),
            ("PROV_FACTS_HEARINGS_TIMER", datetime(2019, 1, 11), True),
            ("PROV_FACTS_HEARINGS_TIMER", None, True),
        ]

        for key, due_date, contains in test_data:
            with self.subTest(key=key, due_date=due_date, contains=contains):
                workflow_state, __ = CaseWorkflowState.objects.set_value(
                    self.case, key, "", due_date)
                results = SubmissionType.objects.get_available_submission_types_for_case(
                    self.case, direction_kwargs)
                if contains:
                    self.assertEqual(results.count(), 1)
                    self.assertEqual(self.hearing_request_type, results[0])
                else:
                    self.assertEqual(results.count(), 0)
Esempio n. 2
0
class CaseAPITest(APITestCase, APISetUpMixin):
    fixtures = get_case_fixtures()

    def setUp(self):
        self.setup_test()

    @skip("Fix for updated security model")
    def test_user_access_denied(self):
        self.client.force_authenticate(user=self.user_denied, token=self.user_denied.auth_token)
        response = self.client.get(f"/api/v1/cases/organisation/{self.organisation.id}/")
        self.assertEqual(response.status_code, status.HTTP_401_UNAUTHORIZED)

    def test_user_access_allowed(self):
        self.client.force_authenticate(user=self.user_1, token=self.user_1.auth_token)
        response = self.client.get(f"/api/v1/cases/{self.case.id}/")
        self.assertEqual(response.status_code, status.HTTP_200_OK)

    def test_get_cases_assigned_user(self):
        self.client.force_authenticate(user=self.user_1, token=self.user_1.auth_token)
        response = self.client.get(f"/api/v1/cases/{self.case.id}/")
        response_data = response.json()
        self.assertEqual(response_data["response"]["result"]["id"], str(self.case.id))

    def test_get_cases_owner_user(self):
        self.client.force_authenticate(user=self.user_owner, token=self.user_1.auth_token)
        response = self.client.get(f"/api/v1/cases/{self.case.id}/")
        response_data = response.json()
        self.assertEqual(response_data["response"]["result"]["id"], str(self.case.id))

    @skip("Fix for updated security model")
    def test_get_cases_unassigned_user(self):
        self.client.force_authenticate(user=self.user_2, token=self.user_2.auth_token)
        response = self.client.get(f"/api/v1/cases/{self.case.id}/")
        response_data = response.json()
        self.assertEqual(len(response_data["response"]["results"]), 0)
Esempio n. 3
0
class SubmissionAPITest(APITestCase, APISetUpMixin):
    fixtures = get_case_fixtures(
        "submission_document_types.json",
    )

    def setUp(self):
        self.setup_test()

    def test_create_submission(self):
        payload = {
            "submission_type": "General",
            "submission_status_id": 7,
            "name": "General(name)",
        }
        self.client.force_authenticate(user=self.user_1, token=self.user_1.auth_token)
        url = f"/api/v1/cases/{self.case.id}/organisation/" f"{self.organisation.id}/submissions/"

        response = self.client.post(url, payload)
        self.assertEqual(response.status_code, status.HTTP_201_CREATED)
        response_data = response.json()
        self.assertEqual(response_data["response"]["result"]["submission"]["name"], "General(name)")
        self.assertEqual(response_data["response"]["result"]["submission"]["status"]["id"], 7)
        self.assertEqual(
            response_data["response"]["result"]["submission"]["type"]["name"], "General"
        )

    def test_get_all_organisation_submissions(self):
        pass

    def test_get_case_submissions(self):
        pass

    def test_access_denied_get_submissions(self):
        pass
class OutcomesTests(TestCase, CaseTestMixin):
    fixtures = get_case_fixtures()  # 'workflow_template_anti_dumping.json')

    def setUp(self):
        self.setup_test()
        self.workflow = Workflow(
            {"root": [{
                "key": "MY_GROUP",
                "children": []
            }]})

    def setup_workflow(self, children):
        self.workflow["root"][0]["children"] = children
        CaseWorkflow.objects.filter(case=self.case).update(
            workflow=self.workflow)
        self.case.refresh_from_db()

    def setup_case_change_task_attributes(self):
        outcome_spec = [{
            "spec": [{
                "always": {
                    "value": {
                        "MY_KEY": {
                            "active": False,
                            "required": True
                        }
                    },
                }
            }],
            "type":
            "change_task_attributes",
        }]

        task = {
            "key": "MY_KEY",
            "response_type": {
                "key": "YESNO"
            },
            "outcome_spec": outcome_spec,
            "active": True,
            "required": False,
            "value": "yes",
        }
        self.setup_workflow([task])

    def test_change_task_attributes(self):
        self.setup_case_change_task_attributes()

        self.workflow.evaluate_outcome("MY_KEY", case=self.case)

        self.assertFalse(
            self.case.workflow.as_workflow().get_node("MY_KEY")["active"])
        self.assertTrue(
            self.case.workflow.as_workflow().get_node("MY_KEY")["required"])
Esempio n. 5
0
class CreateCaseTest(TestCase):
    fixtures = get_case_fixtures("sectors.json", )

    def setUp(self):
        Group.objects.create(name=SECURITY_GROUP_ORGANISATION_USER)
        Group.objects.create(name=SECURITY_GROUP_ORGANISATION_OWNER)

    def test_create_case(self):
        factory = APIRequestFactory()
        assert Case.objects.all().count() == 0
        request = factory.post("/cases/")
        response = CaseList.as_view()(request)
        assert response.status_code == 201
        # Check that a case was created
        assert Case.objects.all().count() == 1

        # Check the test user was created
        user = User.objects.last()
        assert user.email == TEST_EMAIL
class SubmissionTest(TestCase, CaseTestMixin):
    fixtures = get_case_fixtures()

    def setUp(self):
        self.setup_test()
        self.hearing_request_type = SubmissionType.objects.get(
            id=SUBMISSION_TYPE_HEARING_REQUEST)

    def test_create_without_window_based_due_date(self):
        submission = Submission.objects.create(
            name=self.hearing_request_type.name,
            type=self.hearing_request_type,
            status=self.hearing_request_type.default_status,
            case=self.case,
            organisation=self.organisation,
            created_by=self.user_owner,
        )

        self.assertIsNone(submission.due_at)
Esempio n. 7
0
class ProcessTimeGateActionsTest(TestCase, CaseTestMixin):
    fixtures = get_case_fixtures()

    def setUp(self):
        self.setup_test()
        self.workflow_state, __ = CaseWorkflowState.objects.set_value(
            self.case, "PROV_FACTS_HEARINGS_TIMER", None,
            datetime(2019, 1, 10))
        self.timegate_status = TimeGateStatus.objects.create(
            workflow_state=self.workflow_state)

    @freeze_time("2019-01-10 10:00:00")
    def test_run(self):
        process_timegate_actions()

        self.case.refresh_from_db()
        self.assertEqual(
            self.case.stage.key,
            "STATEMENT_OF_ESSENTIAL_FACTS_HEARING_REQUESTS_CLOSED")
        updated_status = TimeGateStatus.objects.get(
            workflow_state=self.workflow_state)
        self.assertEqual(updated_status.ack_at, timezone.now())
Esempio n. 8
0
class CaseTest(TestCase, CaseTestMixin):
    fixtures = get_case_fixtures()

    def setUp(self):
        self.now = datetime.datetime.now().date()
        self.user_owner = User.objects.create_user(
            name="org owner",  # /PS-IGNORE
            email="*****@*****.**",  # /PS-IGNORE
            password='******',  # /PS-IGNORE
            assign_default_groups=False)
        self.notice = Notice.objects.create(
            name='notice 1',
            reference='reference 1',
            case_type=CaseType.objects.get(acronym='AD'),
            published_at=self.now - datetime.timedelta(weeks=60),
            terminated_at=self.now + datetime.timedelta(weeks=60))
        self.notice_expected_type_acronyms = {
            "IR", "SC", "ER", "AR", "CR", "NE", "SR", "RI", "BU"
        }

    def test_correct_review_types(self):
        available_review_types = self.notice.available_case_review_types()
        self.assertEqual(len(available_review_types),
                         len(self.notice_expected_type_acronyms))
        available_review_types = set(
            [each["acronym"] for each in available_review_types])
        self.assertEqual(available_review_types,
                         self.notice_expected_type_acronyms)

    def test_correct_review_types_termination_change_1(self):
        """Now we change the termination_at value of the Notice object to 6 weeks from now,
        this should change the status of all of these review types of unavailable.
        """
        available_review_types = self.notice.available_case_review_types()
        for available_review in available_review_types:
            if available_review["acronym"] == "ER":
                self.assertEqual(available_review["dates"]["status"],
                                 "before_start")
            else:
                self.assertEqual(available_review["dates"]["status"], "ok")

        # Now we change the terminated_at value to 6 weeks from now
        self.notice.terminated_at = self.now + datetime.timedelta(weeks=6)
        self.notice.save()
        self.notice.refresh_from_db()

        available_review_types = self.notice.available_case_review_types()
        for available_review in available_review_types:
            if available_review["acronym"] != "RI":
                self.assertEqual(available_review["dates"]["status"],
                                 "after_end")

    def test_correct_review_types_termination_change_2(self):
        """Now we change the termination_at value of the Notice object to 15 weeks from now,
        this should change the status of SOME of these review types of unavailable.
        """
        self.notice.terminated_at = self.now + datetime.timedelta(weeks=15)
        self.notice.save()
        self.notice.refresh_from_db()
        available_review_types = self.notice.available_case_review_types()
        for available_review in available_review_types:
            # The Interim Review type should no longer be available as the measures are ending soon
            if available_review["acronym"] == "IR":
                self.assertEqual(available_review["dates"]["status"],
                                 "after_end")

            # The Scope Review type should be available as it's not 3 months till measure expiry
            if available_review["acronym"] == "SC":
                self.assertEqual(available_review["dates"]["status"], "ok")

    def test_correct_review_types_sf(self):
        """Tests that when the case_type of the Notice is changed, the review types also do.
        """
        safeguarding_expected_type_acronyms = {
            "RI",
            "SE",
            "SS",
            "TQ",
        }

        self.notice.case_type = CaseType.objects.get(
            acronym='SF')  # Change to safeguarding investigation
        self.notice.terminated_at = self.now + datetime.timedelta(
            weeks=104)  # Change to expire > 18 months from now
        self.notice.save()
        available_review_types = self.notice.available_case_review_types()

        self.assertEqual(len(available_review_types),
                         len(safeguarding_expected_type_acronyms))
        available_review_types = set(
            [each["acronym"] for each in available_review_types])
        self.assertEqual(available_review_types,
                         safeguarding_expected_type_acronyms)
Esempio n. 9
0
class SubmissionStatusAPITest(APITestCase, APISetUpMixin):
    fixtures = get_case_fixtures()

    def setUp(self):
        self.setup_test()
        load_system_params()
        self.submission_type = SubmissionType.objects.get(name="Questionnaire")
        self.submission = Submission.objects.create(
            type=self.submission_type,
            case=self.case,
            contact=self.user_1.contact,
            organisation=self.organisation,
            created_by=self.user_1,
        )
        self.url = (
            f"/api/v1/cases/{self.case.id}/organisation/{self.organisation.id}/"
            f"submission/{self.submission.id}/status/"
        )

    @patch("core.notifier.NotificationsAPIClient")
    def test_create_submission(self, notifier_client):
        payload = {
            "submission_type": "Questionnaire",
            "submission_status_id": 6,
            "status_context": "sent",
        }
        self.client.force_authenticate(user=self.user_1, token=self.user_1.auth_token)
        response = self.post_form(self.url, payload)

        self.assertEqual(response.status_code, status.HTTP_200_OK)
        self.assertEqual(notifier_client().send_email_notification.call_count, 0)
        response_data = response.data["response"]
        self.assertTrue(response_data["success"])
        self.assertEqual(response_data["result"]["submission"]["id"], str(self.submission.id))
        self.assertEqual(response_data["result"]["submission"]["type"]["name"], "Questionnaire")

    @patch("core.notifier.NotificationsAPIClient")
    def test_create_submission_with_notification(self, notifier_client):
        self.submission_type = SubmissionType.objects.get(name="General")
        self.submission.type = self.submission_type
        self.submission.save()
        payload = {
            "submission_type": "General",
            "submission_status_id": 7,
            "status_context": "received",
        }
        notifier_client().send_email_notification.return_value = {}
        self.client.force_authenticate(user=self.user_1, token=self.user_1.auth_token)
        response = self.post_form(self.url, payload)

        self.assertEqual(response.status_code, status.HTTP_200_OK)

        # Build footer
        base_footer = SystemParameter.get("NOTIFY_BLOCK_FOOTER")
        email = f"{self.case.reference}@{SystemParameter.get('TRADE_REMEDIES_EMAIL_DOMAIN')}"
        footer = "\n".join([base_footer, f"Contact: {email}"])
        notify_data = {
            "company": self.organisation.name,
            "case_name": self.case.name,
            "case_title": self.case.name,
            "case_number": self.case.reference,
            "case_type": self.case.type.name,
            "investigation_type": self.case.type.name,
            "dumped_or_subsidised": self.case.dumped_or_subsidised(),
            "product": "",
            "full_name": self.user_1.contact.name.strip(),
            "country": "N/A",
            "organisation_name": titlecase(self.organisation.name),
            "notice_url": self.submission.url or "N/A",  # TODO: Remove
            "notice_of_initiation_url": self.submission.url or "N/A",
            "login_url": public_login_url(),
            "submission_type": "General",
            "company_name": titlecase(self.submission.organisation.name)
            if self.submission.organisation
            else "",
            "deadline": "",
            "footer": footer,
            "email": email,
            "guidance_url": SystemParameter.get("LINK_HELP_BOX_GUIDANCE"),
        }
        notifier_client().send_email_notification.assert_called_once_with(
            email_address=self.user_1.email,
            personalisation=notify_data,
            reference=None,
            template_id="d6fb3018-2338-40c9-aa6d-f1195f5f65de",  # /PS-IGNORE
        )
        response_data = response.data["response"]
        self.assertTrue(response_data["success"])
        self.assertEqual(response_data["result"]["submission"]["id"], str(self.submission.id))
        self.assertEqual(response_data["result"]["submission"]["type"]["name"], "General")