Skip to content

Commit

Permalink
Merge pull request #6 from ATIX-AG/fix-tests
Browse files Browse the repository at this point in the history
Fix pytest errors and remove duplicate tests
  • Loading branch information
m-bucher authored Mar 12, 2024
2 parents 4a60535 + 11aeb75 commit 5b5a417
Show file tree
Hide file tree
Showing 3 changed files with 96 additions and 176 deletions.
96 changes: 96 additions & 0 deletions tests/test_api.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
import pytest
import os

from unittest.mock import Mock

from errata_server.api_beta import Endpoint as BetaEndpoint
from errata_server.api_v1 import Endpoint as V1Endpoint


TEST_DIR = os.path.dirname(os.path.abspath(__file__))


GET_DATA = \
b'[{"name": "DSA-1234-1", "title": "base-camp -- security update", "'\
b'issued": "01 Jan 1000", "affected_source_package": "base-camp", "p'\
b'ackages": [{"name": "base-camp", "version": "3.2.1+u1", "architect'\
b'ure": "amd64", "component": "main", "release": "stretch"}], "descr'\
b'iption": "A terribly long string to describe what is up.", "cves":'\
b' ["CVE-1000-1000000"], "severity": "high", "scope": "remote"}, {"n'\
b'ame": "DSA-2345-1", "title": "second-base -- security update", "is'\
b'sued": "02 Jan 1000", "affected_source_package": "second-base", "p'\
b'ackages": [{"name": "libsecond-base", "version": "2.1-1+u1", "arch'\
b'itecture": "amd64", "component": "main", "release": "stretch"}, {"'\
b'name": "second-base-common", "version": "2.2-1+u1", "architecture"'\
b': "all", "component": "main", "release": "stretch"}], "description'\
b'": "Here is something going on, too", "cves": ["CVE-1000-1000001"]'\
b', "severity": "not yet assigned", "scope": "local", "dbts_bugs": ['\
b'10]}]'


@pytest.fixture(params=(BetaEndpoint, V1Endpoint), ids=["beta", "v1"])
def endpoint(request):
yield request.param('debian', os.path.join(TEST_DIR, 'fixtures'))


@pytest.mark.asyncio
async def test_validate_config(endpoint):
await endpoint.read_task
assert endpoint.etag_base == b'abbd247d7efc27b5d2d487387aee289edb1bf26c043d3232a12f34a9f0c16ab5'


@pytest.mark.asyncio
async def test_get_no_data(endpoint):
await endpoint.read_task
endpoint.data = None
request = Mock()
request.uri = b'/dep/api/beta/debian?releases=stretch'
request.setETag.return_value = False
await endpoint.get(request)
request.write.assert_called_with(b'Service temporarily unavailable')


@pytest.mark.asyncio
async def test_get(endpoint):
request = Mock()
request.uri = b'/dep/api/beta/debian?releases=stretch'
request.setETag.return_value = False
await endpoint.get(request)
request.write.assert_called_with(GET_DATA)


@pytest.mark.asyncio
async def test_get_with_alias(endpoint):
request = Mock()
request.uri = b'/dep/api/beta/debian?releases=stretch/updates'
request.setETag.return_value = False
await endpoint.get(request)
request.write.assert_called_with(GET_DATA)


@pytest.mark.asyncio
async def test_get_with_whitespace(endpoint):
request = Mock()
request.uri = b'/dep/api/beta/debian?releases=blue, stretch'
request.setETag.return_value = False
await endpoint.get(request)
request.write.assert_called_with(GET_DATA)


@pytest.mark.asyncio
async def test_get_invalid(endpoint):
request = Mock()
request.uri = b'/dep/api/beta/debian?releases=blue'
request.setETag.return_value = False
await endpoint.get(request)
request.write.assert_called_with(b'[]')


@pytest.mark.asyncio
async def test_get_etag(endpoint):
request = Mock()
request.uri = b'/dep/api/beta/debian?releases=stretch'
request.setETag.return_value = True
await endpoint.get(request)
request.write.assert_not_called()
request.setETag.assert_called_with(b'c45b9b107d88ae65b41e4fb186fe4e83e6df9e0005724dfdbc352ebfff1e56a8')
88 changes: 0 additions & 88 deletions tests/test_api_beta.py

This file was deleted.

88 changes: 0 additions & 88 deletions tests/test_api_v1.py

This file was deleted.

0 comments on commit 5b5a417

Please sign in to comment.