Skip to content

Commit

Permalink
TST: Refactor tests, update request import
Browse files Browse the repository at this point in the history
  • Loading branch information
mgxd committed Oct 21, 2024
1 parent 982d6b0 commit 2e4e87b
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 40 deletions.
38 changes: 3 additions & 35 deletions migas/tests/test_operations.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
10 changes: 5 additions & 5 deletions migas/tests/test_request.py
Original file line number Diff line number Diff line change
@@ -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'
Expand All @@ -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

0 comments on commit 2e4e87b

Please sign in to comment.