Skip to content

Commit

Permalink
Merge 2f4279f into c3fc5dc
Browse files Browse the repository at this point in the history
  • Loading branch information
hluk committed Mar 4, 2024
2 parents c3fc5dc + 2f4279f commit 899346d
Show file tree
Hide file tree
Showing 9 changed files with 311 additions and 229 deletions.
170 changes: 121 additions & 49 deletions poetry.lock

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,9 @@ opentelemetry-instrumentation-sqlalchemy = "^0.44b0"
sphinx = {version = "^7.1.1", optional = true}
sphinxcontrib-httpdomain = {version = "^1.8.1", optional = true}
markupsafe = {version = "==2.1.5", optional = true}
pydantic = "^1.10.14"
Flask-Pydantic = "^0.11.0"
flask-restx = "^1.1.0"
pydantic = "^2.6.3"
Flask-Pydantic = "^0.12.0"
flask-restx = "^1.3.0"

[tool.poetry.extras]
test = [
Expand Down
2 changes: 1 addition & 1 deletion tests/test_access_control.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ def test_ldap_host_base_not_defined(self, client, session):
r = client.post('/api/v1.0/waivers/', data=json.dumps(self.data),
content_type='application/json', headers=self.headers)
res_data = json.loads(r.get_data(as_text=True))
assert r.status_code == 500
assert r.status_code == 500, r.text
assert res_data['message'] == ('LDAP_HOST and LDAP_SEARCHES also need to be defined '
'if PERMISSIONS is defined.')

Expand Down
111 changes: 52 additions & 59 deletions tests/test_api_v10.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

import pytest
from requests import ConnectionError, HTTPError
from mock import patch, Mock
from mock import patch, ANY, Mock
from stomp.exception import StompException

from .utils import create_waiver
Expand Down Expand Up @@ -96,7 +96,7 @@ def test_create_waiver_with_subject(mocked_user, client, session):
r = client.post('/api/v1.0/waivers/', data=json.dumps(data),
content_type='application/json')
res_data = json.loads(r.get_data(as_text=True))
assert r.status_code == 201
assert r.status_code == 201, r.text
assert res_data['username'] == 'foo'
assert res_data['subject'] == {'type': 'koji_build', 'item': 'glibc-2.26-27.fc27'}
assert res_data['subject_type'] == 'koji_build'
Expand Down Expand Up @@ -179,21 +179,20 @@ def test_create_waiver_without_comment(mocked_user, client, session):
content_type='application/json')
res_data = json.loads(r.get_data(as_text=True))
assert r.status_code == 400
bp = res_data['validation_error']['body_params']
assert {
'loc': ['__root__'],
'msg': 'value is not a valid list',
'type': 'type_error.list'
} in bp
bp = res_data['validation_error']
assert {
'loc': ['__root__', 'comment'],
'msg': 'field required',
'type': 'value_error.missing'
'msg': 'Input should be a valid list',
'type': 'list_type',
'loc': [ANY],
'input': ANY,
'url': ANY,
} in bp
assert {
'loc': ['__root__', '__root__'],
'msg': 'Argument testcase is missing',
'type': 'value_error'
'msg': 'Field required',
'type': 'missing',
'loc': [ANY, 'comment'],
'input': ANY,
'url': ANY,
} in bp


Expand Down Expand Up @@ -249,16 +248,13 @@ def test_create_waiver_with_no_testcase(mocked_user, client):
content_type='application/json')
res_data = json.loads(r.get_data(as_text=True))
assert r.status_code == 400
bp = res_data['validation_error']['body_params']
assert {
'loc': ['__root__'],
'msg': 'value is not a valid list',
'type': 'type_error.list'
} in bp
bp = res_data['validation_error']
assert {
'loc': ['__root__', '__root__'],
'msg': 'Argument testcase is missing',
'type': 'value_error'
'msg': 'Value error, Argument testcase is missing',
'type': 'value_error',
'loc': ANY,
'input': ANY,
'url': ANY,
} in bp


Expand All @@ -271,33 +267,13 @@ def test_create_waiver_with_malformed_subject(mocked_user, client):
content_type='application/json')
res_data = json.loads(r.get_data(as_text=True))
assert r.status_code == 400
bp = res_data['validation_error']['body_params']
assert {
'loc': ['__root__'],
'msg': 'value is not a valid list',
'type': 'type_error.list'
} in bp
assert {
'loc': ['__root__', 'subject'],
'msg': 'value is not a valid dict',
'type': 'type_error.dict'
} in bp
bp = res_data['validation_error']
assert {
'loc': ['__root__', 'product_version'],
'msg': 'field required', 'type': 'value_error.missing'
} in bp
assert {
'loc': ['__root__', 'comment'],
'msg': 'field required',
'type': 'value_error.missing'
} in bp
assert {
'loc': ['__root__', '__root__'],
'msg': (
'subject must be defined using result_id or subject '
'or both subject_identifier, subject_type'
),
'type': 'value_error'
'msg': 'Input should be a valid dictionary or instance of TestSubject',
'type': 'model_type',
'loc': [ANY, 'subject'],
'input': ANY,
'url': ANY,
} in bp


Expand Down Expand Up @@ -738,8 +714,14 @@ def test_filtering_with_missing_filter(client, session):
content_type='application/json')
res_data = json.loads(r.get_data(as_text=True))
assert r.status_code == 400
bp = res_data['validation_error']['body_params']
assert {'loc': ['filters'], 'msg': 'field required', 'type': 'value_error.missing'} in bp
bp = res_data['validation_error']
assert {
'loc': ['filters'],
'msg': 'Field required',
'type': 'missing',
'input': ANY,
'url': ANY,
} in bp


def test_waivers_by_subjects_and_testcases(client, session):
Expand Down Expand Up @@ -774,9 +756,9 @@ def test_waivers_by_subjects_and_testcases(client, session):


@pytest.mark.parametrize("results,expected_error_message,excepted_error_type", [
([{'item': {'subject.test1': 'subject1'}}], 'field required', 'value_error.missing'),
([{'subject': 'subject1'}], 'value is not a valid dict', 'type_error.dict'),
([{}], 'field required', 'value_error.missing')
([{'item': {'subject.test1': 'subject1'}}], 'Field required', 'missing'),
([{'subject': 'subject1'}], 'value is not a valid dict', 'dict_type'),
([{}], 'Field required', 'missing')
])
def test_waivers_by_subjects_and_testcases_with_bad_results_parameter(
client, session, results, expected_error_message, excepted_error_type
Expand All @@ -786,16 +768,20 @@ def test_waivers_by_subjects_and_testcases_with_bad_results_parameter(
content_type='application/json')
res_data = json.loads(r.get_data(as_text=True))
assert r.status_code == 400
bp = res_data['validation_error']['body_params']
bp = res_data['validation_error']
assert {
'loc': ['results', 0, 'testcase'],
'type': 'value_error.missing',
'msg': 'field required'
'type': 'missing',
'msg': 'Field required',
'input': ANY,
'url': ANY,
} in bp
assert {
'loc': ['results', 0, 'subject'],
'type': excepted_error_type,
'msg': expected_error_message
'msg': expected_error_message,
'input': ANY,
'url': ANY,
}


Expand Down Expand Up @@ -836,7 +822,14 @@ def test_waivers_by_subjects_and_testcases_with_malformed_since(client, session)
content_type='application/json')
res_data = json.loads(r.get_data(as_text=True))
assert r.status_code == 400
assert res_data['message']['since'] == "Invalid isoformat string: '123'"
bp = res_data['validation_error']
assert {
'msg': 'Input should be a valid string',
'type': 'string_type',
'loc': ['since'],
'input': ANY,
'url': ANY,
} in bp

data = {'since': 'asdf'}
r = client.post('/api/v1.0/waivers/+by-subjects-and-testcases', data=json.dumps(data),
Expand Down
Loading

0 comments on commit 899346d

Please sign in to comment.