Skip to content
Snippets Groups Projects
Verified Commit 3e95d486 authored by Martin Weise's avatar Martin Weise
Browse files

Improved coverage

parent a547c302
No related branches found
No related tags found
3 merge requests!387Wrong model,!384Wrong model,!381Wrong model
Showing with 99 additions and 55 deletions
...@@ -302,7 +302,7 @@ test-analyse-service: ...@@ -302,7 +302,7 @@ test-analyse-service:
script: script:
- "pip install pipenv" - "pip install pipenv"
- "pipenv install gunicorn && pipenv install --dev --system --deploy" - "pipenv install gunicorn && pipenv install --dev --system --deploy"
- cd ./dbrepo-analyse-service/ && coverage run -m pytest test/test_determine_dt.py test/test_determine_pk.py test/test_s3_client.py --junitxml=report.xml && coverage html --omit="test/*" && coverage report --omit="test/*" > ./coverage.txt - cd ./dbrepo-analyse-service/ && coverage run -m pytest test/test_determine_dt.py test/test_determine_pk.py test/test_s3_client.py --junitxml=report.xml && coverage html --omit="tests/*" && coverage report --omit="tests/*" > ./coverage.txt
- "cat ./coverage.txt | grep -o 'TOTAL[^%]*%'" - "cat ./coverage.txt | grep -o 'TOTAL[^%]*%'"
artifacts: artifacts:
when: always when: always
...@@ -324,7 +324,7 @@ test-auth-service-init: ...@@ -324,7 +324,7 @@ test-auth-service-init:
- "pip install pipenv" - "pip install pipenv"
- "pipenv install gunicorn && pipenv install --dev --system --deploy" - "pipenv install gunicorn && pipenv install --dev --system --deploy"
script: script:
- cd ./dbrepo-auth-service/init/ && coverage run -m pytest test/test_unit_app.py --junitxml=report.xml && coverage html --omit="test/*" && coverage report --omit="test/*" > ./coverage.txt - cd ./dbrepo-auth-service/init/ && coverage run -m pytest test/test_unit_app.py --junitxml=report.xml && coverage html --omit="tests/*" && coverage report --omit="tests/*" > ./coverage.txt
- "cat ./coverage.txt | grep -o 'TOTAL[^%]*%'" - "cat ./coverage.txt | grep -o 'TOTAL[^%]*%'"
artifacts: artifacts:
when: always when: always
...@@ -403,7 +403,7 @@ test-lib: ...@@ -403,7 +403,7 @@ test-lib:
script: script:
- "pip install pipenv" - "pip install pipenv"
- "pipenv install gunicorn && pipenv install --dev --system --deploy" - "pipenv install gunicorn && pipenv install --dev --system --deploy"
- cd ./lib/python/ && coverage run -m pytest tests/test_unit_analyse.py tests/test_unit_container.py tests/test_unit_database.py tests/test_unit_identifier.py tests/test_unit_license.py tests/test_unit_query.py tests/test_unit_rest_client.py tests/test_unit_table.py tests/test_unit_user.py tests/test_unit_view.py --junitxml=report.xml && coverage html --omit="test/*" && coverage report --omit="test/*" > ./coverage.txt - cd ./lib/python/ && coverage run -m pytest tests/test_unit_analyse.py tests/test_unit_container.py tests/test_unit_database.py tests/test_unit_identifier.py tests/test_unit_license.py tests/test_unit_query.py tests/test_unit_rest_client.py tests/test_unit_table.py tests/test_unit_user.py tests/test_unit_view.py tests/test_unit_rest_client.py --junitxml=report.xml && coverage html --omit="tests/*" && coverage report --omit="tests/*" > ./coverage.txt
- "cat ./coverage.txt | grep -o 'TOTAL[^%]*%'" - "cat ./coverage.txt | grep -o 'TOTAL[^%]*%'"
artifacts: artifacts:
when: always when: always
......
[report]
omit =
*/tests/*
...@@ -677,6 +677,7 @@ class View(BaseModel): ...@@ -677,6 +677,7 @@ class View(BaseModel):
owner: UserBrief owner: UserBrief
internal_name: str internal_name: str
is_public: bool is_public: bool
is_schema_public: bool
initial_view: bool initial_view: bool
columns: List[ViewColumn] columns: List[ViewColumn]
identifiers: List[Identifier] = field(default_factory=list) identifiers: List[Identifier] = field(default_factory=list)
...@@ -959,6 +960,7 @@ class Column(BaseModel): ...@@ -959,6 +960,7 @@ class Column(BaseModel):
class ViewColumn(BaseModel): class ViewColumn(BaseModel):
id: int id: int
name: str name: str
ord: int
database_id: int database_id: int
internal_name: str internal_name: str
type: ColumnType type: ColumnType
......
import os import os
from unittest import TestCase, mock, main import unittest
import requests_mock
from dbrepo.RestClient import RestClient from dbrepo.RestClient import RestClient
from dbrepo.api.dto import JwtAuth
from dbrepo.api.exceptions import MalformedError, ServiceConnectionError, ServiceError, ForbiddenError, \
AuthenticationError, ResponseCodeError
class DatabaseUnitTest(TestCase): class RestClientUnitTest(unittest.TestCase):
def test_constructor_succeeds(self): def test_constructor_succeeds(self):
with requests_mock.Mocker() as mock:
# test
os.environ['REST_API_SECURE'] = 'True'
response = RestClient()
self.assertTrue(response.secure)
def test_get_jwt_auth_empty_succeeds(self):
with requests_mock.Mocker() as mock:
exp = JwtAuth(access_token='ey123',
refresh_token='ey456',
id_token='ey789',
expires_in=3600,
scope='scope',
token_type='Bearer',
not_before_policy=0,
session_state='session_state',
refresh_expires_in=7200)
# mock
mock.post('/api/user/token', json=exp.model_dump(), status_code=202)
# test
response = RestClient().get_jwt_auth()
self.assertEqual(exp, response)
def test_get_jwt_auth_400_fails(self):
with requests_mock.Mocker() as mock:
# mock
mock.post('/api/user/token', status_code=400)
# test
try:
response = RestClient().get_jwt_auth()
except MalformedError:
pass
def test_get_jwt_auth_403_fails(self):
with requests_mock.Mocker() as mock:
# mock
mock.post('/api/user/token', status_code=403)
# test
try:
response = RestClient().get_jwt_auth()
except ForbiddenError:
pass
def test_get_jwt_auth_428_fails(self):
with requests_mock.Mocker() as mock:
# mock
mock.post('/api/user/token', status_code=428)
# test
try:
response = RestClient().get_jwt_auth()
except AuthenticationError:
pass
def test_get_jwt_auth_502_fails(self):
with requests_mock.Mocker() as mock:
# mock
mock.post('/api/user/token', status_code=502)
# test # test
client = RestClient() try:
self.assertEqual("http://localhost", client.endpoint) response = RestClient().get_jwt_auth()
self.assertIsNone(client.username) except ServiceConnectionError:
self.assertIsNone(client.password) pass
self.assertTrue(client.secure)
@mock.patch.dict(os.environ, { def test_get_jwt_auth_503_fails(self):
"REST_API_ENDPOINT": "https://test.dbrepo.tuwien.ac.at", with requests_mock.Mocker() as mock:
"REST_API_USERNAME": "foo", # mock
"REST_API_PASSWORD": "bar", mock.post('/api/user/token', status_code=503)
"REST_API_SECURE": "false",
})
def test_constructor_environment_succeeds(self):
# test # test
client = RestClient() try:
self.assertEqual("https://test.dbrepo.tuwien.ac.at", client.endpoint) response = RestClient().get_jwt_auth()
self.assertEqual("foo", client.username) except ServiceError:
self.assertEqual("bar", client.password) pass
self.assertFalse(client.secure)
def test_constructor_credentials_succeeds(self): def test_get_jwt_auth_unknown_fails(self):
with requests_mock.Mocker() as mock:
# mock
mock.post('/api/user/token', status_code=418)
# test # test
client = RestClient(username='admin', password='pass') try:
self.assertEqual("http://localhost", client.endpoint) response = RestClient().get_jwt_auth()
self.assertEqual('admin', client.username) except ResponseCodeError:
self.assertEqual('pass', client.password) pass
self.assertTrue(client.secure)
if __name__ == "__main__": if __name__ == "__main__":
main() unittest.main()
...@@ -5,7 +5,7 @@ import requests_mock ...@@ -5,7 +5,7 @@ import requests_mock
from pandas import DataFrame from pandas import DataFrame
from dbrepo.RestClient import RestClient from dbrepo.RestClient import RestClient
from dbrepo.api.dto import View, ViewColumn, ColumnType, UserBrief from dbrepo.api.dto import View, ViewColumn, ColumnType, UserBrief, ViewBrief
from dbrepo.api.exceptions import ForbiddenError, NotExistsError, MalformedError, AuthenticationError from dbrepo.api.exceptions import ForbiddenError, NotExistsError, MalformedError, AuthenticationError
...@@ -21,26 +21,16 @@ class ViewUnitTest(unittest.TestCase): ...@@ -21,26 +21,16 @@ class ViewUnitTest(unittest.TestCase):
def test_get_views_succeeds(self): def test_get_views_succeeds(self):
with requests_mock.Mocker() as mock: with requests_mock.Mocker() as mock:
exp = [View(id=1, exp = [ViewBrief(id=1,
name="Data", name="Data",
internal_name="data", internal_name="data",
database_id=1, database_id=1,
initial_view=False, initial_view=False,
query="SELECT id FROM mytable WHERE deg > 0", query="SELECT id FROM mytable WHERE deg > 0",
query_hash="94c74728b11a690e51d64719868824735f0817b7", query_hash="94c74728b11a690e51d64719868824735f0817b7",
owner=UserBrief(id='8638c043-5145-4be8-a3e4-4b79991b0a16', username='mweise'), owned_by='8638c043-5145-4be8-a3e4-4b79991b0a16',
is_public=True,
is_schema_public=True,
columns=[ViewColumn(id=1,
ord=0,
name="id",
internal_name="id",
database_id=1,
auto_generated=False,
type=ColumnType.BIGINT,
is_public=True, is_public=True,
is_null_allowed=False)], is_schema_public=True)]
identifiers=[])]
# mock # mock
mock.get('/api/database/1/view', json=[exp[0].model_dump()]) mock.get('/api/database/1/view', json=[exp[0].model_dump()])
# test # test
...@@ -74,9 +64,7 @@ class ViewUnitTest(unittest.TestCase): ...@@ -74,9 +64,7 @@ class ViewUnitTest(unittest.TestCase):
name="id", name="id",
internal_name="id", internal_name="id",
database_id=1, database_id=1,
auto_generated=False,
type=ColumnType.BIGINT, type=ColumnType.BIGINT,
is_public=True,
is_null_allowed=False)], is_null_allowed=False)],
identifiers=[]) identifiers=[])
# mock # mock
...@@ -122,9 +110,7 @@ class ViewUnitTest(unittest.TestCase): ...@@ -122,9 +110,7 @@ class ViewUnitTest(unittest.TestCase):
name="id", name="id",
internal_name="id", internal_name="id",
database_id=1, database_id=1,
auto_generated=False,
type=ColumnType.BIGINT, type=ColumnType.BIGINT,
is_public=True,
is_null_allowed=False)], is_null_allowed=False)],
identifiers=[]) identifiers=[])
# mock # mock
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment