def test_since_with_filter(self):
        # Arrange
        sc = SupplyChainFactory.create(name="Supply Chain 1")
        sa = StrategicActionFactory.create(name="SA 01", supply_chain=sc)
        sau = StrategicActionUpdateFactory.create(
            status=StrategicActionUpdate.Status.IN_PROGRESS,
            supply_chain=sc,
            strategic_action=sa,
        )

        # Act
        sau_prog = StrategicActionUpdate.objects.since(
            deadline=date.today() - timedelta(days=1),
            supply_chain=sc,
            status=StrategicActionUpdate.Status.IN_PROGRESS,
        )

        sau_comp = StrategicActionUpdate.objects.since(
            deadline=date.today() - timedelta(days=1),
            supply_chain=sc,
            status=StrategicActionUpdate.Status.READY_TO_SUBMIT,
        )

        # Assert
        assert sau_prog[0] == sau
        assert sau_comp.count() == 0
Esempio n. 2
0
    def test_update_details_ongoing(self, logged_in_client, test_user):
        # Arrange
        sc_name = "ceramics"
        sa_name = "action 01"
        update_slug = "05-2021"
        sc = SupplyChainFactory.create(
            name=sc_name,
            gov_department=test_user.gov_department,
            last_submission_date=date.today(),
        )
        sa = StrategicActionFactory.create(name=sa_name,
                                           supply_chain=sc,
                                           is_ongoing=True)
        StrategicActionUpdateFactory(
            slug=update_slug,
            status=Status.SUBMITTED,
            submission_date=date.today(),
            strategic_action=sa,
            supply_chain=sc,
        )

        # Act
        resp = logged_in_client.get(
            reverse(
                "monthly-update-review",
                kwargs={
                    "supply_chain_slug": sc_name,
                    "action_slug": slugify(sa_name),
                    "update_slug": update_slug,
                },
            ))

        # Assert
        assert resp.context["supply_chain_name"] == sc_name
        assert resp.context["completion_estimation"] == "Ongoing"
    def test_SC_complete_summary_with_archived(self, logged_in_client,
                                               taskcomp_stub, test_user):
        # Arrange
        SupplyChainFactory.create(
            is_archived=True,
            archived_reason="reason",
            gov_department=test_user.gov_department,
        )

        # Act
        resp = logged_in_client.get(taskcomp_stub["url"])

        # Assert
        assert SupplyChain.objects.all().count() == 4
        assert resp.context["view"].sum_of_supply_chains == 3
        assert resp.context["view"].num_updated_supply_chains == 1
def taskcomp_stub(test_user):
    sc_name = "Supply Chain 1"
    sc = SupplyChainFactory.create(
        name=sc_name,
        gov_department=test_user.gov_department,
        last_submission_date=date.today(),
    )
    scs = SupplyChainFactory.create_batch(
        2, gov_department=test_user.gov_department)
    sa = StrategicActionFactory.create(supply_chain=sc)
    StrategicActionUpdateFactory(
        status=Status.SUBMITTED,
        submission_date=date.today(),
        strategic_action=sa,
        supply_chain=sc,
    )

    yield {
        "sc_name":
        sc_name,
        "url":
        reverse(
            "supply-chain-update-complete",
            kwargs={"supply_chain_slug": slugify(sc_name)},
        ),
    }
def test_sc_risk_status():
    # Arrange
    sc_name = "optional"

    # Act
    sc = SupplyChainFactory.create(name=sc_name)

    # Assert
    assert SupplyChain.objects.count() == 1
    assert SupplyChain.objects.get(name=sc_name).risk_severity_status == ""
    def test_update_on_umbrella(slef, logged_in_client, test_user):
        # Arrange
        u_name = "houseware"
        sc_name = "ceramics"

        u = SupplyChainUmbrellaFactory.create(name=u_name)
        SupplyChainFactory.create(
            name=sc_name,
            gov_department=test_user.gov_department,
            supply_chain_umbrella=u,
        )

        # Act
        resp = logged_in_client.get(
            reverse("supply-chain-task-list",
                    kwargs={"supply_chain_slug": slugify(u_name)}), )

        # Assert
        assert resp.context["view"].supply_chain_name == u_name
Esempio n. 7
0
def update_stub(test_user):
    sc_name = "Supply Chain 1"
    sa_name = "action 01"
    sa_completion = "2021-02-01"
    update_slug = "05-2021"
    sau_rag = "Amber"
    sau_reason = "Brexit negotiations"

    sc = SupplyChainFactory.create(
        name=sc_name,
        gov_department=test_user.gov_department,
        last_submission_date=date.today(),
    )
    sa = StrategicActionFactory.create(name=sa_name,
                                       supply_chain=sc,
                                       target_completion_date=sa_completion)
    StrategicActionUpdateFactory(
        slug=update_slug,
        status=Status.SUBMITTED,
        submission_date=date.today(),
        strategic_action=sa,
        supply_chain=sc,
        implementation_rag_rating=sau_rag,
        reason_for_delays=sau_reason,
    )

    yield {
        "sc":
        sc,
        "sa":
        sa,
        "sc_name":
        sc_name,
        "sa_name":
        sa_name,
        "sa_completion":
        sa_completion,
        "sau_rag":
        sau_rag,
        "sau_reason":
        sau_reason,
        "update_slug":
        update_slug,
        "url":
        reverse(
            "monthly-update-review",
            kwargs={
                "supply_chain_slug": slugify(sc_name),
                "action_slug": slugify(sa_name),
                "update_slug": update_slug,
            },
        ),
    }
    def test_SC_unlink_umbrella(self, test_user):
        # Arrange
        umbrella = SupplyChainUmbrellaFactory.create(
            gov_department=test_user.gov_department, )
        sc = SupplyChainFactory.create(gov_department=test_user.gov_department,
                                       supply_chain_umbrella=umbrella)

        # Act
        sc.supply_chain_umbrella = None

        # Assert
        self.validate(sc, {}, objects_saved=1)
def model_stub(test_user):
    sc = SupplyChainFactory.create(
        name=sc_name,
        gov_department=test_user.gov_department,
        last_submission_date=date.today(),
    )
    sa = StrategicActionFactory.create(supply_chain=sc, name=sa_name)
    StrategicActionUpdateFactory(
        status=Status.SUBMITTED,
        submission_date=date(day=1, month=1, year=2020),
        strategic_action=sa,
        supply_chain=sc,
    )
    def test_receive_stage_missing_summary(self):
        # Arrage
        sc = SupplyChainFactory.create()
        vul_obj = VulnerabilityAssessmentFactory.build(supply_chain=sc)

        # Act
        receive = VulAssessmentReceiveStageFactory.build(
            receive_stage_summary_4=None, vulnerability=vul_obj)

        # Assert
        with pytest.raises(ValidationError) as exc_info:
            receive.full_clean()
            receive.save()

        assert VulAssessmentReceiveStage.objects.count() == 0
    def test_supply_stage_missing_RAG(self):
        # Arrage
        sc = SupplyChainFactory.create()
        vul_obj = VulnerabilityAssessmentFactory.build(supply_chain=sc)

        # Act
        supply = VulAssessmentSupplyStageFactory.build(
            supply_stage_rag_rating=None, vulnerability=vul_obj)

        # Assert
        with pytest.raises(ValidationError) as exc_info:
            supply.full_clean()
            supply.save()

        assert VulAssessmentSupplyStage.objects.count() == 0
    def test_auth_success(self, logged_in_client, test_user):
        # Arrange
        sc = SupplyChainFactory.create()

        # Act
        resp = logged_in_client.get(
            reverse(
                "chain-details-info",
                kwargs={
                    "dept": test_user.gov_department,
                    "supply_chain_slug": sc.slug
                },
            ))

        # Assert
        assert resp.status_code == 200
    def test_auth_on_dept(self, logged_in_client):
        # Arrange
        dept_name = "other_dep"
        dept = GovDepartmentFactory(name=dept_name)
        sc = SupplyChainFactory.create(gov_department=dept)

        # Act
        resp = logged_in_client.get(
            reverse(
                "chain-details-info",
                kwargs={
                    "dept": dept_name,
                    "supply_chain_slug": sc.slug
                },
            ))

        # Assert
        assert resp.status_code == 200
    def test_supply_chain_scenario_assessment_is_optional(self, logged_in_ogd):
        # Arrange
        dept = GovDepartment.objects.first()
        sc = SupplyChainFactory.create(gov_department=dept)

        # Act
        resp = logged_in_ogd.get(
            reverse(
                "chain-details-info",
                kwargs={
                    "dept": dept.name,
                    "supply_chain_slug": sc.slug
                },
            ))

        # Assert
        assert resp.status_code == 200
        assert not hasattr(resp.context["sc"], "scenario_assessment")
    def test_vul_object_save(self):
        # Arrage
        # Act
        sc = SupplyChainFactory.create()
        vul_obj = VulnerabilityAssessmentFactory.create(supply_chain=sc)
        VulAssessmentSupplyStageFactory.create(vulnerability=vul_obj)
        VulAssessmentReceiveStageFactory.create(vulnerability=vul_obj)
        VulAssessmentMakeStageFactory.create(vulnerability=vul_obj)
        VulAssessmentDeliverStageFactory.create(vulnerability=vul_obj)
        VulAssessmentStoreStageFactory.create(vulnerability=vul_obj)

        # Assert
        assert SupplyChain.objects.count() == 1
        assert VulnerabilityAssessment.objects.count() == 1
        assert VulAssessmentSupplyStage.objects.count() == 1
        assert VulAssessmentReceiveStage.objects.count() == 1
        assert VulAssessmentMakeStage.objects.count() == 1
        assert VulAssessmentStoreStage.objects.count() == 1
        assert VulAssessmentDeliverStage.objects.count() == 1
Esempio n. 16
0
def sc_stub(test_user):
    sc_name = "Supply Chain 1"
    sc_con_name = "HelloWorld"
    sc_con_email = "hello@local"
    sc_vul_status = RAGRating.GREEN
    sc_risk_status = Rating.MEDIUM
    sc = SupplyChainFactory.create(
        name=sc_name,
        gov_department=test_user.gov_department,
        contact_name=sc_con_name,
        contact_email=sc_con_email,
        vulnerability_status=sc_vul_status,
        risk_severity_status=sc_risk_status,
    )
    yield {
        "sc_name": sc_name,
        "sc_con_name": sc_con_name,
        "sc_con_email": sc_con_email,
        "sc_vul_status": sc_vul_status,
        "sc_risk_status": sc_risk_status,
        "url": reverse("supply-chain-summary"),
    }