Пример #1
0
def test_get_collection_startswith(client, mock_thing, db_session):
    # Create and save two more things with the same name as the mock.
    ThingFactory.create(name=mock_thing.name,
                        created=str(datetime.datetime.now()))
    ThingFactory.create(name=mock_thing.name,
                        created=str(datetime.datetime.now()))

    startswith_data = {"meta": {"args": {"name": "mock"}}}

    res = client.post("/thing/startswith", json={"meta": startswith_data})
    assert res.status_code == 200

    result = res.get_json()
    assert result["meta"]["count"] == 3
Пример #2
0
def test_get_collection_filter_by_name_for_partial_match_returs_no_results(
        client, mock_thing, db_session):
    # Create and save two more things with the same name as the mock.
    ThingFactory.create(name=mock_thing.name,
                        created=str(datetime.datetime.now()))
    ThingFactory.create(name=mock_thing.name,
                        created=str(datetime.datetime.now()))

    name = "mock_"
    res = client.get(f"/thing/?filter[name]={name}")
    assert res.status_code == 200

    result = res.get_json()
    assert result["meta"]["count"] == 0
Пример #3
0
def test_get_collection_filtered_by_name_exact_match(client, mock_thing,
                                                     db_session):
    # Create and save two more things with the same name as the mock.
    ThingFactory.create(name=mock_thing.name,
                        created=str(datetime.datetime.now()))
    ThingFactory.create(name=mock_thing.name,
                        created=str(datetime.datetime.now()))

    res = client.get(f"/thing/?filter[name]={mock_thing.name}")
    assert res.status_code == 200

    result = res.get_json()
    assert result["meta"]["count"] == 3
    for el in result["data"]:
        assert el["attributes"]["name"] == mock_thing.name
Пример #4
0
def test_get_collection_filter_by_id(client, mock_thing, db_session):
    # Create and save two more things with the same name as the mock but different ids.
    ThingFactory.create(name=mock_thing.name,
                        created=str(datetime.datetime.now()),
                        id="mock_id1")
    ThingFactory.create(name=mock_thing.name,
                        created=str(datetime.datetime.now()),
                        id="mock_id2")

    res = client.get(f"/thing/?filter[id]={mock_thing.id}")
    assert res.status_code == 200

    result = res.get_json()
    assert result["meta"]["count"] == 1
    # no need for uniqueness check because id is primary key.
    assert result["data"][0]["id"] == mock_thing.id
Пример #5
0
def test_thing_get_by_name(client):
    thing = ThingFactory(name="something")

    res = client.get("/thing/get_by_name?name=something")
    assert res.status_code == 200
    assert res.get_json()["data"]["id"] == thing.id
    assert res.get_json()["data"]["attributes"]["name"] == thing.name
def test_thing_get_by_name(client):
    thing = ThingFactory(name="something")

    q_params = {"name": "something"}
    res = client.get("/thing/get_by_name", query_string=q_params)
    assert res.status_code == 200
    assert res.get_json()["data"]["id"] == thing.id
    assert res.get_json()["data"]["attributes"]["name"] == thing.name
Пример #7
0
def test_thing_get_fields(client):
    """
        Test that only the specified fields are returned
    """
    thing = ThingFactory(name="something", description="nothing")
    q_params = {"fields[thing]" : "name"}
    res = client.get(f"/thing/{thing.id}", query_string=q_params)
    assert res.status_code == 200
    assert res.get_json()["data"]["id"] == thing.id
    assert res.get_json()["data"]["attributes"]["name"] == thing.name
    assert res.get_json()["data"]["attributes"].get("description") is None
Пример #8
0
def test_invalid_jsonapirpc(client):
    thing = ThingFactory(name="something", description="nothing")
    res = client.get("/thing/get_by_name")
    assert res.status_code == 500
Пример #9
0
def mock_thing(db_session):
    thing = ThingFactory.create(name="mock_thing", created=str(datetime.datetime.now()), description="mock_description")

    yield thing