From 9fec779f150ebf45910d89a0d12fa2e8f701cda7 Mon Sep 17 00:00:00 2001 From: mathiasg Date: Mon, 21 Oct 2024 11:28:43 -0400 Subject: [PATCH] TST: Refactor tests, update request import --- migas/tests/test_operations.py | 38 +++------------------------------- migas/tests/test_request.py | 10 ++++----- 2 files changed, 8 insertions(+), 40 deletions(-) diff --git a/migas/tests/test_operations.py b/migas/tests/test_operations.py index bac47d9..96df3bb 100644 --- a/migas/tests/test_operations.py +++ b/migas/tests/test_operations.py @@ -25,30 +25,17 @@ today = today.strftime('%Y-%m-%d') -def test_operations(setup_migas): - _test_add_breakcrumb() - # add delay to ensure server has updated - time.sleep(2) - _test_get_usage() - -def _test_add_breakcrumb(): +def test_database_io(setup_migas): res = add_breadcrumb(test_project, __version__) - assert res['success'] is True - # ensure kwargs can be submitted res = add_breadcrumb(test_project, __version__, language='cpython', platform='win32') - assert res['success'] is True - - # validation should happen instantly + # this breadcrumb is not valid res = add_breadcrumb(test_project, __version__, status='wtf') - assert res['success'] is False -def _test_get_usage(): - """This test requires `_test_add_breadcrumb()` to be run before.""" res = get_usage(test_project, start=today) assert res['success'] is True all_usage = res['hits'] - assert all_usage > 0 + assert all_usage == 2 res = get_usage(test_project, start=today, unique=True) assert res['success'] is True @@ -64,25 +51,6 @@ def _test_get_usage(): assert res['hits'] == 0 -def test_add_project(setup_migas): - res = add_project(test_project, __version__) - assert res['success'] is True - latest = res['latest_version'] - assert latest - - # ensure kwargs can be submitted - res = add_project(test_project, __version__, language='cpython', platform='win32') - assert res['success'] is True - assert res['latest_version'] == latest - # should be cached since we just checked the version - assert res['cached'] is True - - # illegal queries should fail - res = add_project(test_project, __version__, status='wtf') - assert res['success'] is False - assert res['latest_version'] is None - - def test_check_project(setup_migas): res = check_project(test_project, __version__) assert res['success'] is True diff --git a/migas/tests/test_request.py b/migas/tests/test_request.py index ce91fb4..093f1ea 100644 --- a/migas/tests/test_request.py +++ b/migas/tests/test_request.py @@ -1,6 +1,6 @@ import pytest -from migas.request import request +from migas.request import _request GET_URL = 'https://httpbin.org/get' GET_COMPRESSED_URL = 'https://httpbingo.org/get' @@ -15,22 +15,22 @@ ] ) def test_request_get(method, url, query): - status, res = request(url, query=query, method=method) + status, res = _request(url, query=query, method=method) assert status == 200 assert res def test_timeout(monkeypatch): - status, res = request(GET_URL, timeout=0.00001, method="GET") + status, res = _request(GET_URL, timeout=0.00001, method="GET") assert status == 408 assert res['errors'] monkeypatch.setenv('MIGAS_TIMEOUT', '0.000001') - status, res = request(GET_URL, method="GET") + status, res = _request(GET_URL, method="GET") assert status == 408 assert res['errors'] monkeypatch.delenv('MIGAS_TIMEOUT') - status, res = request(GET_URL, method="GET") + status, res = _request(GET_URL, method="GET") assert status == 200 assert res