コード例 #1
0
def update_action(arf, api_user, incident_id, action_data):
    req = arf.put(
        reverse("incident-action-list", kwargs={"incident_pk": incident_id}),
        action_data,
        format="json",
    )
    force_authenticate(req, user=api_user)

    return IncidentActionViewSet.as_view({"put": "update"})(
        req, incident_pk=incident_id, pk=action_data["pk"]
    )
コード例 #2
0
def test_list_actions_by_incident(arf, api_user):
    incident = IncidentFactory.create()

    req = arf.get(reverse("incident-action-list", kwargs={"incident_pk": incident.pk}))
    force_authenticate(req, user=api_user)
    response = IncidentActionViewSet.as_view({"get": "list"})(
        req, incident_pk=incident.pk
    )

    content = json.loads(response.rendered_content)
    print(content)
    assert response.status_code == 200, "Got non-200 response from API"

    assert len(content["results"]) == len(incident.action_items())
    for action in content["results"]:
        assert action["details"]
        assert "done" in action
        assert action["user"]
コード例 #3
0
def test_delete_action(arf, api_user):
    incident = IncidentFactory.create()
    user = ExternalUserFactory.create()

    action = ActionFactory.create(user=user, incident=incident)

    req = arf.delete(
        reverse("incident-action-list", kwargs={"incident_pk": incident.pk}),
        format="json",
    )
    force_authenticate(req, user=api_user)
    response = IncidentActionViewSet.as_view({"delete": "destroy"})(
        req, incident_pk=incident.pk, pk=action.pk
    )

    assert response.status_code == 204, "Got non-204 response from API"
    with pytest.raises(Action.DoesNotExist):
        Action.objects.get(pk=action.pk)
コード例 #4
0
ファイル: test_actions.py プロジェクト: zfouts/response
def test_create_action(arf, api_user):
    incident = IncidentFactory.create()
    user = ExternalUserFactory.create()

    action_model = ActionFactory.build(user=user)
    action = serializers.ActionSerializer(action_model).data

    req = arf.post(
        reverse("incident-action-list", kwargs={"incident_pk": incident.pk}),
        action,
        format="json",
    )
    force_authenticate(req, user=api_user)
    response = IncidentActionViewSet.as_view({"post": "create"
                                              })(req, incident_pk=incident.pk)

    assert response.status_code == 201, "Got non-201 response from API"
    assert Action.objects.filter(details=action_model.details).exists()