Skip to content

Commit

Permalink
First version of python-nextgen client tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Moritz Hannemann committed Feb 7, 2024
1 parent 30e92b2 commit 3c55d37
Show file tree
Hide file tree
Showing 76 changed files with 7,422 additions and 0 deletions.
37 changes: 37 additions & 0 deletions openapi/python-nextgen/test/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import scicat_openapi_client as soc

configuration = soc.Configuration(
host="http://localhost:3000"
)
api_client = soc.ApiClient(configuration)

users = {
'admin': soc.CredentialsDto(username='admin', password='am2jf70TPNZsSan'),
'ingestor': soc.CredentialsDto(username='ingestor', password='aman'),
'proposalIngestor': soc.CredentialsDto(
username='proposalIngestor',
password='aman'),
'archiveManager': soc.CredentialsDto(
username='archiveManager',
password='aman'),
'user1': soc.CredentialsDto(
username='user2',
password='a609316768619f154ef58db4d847b75e'),
'user2': soc.CredentialsDto(
username='user2',
password='f522d1d715970073a6413474ca0e0f63'),
#
'nouser': soc.CredentialsDto(
username='nouser',
password='f522d1d715970073a6413474ca0e0f63'),
}


def login(api, user: str):
auth_api = soc.AuthApi(api_client)
login_dto = auth_api.auth_controller_login(users[user])
api.api_client.configuration.access_token = login_dto.access_token


def logout(api):
api.api_client.configuration.access_token = ""
48 changes: 48 additions & 0 deletions openapi/python-nextgen/test/test_admin_api.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
# coding: utf-8

"""
SciCat backend API
This is the API for the SciCat Backend # noqa: E501
The version of the OpenAPI document: 4.0.0
Generated by OpenAPI Generator (https://openapi-generator.tech)
Do not edit the class manually.
"""

import unittest

from scicat_openapi_client.api.admin_api import AdminApi # noqa: E501
from test import api_client, login, logout


class TestAdminApi(unittest.TestCase):
"""AdminApi unit test stubs"""

@classmethod
def setUpClass(cls):
cls.api = AdminApi(api_client)
login(cls.api, 'ingestor')

@classmethod
def tearDownClass(cls):
logout(cls.api)

def test_admin_controller_get_config(self):
"""Test case for admin_controller_get_config
"""
response = self.api.admin_controller_get_config()
assert response['accessTokenPrefix'] == 'Bearer '

def test_admin_controller_get_theme(self):
"""Test case for admin_controller_get_theme
"""
response = self.api.admin_controller_get_theme()
assert response['name']


if __name__ == '__main__':
unittest.main()
92 changes: 92 additions & 0 deletions openapi/python-nextgen/test/test_attachment.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
# coding: utf-8

"""
SciCat backend API
This is the API for the SciCat Backend # noqa: E501
The version of the OpenAPI document: 4.0.0
Generated by OpenAPI Generator (https://openapi-generator.tech)
Do not edit the class manually.
"""
import datetime
import random
import time
import unittest

from scicat_openapi_client.models.attachment import Attachment # noqa: E501


def make_instance(include_optional):
"""Test Attachment
include_option is a boolean, when False only required
params are included, when True both required and
optional params are included """
random.seed(time.perf_counter())
if include_optional:
return Attachment(
created_by='ingestor',
updated_by='ingestor',
created_at=datetime.datetime.strptime(
'2013-10-20 19:20:30.00',
'%Y-%m-%d %H:%M:%S.%f'),
updated_at=datetime.datetime.strptime(
'2013-10-20 19:20:30.00',
'%Y-%m-%d %H:%M:%S.%f'),
owner_group='ingestor',
access_groups=[
'admin',
'ingestor'
],
instrument_group='instrument',
is_published=True,
id=str(random.randint(0, 99999)),
thumbnail='Thumbnail',
caption='Caption',
dataset_id=str(random.randint(0, 99999)),
proposal_id=str(random.randint(0, 99999)),
sample_id=str(random.randint(0, 99999))
)
else:
return Attachment(
created_by='ingestor',
updated_by='ingestor',
created_at=datetime.datetime.strptime(
'2013-10-20 19:20:30.00',
'%Y-%m-%d %H:%M:%S.%f'),
updated_at=datetime.datetime.strptime(
'2013-10-20 19:20:30.00',
'%Y-%m-%d %H:%M:%S.%f'),
owner_group='ingestor',
access_groups=[
'admin',
'ingestor'
],
is_published=True,
id=str(random.randint(0, 99999)),
thumbnail='Thumbnail',
caption='Caption',
)


class TestAttachment(unittest.TestCase):
"""Attachment unit test stubs"""

def setUp(self):
pass

def tearDown(self):
pass

def testRequiredAttachment(self):
"""Test Attachment"""
make_instance(include_optional=False)

def testOptionalAttachment(self):
"""Test Attachment"""
make_instance(include_optional=True)


if __name__ == '__main__':
unittest.main()
56 changes: 56 additions & 0 deletions openapi/python-nextgen/test/test_auth_api.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
# coding: utf-8

"""
SciCat backend API
This is the API for the SciCat Backend # noqa: E501
The version of the OpenAPI document: 4.0.0
Generated by OpenAPI Generator (https://openapi-generator.tech)
Do not edit the class manually.
"""

import unittest

from scicat_openapi_client.api.auth_api import AuthApi # noqa: E501
from test import api_client, users


class TestAuthApi(unittest.TestCase):
"""AuthApi unit test stubs"""

@classmethod
def setUpClass(cls):
cls.api = AuthApi(api_client)

def tearDown(self):
pass

def test_auth_controller_login(self):
"""Test case for auth_controller_login
"""
login_dto = self.api.auth_controller_login(users['ingestor'])
assert str(login_dto.access_token)

def test_auth_controller_logout(self):
"""Test case for auth_controller_logout
It logs the current user out. # noqa: E501
"""
login_dto = self.api.auth_controller_login(users['ingestor'])
self.api.api_client.configuration.access_token = login_dto.access_token
self.api.auth_controller_logout()

def test_auth_controller_whoami(self):
"""Test case for auth_controller_whoami
"""
login_dto = self.api.auth_controller_login(users['ingestor'])
self.api.api_client.configuration.access_token = login_dto.access_token
self.api.auth_controller_whoami()


if __name__ == '__main__':
unittest.main()
68 changes: 68 additions & 0 deletions openapi/python-nextgen/test/test_create_attachment_dto.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
# coding: utf-8

"""
SciCat backend API
This is the API for the SciCat Backend # noqa: E501
The version of the OpenAPI document: 4.0.0
Generated by OpenAPI Generator (https://openapi-generator.tech)
Do not edit the class manually.
"""
import random
import time
import unittest

from scicat_openapi_client.models.create_attachment_dto import \
CreateAttachmentDto # noqa: E501


def make_instance(include_optional):
"""Test CreateAttachmentDto
include_option is a boolean, when False only required
params are included, when True both required and
optional params are included """
random.seed(time.perf_counter())
if include_optional:
return CreateAttachmentDto(
owner_group='ingestor',
access_groups=[
'admin',
'ingestor'
],
instrument_group='instrument',
id=str(random.randint(0, 99999)),
thumbnail='Thumbnail',
caption='Caption',
dataset_id=str(random.randint(0, 99999)),
proposal_id=str(random.randint(0, 99999)),
sample_id=str(random.randint(0, 99999))
)
else:
return CreateAttachmentDto(
owner_group='ingestor',
caption='Caption',
)


class TestCreateAttachmentDto(unittest.TestCase):
"""CreateAttachmentDto unit test stubs"""

def setUp(self):
pass

def tearDown(self):
pass

def testRequiredCreateAttachmentDto(self):
"""Test CreateAttachmentDto"""
make_instance(include_optional=False)

def testCreateAttachmentDto(self):
"""Test CreateAttachmentDto"""
make_instance(include_optional=True)


if __name__ == '__main__':
unittest.main()
52 changes: 52 additions & 0 deletions openapi/python-nextgen/test/test_create_custom_jwt.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
# coding: utf-8

"""
SciCat backend API
This is the API for the SciCat Backend # noqa: E501
The version of the OpenAPI document: 4.0.0
Generated by OpenAPI Generator (https://openapi-generator.tech)
Do not edit the class manually.
"""

import unittest

from scicat_openapi_client.models.create_custom_jwt import \
CreateCustomJwt # noqa: E501


def make_instance(include_optional):
"""Test CreateCustomJwt
include_option is a boolean, when False only required
params are included, when True both required and
optional params are included """
if include_optional:
return CreateCustomJwt(
expires_in='10000000'
)
else:
return CreateCustomJwt()


class TestCreateCustomJwt(unittest.TestCase):
"""CreateCustomJwt unit test stubs"""

def setUp(self):
pass

def tearDown(self):
pass

def testRequiredCreateCustomJwt(self):
"""Test CreateCustomJwt"""
make_instance(include_optional=False)

def testOptionalCreateCustomJwt(self):
"""Test CreateCustomJwt"""
make_instance(include_optional=True)


if __name__ == '__main__':
unittest.main()
Loading

0 comments on commit 3c55d37

Please sign in to comment.