diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 6e084f17d40ca2f0de1a3d730bfab6ac8e5b9af9..3928026c5a25dd1b4b26ae443c5c911d3f50f040 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -405,7 +405,7 @@ test-lib: script: - "pip install pipenv" - "pipenv install gunicorn && pipenv install --dev --system --deploy" - - cd ./lib/python/ && coverage run --rcfile=.coveragerc -m pytest tests/test_unit_container.py tests/test_unit_concept.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_unit.py && coverage html && coverage xml && coverage report > ./coverage.txt + - cd ./lib/python/ && coverage run --rcfile=.coveragerc -m pytest tests/test_unit_container.py tests/test_unit_messages.py tests/test_unit_image.py tests/test_unit_concept.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_unit.py && coverage html && coverage xml && coverage report > ./coverage.txt - "cat ./coverage.txt | grep -o 'TOTAL[^%]*%'" artifacts: when: always diff --git a/dbrepo-auth-service/listeners/target/create-event-listener.jar b/dbrepo-auth-service/listeners/target/create-event-listener.jar index 8da93ba40f621cea1db4e46414fd28ef77856fc4..ab18ceb405c9b37ab5d7ed52be8ec5faafd4554d 100644 Binary files a/dbrepo-auth-service/listeners/target/create-event-listener.jar and b/dbrepo-auth-service/listeners/target/create-event-listener.jar differ diff --git a/dbrepo-metadata-db/1_setup-schema.sql b/dbrepo-metadata-db/1_setup-schema.sql index f874c4e2635094dc57e7f61e2a47d41a6685c5a9..17d303ea7d6001e73a55b19cc286e8d9980e1d35 100644 --- a/dbrepo-metadata-db/1_setup-schema.sql +++ b/dbrepo-metadata-db/1_setup-schema.sql @@ -331,9 +331,9 @@ CREATE TABLE IF NOT EXISTS `mdb_identifiers` ( id VARCHAR(36) NOT NULL DEFAULT UUID(), dbid VARCHAR(36) NOT NULL, - qid VARCHAR(36) NOT NULL, - vid VARCHAR(36) NOT NULL, - tid VARCHAR(36) NOT NULL, + qid VARCHAR(36), + vid VARCHAR(36), + tid VARCHAR(36), publisher VARCHAR(255) NOT NULL, language VARCHAR(2), publication_year INT NOT NULL, diff --git a/helm/dbrepo/files/create-event-listener.jar b/helm/dbrepo/files/create-event-listener.jar index 8da93ba40f621cea1db4e46414fd28ef77856fc4..ab18ceb405c9b37ab5d7ed52be8ec5faafd4554d 100644 Binary files a/helm/dbrepo/files/create-event-listener.jar and b/helm/dbrepo/files/create-event-listener.jar differ diff --git a/lib/python/dbrepo/RestClient.py b/lib/python/dbrepo/RestClient.py index 9e609a70921634ee22377407e398507db46693db..0cd8afe2720bcd39e4fe2861b004e91ffd26deb6 100644 --- a/lib/python/dbrepo/RestClient.py +++ b/lib/python/dbrepo/RestClient.py @@ -1713,7 +1713,7 @@ class RestClient: :raises FormatNotAvailable: If the service could not represent the output. :raises ResponseCodeError: If something went wrong with the retrieval of the identifiers. """ - url = f'/api/identifiers' + url = f'/api/identifier' params = [] if database_id is not None: params.append(('dbid', database_id)) @@ -1745,6 +1745,35 @@ class RestClient: raise ResponseCodeError(f'Failed to get identifiers: response code: {response.status_code} is not ' f'200 (OK): {response.text}') + def get_images(self) -> List[ImageBrief] | str: + """ + Get list of container images. + + :returns: List of images, if successful. + """ + url = f'/api/image' + response = self._wrapper(method="get", url=url, headers={'Accept': 'application/json'}) + if response.status_code == 200: + body = response.json() + return TypeAdapter(List[ImageBrief]).validate_python(body) + raise ResponseCodeError(f'Failed to get images: response code: {response.status_code} is not ' + f'200 (OK): {response.text}') + + def get_messages(self) -> List[Message] | str: + """ + Get list of messages. + + :returns: List of messages, if successful. + """ + url = f'/api/message' + response = self._wrapper(method="get", url=url, headers={'Accept': 'application/json'}) + if response.status_code == 200: + body = response.json() + return TypeAdapter(List[Message]).validate_python(body) + raise ResponseCodeError(f'Failed to get messages: response code: {response.status_code} is not ' + f'200 (OK): {response.text}') + + def update_table_column(self, database_id: str, table_id: str, column_id: str, concept_uri: str = None, unit_uri: str = None) -> Column: """ diff --git a/lib/python/dbrepo/api/dto.py b/lib/python/dbrepo/api/dto.py index ac071cb412aa4f2b63306f1d8150397188a181fb..c378a6d9aa671a8eaf4babdb5c2f107be37212f5 100644 --- a/lib/python/dbrepo/api/dto.py +++ b/lib/python/dbrepo/api/dto.py @@ -665,6 +665,14 @@ class Identifier(BaseModel): publication_day: Optional[int] = None publication_month: Optional[int] = None +class Message(BaseModel): + id: int + type: str + link: Optional[str] = None + link_text: Optional[str] = None + display_start: Optional[Timestamp] = None + display_end: Optional[Timestamp] = None + class IdentifierBrief(BaseModel): id: str diff --git a/lib/python/tests/test_unit_identifier.py b/lib/python/tests/test_unit_identifier.py index 6509bcac5a3e9e20a13bf25f67c86b2196712517..9ac386437c29f4c65f6879d1a1f0c98641652652 100644 --- a/lib/python/tests/test_unit_identifier.py +++ b/lib/python/tests/test_unit_identifier.py @@ -187,7 +187,7 @@ class IdentifierUnitTest(unittest.TestCase): status=IdentifierStatusType.PUBLISHED, owner=UserBrief(id='8638c043-5145-4be8-a3e4-4b79991b0a16', username='mweise'))] # mock - mock.get('/api/identifiers', json=[exp[0].model_dump()], headers={"Accept": "application/json"}) + mock.get('/api/identifier', json=[exp[0].model_dump()], headers={"Accept": "application/json"}) # test response = RestClient().get_identifiers(database_id="6bd39359-b154-456d-b9c2-caa516a45732", view_id="e5229d24-584a-43e8-b9f6-d349c3053f9c", @@ -199,7 +199,7 @@ class IdentifierUnitTest(unittest.TestCase): with requests_mock.Mocker() as mock: exp = [] # mock - mock.get('/api/identifiers', json=[], headers={"Accept": "application/json"}) + mock.get('/api/identifier', json=[], headers={"Accept": "application/json"}) # test response = RestClient().get_identifiers(database_id="6bd39359-b154-456d-b9c2-caa516a45732", subset_id="0831bf54-9dd9-46fe-8c2c-c539332ea177") @@ -209,7 +209,7 @@ class IdentifierUnitTest(unittest.TestCase): with requests_mock.Mocker() as mock: exp = [] # mock - mock.get('/api/identifiers', json=[], headers={"Accept": "application/json"}) + mock.get('/api/identifier', json=[], headers={"Accept": "application/json"}) # test response = RestClient().get_identifiers(database_id="6bd39359-b154-456d-b9c2-caa516a45732", table_id="b3230b86-4743-498d-9015-3fad58049692") @@ -239,7 +239,7 @@ class IdentifierUnitTest(unittest.TestCase): def test_get_identifiers_404_fails(self): with requests_mock.Mocker() as mock: # mock - mock.get('/api/identifiers', status_code=404) + mock.get('/api/identifier', status_code=404) # test try: RestClient().get_identifiers() @@ -249,7 +249,7 @@ class IdentifierUnitTest(unittest.TestCase): def test_get_identifiers_406_fails(self): with requests_mock.Mocker() as mock: # mock - mock.get('/api/identifiers', status_code=406) + mock.get('/api/identifier', status_code=406) # test try: RestClient().get_identifiers() @@ -259,7 +259,7 @@ class IdentifierUnitTest(unittest.TestCase): def test_get_identifiers_unknown_fails(self): with requests_mock.Mocker() as mock: # mock - mock.get('/api/identifiers', status_code=202) + mock.get('/api/identifier', status_code=202) # test try: RestClient().get_identifiers() diff --git a/lib/python/tests/test_unit_image.py b/lib/python/tests/test_unit_image.py new file mode 100644 index 0000000000000000000000000000000000000000..2802efc69073ba10b7c7286b87cdb531ffafbbb1 --- /dev/null +++ b/lib/python/tests/test_unit_image.py @@ -0,0 +1,31 @@ +import unittest + +import requests_mock + +from dbrepo.RestClient import RestClient + +from dbrepo.api.dto import ImageBrief + + +class ImageUnitTest(unittest.TestCase): + + def test_get_images_empty_succeeds(self): + with requests_mock.Mocker() as mock: + # mock + mock.get('/api/image', json=[]) + # test + response = RestClient().get_images() + self.assertEqual([], response) + + def test_get_images_succeeds(self): + with requests_mock.Mocker() as mock: + exp = [ImageBrief(id=1, name="mariadb", version="11.1.3", jdbc_method="mariadb", default=False)] + # mock + mock.get('/api/image', json=[exp[0].model_dump()]) + # test + response = RestClient().get_images() + self.assertEqual(exp, response) + + +if __name__ == "__main__": + unittest.main() diff --git a/lib/python/tests/test_unit_messages.py b/lib/python/tests/test_unit_messages.py new file mode 100644 index 0000000000000000000000000000000000000000..cf863dcb6cbb0507cb97a67175274b5b50c61948 --- /dev/null +++ b/lib/python/tests/test_unit_messages.py @@ -0,0 +1,31 @@ +import unittest + +import requests_mock + +from dbrepo.RestClient import RestClient + +from dbrepo.api.dto import Message + + +class ImageUnitTest(unittest.TestCase): + + def test_get_message_empty_succeeds(self): + with requests_mock.Mocker() as mock: + # mock + mock.get('/api/message', json=[]) + # test + response = RestClient().get_messages() + self.assertEqual([], response) + + def test_get_images_succeeds(self): + with requests_mock.Mocker() as mock: + exp = [Message(id=1, type="info")] + # mock + mock.get('/api/message', json=[exp[0].model_dump()]) + # test + response = RestClient().get_messages() + self.assertEqual(exp, response) + + +if __name__ == "__main__": + unittest.main()