예제 #1
0
def bit_of_everything_queryset(bit_of_everything_item_count,
                               bit_of_everything_last_modified_times):
    """
    Generate a bunch of SCs, SA, and SAUs so we can be sure there's a good mix for the union queryset.
    Doing them this rather odd way helps check that the ordering works as expected
    by interleaving the last_modified values among the different models,
    such that simply concatenating the instances from each queryset would not be ordered by last_modified.
    To get an idea of what comes out, run the following at the console:
    ['sc' if i % 8 == 0 else 'sa' if i % 4 == 1 else 'sau' for i in range(0, 23)]
    """
    supply_chain_in_use = None
    strategic_action_in_use = None
    gov_department: GovDepartment = GovDepartment.objects.first()
    user = UserFactory(gov_department=gov_department)
    with mock.patch("django.utils.timezone.now") as mock_now:
        for i, last_modified in enumerate(
                bit_of_everything_last_modified_times):
            mock_now.return_value = last_modified
            if i % 8 == 0:
                supply_chain_in_use = SupplyChainFactory(
                    gov_department=gov_department)
                continue
            if i % 5 == 1:
                strategic_action_in_use = StrategicActionFactory(
                    supply_chain=supply_chain_in_use)
                continue
            StrategicActionUpdateFactory(
                supply_chain=supply_chain_in_use,
                strategic_action=strategic_action_in_use,
                user=user,
                status=StrategicActionUpdate.Status.SUBMITTED,
            )
def logged_in_ogd():
    dept = GovDepartmentFactory(name="OGD")
    user = UserFactory(first_name="joe", gov_department=dept)

    client = Client()
    client.force_login(user)

    yield client
def dit_user_request(gov_department):
    user = UserFactory(gov_department=gov_department)
    request = HttpRequest()
    request.user = user
    request.path = dummy_from_path
    request.META = {
        "HTTP_HOST": dummy_from_domain,
    }
    return request
    def test_ogd_other_dept(self, logged_in_client):
        # Arrange
        dept_name = "other_dep"
        dept = GovDepartmentFactory(name=dept_name)
        u = UserFactory(gov_department=dept)

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

        # Assert
        assert resp.status_code == 200
    def test_ogd_other_dept_error(self, logged_in_client):
        # Arrange
        dept_name = "other_dep"
        dept = GovDepartmentFactory(name=dept_name)
        u = UserFactory(gov_department=dept)

        # Act
        resp = logged_in_client.get(
            reverse(
                "action-progress-department",
                kwargs={"dept": dept_name},
            ))

        # Assert
        assert resp.status_code == 403
    def test_ogd_other_dept_error(self, logged_in_client):
        # Arrange
        dept_name = "other_dep"
        dept = GovDepartmentFactory(name=dept_name)
        sc_name = "ceramics"
        SupplyChainFactory(gov_department=dept, name=sc_name)
        u = UserFactory(gov_department=dept)

        # Act
        resp = logged_in_client.get(
            reverse(
                "action-progress-list",
                kwargs={
                    "dept": dept_name,
                    "supply_chain_slug": sc_name
                },
            ))

        # Assert
        assert resp.status_code == 403
def test_check_matching_gov_department_success():
    """Test True is returned if supply chain and user have same gov department."""
    g = GovDepartmentFactory()
    user = UserFactory(gov_department=g)
    supply_chain = SupplyChainFactory(gov_department=g)
    assert check_matching_gov_department(user, supply_chain)
def test_check_matching_gov_department_fail():
    """Test False returned if supply chain and user have different gov departments."""
    user = UserFactory()
    supply_chain = SupplyChainFactory()
    assert not check_matching_gov_department(user, supply_chain)
def test_user():
    user = UserFactory(first_name="Test")
    user.save()
    yield user