Exemplo n.º 1
0
def test_get_url(test_type):
    init_cache()
    assert_request(
        "GET",
        ROUTE + GET_URL_INPUT[test_type],
        AssertRequest({}, {}),
        GET_URL_OUTPUT[test_type],
    )
Exemplo n.º 2
0
import pytest

from tests import AssertRequest, AssertResponse, assert_request

ROUTE = "/fruit"

GET_INPUT = {
    "ok": AssertRequest({}, {"name": "apple"}),
    "bad_request": AssertRequest({}, {"name": "banana"}),
    "internal_server_error": AssertRequest({}, {"name": "error"}),
}

GET_OUTPUT = {
    "ok": AssertResponse({
        "name": "apple",
        "count": 1
    }, 200),
    "bad_request": AssertResponse("Bad Request", 400),
    "internal_server_error": AssertResponse("Internal Server Error", 500),
}


@pytest.mark.parametrize("test_type", GET_INPUT.keys())
def test_get(test_type):
    assert_request("GET", ROUTE, GET_INPUT[test_type], GET_OUTPUT[test_type])


HEADERS = {"Content-Type": "Application/json"}

POST_INPUT = {
    "success": AssertRequest(HEADERS, {"name": "banana"}),
Exemplo n.º 3
0
import pytest
from tests import APITestcase, AssertRequest, AssertResponse

ROUTE = "/fruit"

HEADERS = {"Content-Type": "Application/json"}

CASES = [
    APITestcase(
        "ok",
        AssertRequest("GET", ROUTE, {}, {"name": "apple"}),
        AssertResponse({"name": "apple", "count": 1}, 200),
    ),
    APITestcase(
        "bad_request",
        AssertRequest("GET", ROUTE, {}, {"name": "banana"}),
        AssertResponse("Bad Request", 400),
    ),
    APITestcase(
        "internal_server_error",
        AssertRequest("GET", ROUTE, {}, {"name": "error"}),
        AssertResponse("Internal Server Error", 500),
    ),
    APITestcase(
        "ok",
        AssertRequest("POST", ROUTE, HEADERS, None, {"name": "banana"}),
        AssertResponse("OK", 200),
    ),
    APITestcase(
        "fail",
        AssertRequest("POST", ROUTE, HEADERS, None, {"name": "apple"}),
Exemplo n.º 4
0
import pytest

from tests import AssertRequest, AssertResponse, assert_request, clean_db
from models import init_db

ROUTE = "/fruit"

HEADERS = {"Content-Type": "Application/json"}

GET_INPUT = {
    "success": AssertRequest(None, {"name": "apple"}),
    "fail_notexist": AssertRequest(None, {"name": "banana"}),
}

GET_OUTPUT = {
    "success": AssertResponse({
        "name": "apple",
        "count": 1
    }, 200),
    "fail_notexist": AssertResponse("Bad Request", 400),
}


@pytest.mark.parametrize("test_type", GET_INPUT.keys())
def test_get(test_type):
    clean_db()
    init_db()
    assert_request("GET", ROUTE, GET_INPUT[test_type], GET_OUTPUT[test_type])


POST_INPUT = {
Exemplo n.º 5
0
import pytest
from tests import APITestcase, AssertRequest, AssertResponse

ROUTE = "/health"

CASES = [
    APITestcase(
        "OK",
        AssertRequest("GET", ROUTE, headers={}, payload={}),
        AssertResponse("OK", 200),
    )
]


@pytest.mark.parametrize("case", CASES, ids=[case.name for case in CASES])
def test(case: APITestcase):
    case.run()
import pytest
from tests import APITestcase, AssertRequest, AssertResponse

ROUTE = "/health"

CASES = [
    APITestcase("ok", AssertRequest("GET", ROUTE, None, None),
                AssertResponse("OK", 200))
]


@pytest.mark.parametrize("case", CASES, ids=[case.name for case in CASES])
def test(case: APITestcase):
    case.run()
Exemplo n.º 7
0
import pytest

from tests import AssertRequest, AssertResponse, assert_request

ROUTE = "/health"

HEADERS = {}

PAYLOAD = {}

INPUT = {"success": AssertRequest(HEADERS, PAYLOAD)}

OUTPUT = {"success": AssertResponse("OK", 200)}


@pytest.mark.parametrize("test_type", INPUT.keys())
def test_get(test_type):
    assert_request("GET", ROUTE, INPUT[test_type], OUTPUT[test_type])
Exemplo n.º 8
0
import pytest
from cache import init_cache
from tests import AssertRequest, AssertResponse, assert_request

ROUTE = "/fruit"

GET_INPUT = {
    "success": AssertRequest({}, {"name": "apple"}),
    "fail": AssertRequest({}, {"name": "banana"}),
}

GET_OUTPUT = {
    "success": AssertResponse({
        "name": "apple",
        "count": 1
    }, 200),
    "fail": AssertResponse("Bad Request", 400),
}


@pytest.mark.parametrize("test_type", GET_INPUT.keys())
def test_get(test_type):
    init_cache()
    assert_request("GET", ROUTE, GET_INPUT[test_type], GET_OUTPUT[test_type])


GET_URL_INPUT = {"success": "/apple", "fail": "/banana"}

GET_URL_OUTPUT = {
    "success": AssertResponse({
        "name": "apple",
Exemplo n.º 9
0
import pytest
from tests import APITestcase, AssertRequest, AssertResponse

ROUTE = "/fruit"

CASES = [
    APITestcase(
        "success",
        AssertRequest("GET", ROUTE, payload={"name": "apple"}),
        AssertResponse({
            "name": "apple",
            "count": 1
        }, 200),
    ),
    APITestcase(
        "fail",
        AssertRequest("GET", ROUTE, payload={"name": "banana"}),
        AssertResponse("Bad Request", 400),
    ),
    APITestcase(
        "fail",
        AssertRequest("GET", f"{ROUTE}/banana"),
        AssertResponse("Bad Request", 400),
    ),
    APITestcase(
        "success",
        AssertRequest("GET", f"{ROUTE}/apple"),
        AssertResponse({
            "name": "apple",
            "count": 1
        }, 200),