コード例 #1
0
ファイル: test_actions.py プロジェクト: zfouts/response
def test_update_action_sanitized(arf, api_user):
    incident = IncidentFactory.create()
    action = incident.action_items()[0]
    action_data = serializers.ActionSerializer(action).data

    action_data["details"] = "<iframe>this should be escaped</iframe>"
    response = update_action(arf, api_user, incident.pk, action_data)
    assert response.status_code == 200, "Got non-201 response from API"

    updated_action = Action.objects.get(pk=action.pk)
    assert (updated_action.details ==
            "&lt;iframe&gt;this should be escaped&lt;/iframe&gt;")
コード例 #2
0
def test_update_action_user(arf, api_user):
    incident = IncidentFactory.create()
    user = ExternalUserFactory.create()

    action = incident.action_items()[0]

    action_data = serializers.ActionSerializer(action).data
    action_data["user"] = {
        "app_id": "slack",
        "display_name": user.display_name,
        "external_id": user.external_id,
    }
    response = update_action(arf, api_user, incident.pk, action_data)
    print(response.rendered_content)
    assert response.status_code == 200, "Got non-201 response from API"

    updated_action = Action.objects.get(pk=action.pk)
    assert updated_action.user == user
コード例 #3
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()
コード例 #4
0
def test_update_action(arf, api_user):
    incident = IncidentFactory.create()

    action = incident.action_items()[0]

    action_data = serializers.ActionSerializer(action).data

    action_data["details"] = faker.paragraph(nb_sentences=2, variable_nb_sentences=True)
    response = update_action(arf, api_user, incident.pk, action_data)
    print(response.rendered_content)
    assert response.status_code == 200, "Got non-201 response from API"

    updated_action = Action.objects.get(pk=action.pk)
    assert updated_action.details == action_data["details"]

    action_data["done"] = not action_data["done"]
    response = update_action(arf, api_user, incident.pk, action_data)
    print(response.rendered_content)
    assert response.status_code == 200, "Got non-201 response from API"

    updated_action = Action.objects.get(pk=action.pk)
    assert updated_action.done == action_data["done"]
コード例 #5
0
ファイル: test_actions.py プロジェクト: zfouts/response
def test_update_action(arf, api_user):
    incident = IncidentFactory.create()

    action = incident.action_items()[0]

    action_data = serializers.ActionSerializer(action).data

    action_data["details"] = faker.paragraph(nb_sentences=2,
                                             variable_nb_sentences=True)
    response = update_action(arf, api_user, incident.pk, action_data)
    print(response.rendered_content)
    assert response.status_code == 200, "Got non-201 response from API"

    updated_action = Action.objects.get(pk=action.pk)
    assert updated_action.details == action_data["details"]

    priorityChoices = ["1", "2", "3"]
    priorityChoices.remove(action.priority)
    action_data["done"] = not action_data["done"]
    action_data["priority"] = str(random.choice(priorityChoices))
    typeChoices = ["1", "2", "3"]
    typeChoices.remove(action.type)
    action_data["type"] = str(random.choice(typeChoices))
    action_data["done_date"] = faker.date_time_between(
        start_date=action.created_date, end_date="now")
    action_data["due_date"] = faker.date_time_between(start_date="-6m",
                                                      end_date="+6m")
    response = update_action(arf, api_user, incident.pk, action_data)
    print(response.rendered_content)
    assert response.status_code == 200, "Got non-201 response from API"

    updated_action = Action.objects.get(pk=action.pk)
    assert updated_action.done == action_data["done"]
    assert updated_action.priority == action_data["priority"]
    assert updated_action.type == action_data["type"]
    assert updated_action.done_date == action_data["done_date"]
    assert updated_action.due_date == action_data["due_date"]