summaryrefslogtreecommitdiffstats
path: root/python/tests/web_refs.py
blob: 61966480999066098d2d26ee68617eb5bb4900b5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
import json

import pytest
from fatcat_openapi_client.rest import ApiException
from fixtures import *

from fatcat_web.search import get_elastic_container_random_releases


def test_basic_refs(app, mocker):

    with open("tests/files/elastic_refs_in_release.json") as f:
        elastic_resp_in = json.loads(f.read())
    with open("tests/files/elastic_refs_out_release.json") as f:
        elastic_resp_out = json.loads(f.read())
    with open("tests/files/elastic_empty.json") as f:
        elastic_resp_empty = json.loads(f.read())

    es_raw = mocker.patch("elasticsearch.connection.Urllib3HttpConnection.perform_request")
    es_raw.side_effect = [
        (200, {}, json.dumps(elastic_resp_in)),
        (200, {}, json.dumps(elastic_resp_in)),
        (200, {}, json.dumps(elastic_resp_empty)),
        (200, {}, json.dumps(elastic_resp_out)),
        (200, {}, json.dumps(elastic_resp_out)),
        (200, {}, json.dumps(elastic_resp_empty)),
    ]

    # render refs-in
    rv = app.get("/release/aaaaaaaaaaaaarceaaaaaaaaai/refs-in")
    assert rv.status_code == 200
    assert b"Why Most Published Research Findings Are False" in rv.data

    rv = app.get("/release/aaaaaaaaaaaaarceaaaaaaaaai/refs-in.json")
    assert rv.status_code == 200

    # empty (in)
    rv = app.get("/release/aaaaaaaaaaaaarceaaaaaaaaai/refs-in")
    assert rv.status_code == 200
    assert b"No References Found" in rv.data

    # render refs-out
    rv = app.get("/release/aaaaaaaaaaaaarceaaaaaaaaai/refs-out")
    assert rv.status_code == 200
    assert b"Why Most Published Research Findings Are False" in rv.data

    rv = app.get("/release/aaaaaaaaaaaaarceaaaaaaaaai/refs-out.json")
    assert rv.status_code == 200

    # empty (out)
    rv = app.get("/release/aaaaaaaaaaaaarceaaaaaaaaai/refs-out")
    assert rv.status_code == 200
    assert b"No References Found" in rv.data