Beispiel #1
0
def test_create_summaries_invalid_json(test_app_with_db):
    response = test_app_with_db.post("/summaries/", data=json.dumps({}))
    assert response.status_code == 422
    assert response.json() == {
        "detail": [{
            "loc": ["body", "payload", "url"],
            "msg": "field required",
            "type": "value_error.missing",
        }]
    }

    response = test_app_with_db.post("/summaries/",
                                     data=json.dumps({"url": "invalid://url"}))
    assert response.status_code == 422
    assert response.json()["detail"][0]["msg"] == "URL scheme not permitted"
Beispiel #2
0
def test_create_summary(test_app_with_db):
    response = test_app_with_db.post("/summaries/",
                                     data=json.dumps(
                                         {"url": "https://foo.bar"}))

    assert response.status_code == 201
    assert response.json()["url"] == "https://foo.bar"
Beispiel #3
0
def test_remove_summary(test_app_with_db):
    response = test_app_with_db.post("/summaries/",
                                     data=json.dumps(
                                         {"url": "https://foo.bar"}))
    summary_id = response.json()["id"]

    response = test_app_with_db.delete(f"/summaries/{summary_id}/")
    assert response.status_code == 200
    assert response.json() == {"id": summary_id, "url": "https://foo.bar"}
Beispiel #4
0
def test_read_all_summaries(test_app_with_db):
    response = test_app_with_db.post("/summaries/",
                                     data=json.dumps(
                                         {"url": "https://foo.bar"}))
    summary_id = response.json()["id"]

    response = test_app_with_db.get(f"/summaries/")
    assert response.status_code == 200

    response_list = response.json()
    assert len(list(filter(lambda d: d["id"] == summary_id,
                           response_list))) == 1
def test_create_summary(test_app_with_db, monkeypatch):
    test_request_payload = {"url": "https://foo.bar"}
    test_response_payload = {"id": 1, "url": "https://foo.bar"}

    async def mock_post(payload):
        return 1

    monkeypatch.setattr(crud, "post", mock_post)

    response = test_app_with_db.post("/summaries/", data=json.dumps(test_request_payload),)

    assert response.status_code == 201
    assert response.json() == test_response_payload
Beispiel #6
0
def test_read_summary(test_app_with_db):
    response = test_app_with_db.post("/summaries/",
                                     data=json.dumps(
                                         {"url": "https://foo.bar"}))
    summary_id = response.json()["id"]

    response = test_app_with_db.get(f"/summaries/{summary_id}/")
    assert response.status_code == 200

    response_dict = response.json()
    assert response_dict["id"] == summary_id
    assert response_dict["url"] == "https://foo.bar"
    assert response_dict["summary"]
    assert response_dict["created_at"]