Пример #1
0
    def test_sc_summary_multiple(self, logged_in_client, test_user):
        # Arrange
        SupplyChainFactory.create_batch(
            4, gov_department=test_user.gov_department)

        # Act
        resp = logged_in_client.get(reverse("supply-chain-summary"))

        # Assert
        assert resp.status_code == 200
        assert resp.context["supply_chains"].paginator.count == 4
def test_sc_homepage_pagination(num_supply_chains, logged_in_client, test_user,
                                url, num_supply_chains_returned):
    """Test pagination of supply chains on homepage.

    Check the correct number of supply chains are passed to homepage
    via context depending on total number linked to the user's department,
    and that the supply chains are annotated with 'strategic_action_count'.
    """
    SupplyChainFactory.create_batch(num_supply_chains,
                                    gov_department=test_user.gov_department)
    response = logged_in_client.get(url)
    assert response.status_code == 200
    assert response.context[
        "gov_department_name"] == test_user.gov_department.name
    assert len(response.context["supply_chains"]) == num_supply_chains_returned
    def test_dump_sc_data_multiple(self):
        # Arrange
        SupplyChainFactory.create_batch(5)

        # Act
        self.invoke_dump(MODEL_SUPPLY_CHAIN, self.data_file.name)
        rows = self.load_csv()

        # Assert
        assert len(rows) == 5

        names = [x["name"] for x in rows]
        assert all([x.startswith("Product ") for x in names])

        ids = [x["id"] for x in rows]
        assert len(ids) == len(set(ids))
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_homepage_filters_out_archived_supply_chains(
        logged_in_client, test_user):
    gov_department = test_user.gov_department
    # Create archived supply chains
    SupplyChainFactory.create_batch(5,
                                    gov_department=gov_department,
                                    is_archived=True,
                                    archived_reason="Reason")
    # Create non archived supply chains
    SupplyChainFactory.create_batch(5, gov_department=gov_department)

    num_unarchived_supply_chains = SupplyChain.objects.filter(
        is_archived=False).count()
    response = logged_in_client.get(reverse("sc-home"))

    assert len(
        response.context["supply_chains"]) == num_unarchived_supply_chains
Пример #6
0
    def test_pagination(
        self,
        logged_in_client,
        test_user,
        num_scs,
        url,
        pages_returned,
        objects_returned,
    ):
        # Arrange
        SupplyChainFactory.create_batch(
            num_scs, gov_department=test_user.gov_department)

        # Act
        resp = logged_in_client.get(url)

        # Assert
        p = resp.context["supply_chains"]

        assert resp.status_code == 200
        assert p.paginator.num_pages == pages_returned
        assert len(p.object_list) == objects_returned
def test_supply_chain_submitted_since_query():
    """
    Tests that that the custom 'submitted_since' query method
    on the SupplyChain model returns only supply chain objects
    with a last_submission_date after the given deadline.
    """
    SupplyChainFactory.create_batch(3, last_submission_date=date(2021, 4, 7))
    SupplyChainFactory.create_batch(3, last_submission_date=date(2021, 3, 7))
    SupplyChainFactory.create_batch(3, last_submission_date=None)
    supply_chains = SupplyChain.objects.all()
    assert supply_chains.submitted_since(date(2021, 4, 1)).count() == 3
def sc_stub():
    SupplyChainFactory.create_batch(5)

    yield SupplyChain.objects.all()