コード例 #1
0
def test_update_incident(arf, api_user, update_key, update_value):
    """
    Tests that we can PUT /incidents/<pk> and mutate fields that get saved to
    the DB.
    """
    persisted_incidents = IncidentFactory.create_batch(5)

    incident = persisted_incidents[0]
    serializer = serializers.IncidentSerializer(incident)
    serialized = serializer.data

    updated = serialized
    del updated["reporter"]  # can't update reporter
    if update_key:
        updated[update_key] = update_value

    req = arf.put(reverse("incident-detail", kwargs={"pk": incident.pk}),
                  updated,
                  format="json")
    force_authenticate(req, user=api_user)

    response = IncidentViewSet.as_view({"put": "update"})(req, pk=incident.pk)
    print(response.rendered_content)
    assert response.status_code == 200, "Got non-200 response from API"

    if update_key:
        new_incident = Incident.objects.get(pk=incident.pk)
        assert (getattr(new_incident, update_key) == update_value
                ), "Updated value wasn't persisted to the DB"
コード例 #2
0
def test_update_incident_lead(arf, api_user):
    """
    Tests that we can update the incident lead by name
    """
    persisted_incidents = IncidentFactory.create_batch(5)

    incident = persisted_incidents[0]
    serializer = serializers.IncidentSerializer(incident)
    updated = serializer.data

    users = ExternalUser.objects.all()

    new_lead = users[0]
    while new_lead == incident.lead:
        new_lead = random.choices(users)

    updated["lead"] = serializers.ExternalUserSerializer(new_lead).data
    del updated["reporter"]  # can't update reporter

    req = arf.put(reverse("incident-detail", kwargs={"pk": incident.pk}),
                  updated,
                  format="json")
    force_authenticate(req, user=api_user)

    response = IncidentViewSet.as_view({"put": "update"})(req, pk=incident.pk)
    print(response.rendered_content)
    assert response.status_code == 200, "Got non-200 response from API"

    new_incident = Incident.objects.get(pk=incident.pk)
    assert new_incident.lead == new_lead
コード例 #3
0
def test_cannot_unset_severity(arf, api_user):
    """
    Tests that we cannot unset the incident severity
    """

    incident = IncidentFactory.create()
    serializer = serializers.IncidentSerializer(incident)
    updated = serializer.data

    updated["severity"] = None  # unset severity

    req = arf.put(reverse("incident-detail", kwargs={"pk": incident.pk}),
                  updated,
                  format="json")
    force_authenticate(req, user=api_user)

    response = IncidentViewSet.as_view({"put": "update"})(req, pk=incident.pk)
    print(response.rendered_content)
    assert (response.status_code !=
            200), "Got 200 response from API when we expected an error"