init commit
This commit is contained in:
@@ -10,7 +10,7 @@ class BaseTestCase(TestCase):
|
||||
|
||||
def create_app(self):
|
||||
logging.getLogger('connexion.operation').setLevel('ERROR')
|
||||
app = connexion.App(__name__, specification_dir='../openapi/')
|
||||
app = connexion.App(__name__ , specification_dir='../openapi/')
|
||||
app.app.json_encoder = JSONEncoder
|
||||
app.add_api('openapi.yaml', pythonic_params=True)
|
||||
app.add_api('openapi.yaml', pythonic_params=True, base_path='/api')
|
||||
return app.app
|
||||
|
||||
@@ -2,10 +2,12 @@ import unittest
|
||||
|
||||
from flask import json
|
||||
|
||||
import openapi_server
|
||||
from openapi_server.models.patch_notes import PatchNotes # noqa: E501
|
||||
from openapi_server.test import BaseTestCase
|
||||
|
||||
|
||||
|
||||
class TestDefaultController(BaseTestCase):
|
||||
"""DefaultController integration test stubs"""
|
||||
|
||||
@@ -23,7 +25,8 @@ class TestDefaultController(BaseTestCase):
|
||||
headers=headers)
|
||||
self.assert200(response,
|
||||
'Response body is : ' + response.data.decode('utf-8'))
|
||||
|
||||
response = self.client.get('/patchnotes',)
|
||||
assert response.status_code == 200
|
||||
def test_patch_note_delete(self):
|
||||
"""Test case for patch_note_delete
|
||||
|
||||
|
||||
@@ -1,62 +1,167 @@
|
||||
import datetime
|
||||
import logging
|
||||
import unittest
|
||||
import unittest.mock as mock
|
||||
from datetime import datetime
|
||||
|
||||
from flask import json
|
||||
from flask import json, url_for
|
||||
|
||||
import openapi_server
|
||||
from openapi_server.models.patch_notes import PatchNotes # noqa: E501
|
||||
import app
|
||||
from openapi_server.test import BaseTestCase
|
||||
|
||||
logging.basicConfig(level=logging.DEBUG)
|
||||
|
||||
|
||||
|
||||
class TestPatchnotesController(BaseTestCase):
|
||||
"""PatchnotesController integration test stubs"""
|
||||
|
||||
def test_get_patchnotes(self):
|
||||
def setUp(self):
|
||||
self.app = app.app
|
||||
self.app.config['SERVER_NAME'] = '127.0.0.1:8080'
|
||||
|
||||
print('url map:' + str(self.app.url_map))
|
||||
|
||||
@unittest.mock.patch(
|
||||
'openapi_server.controllers.patchnotes_controller.patchnotes_date_get')
|
||||
def test_get_patchnotes(self, mock_get_patchnotes):
|
||||
"""Test case for get_patchnotes
|
||||
|
||||
|
||||
"""
|
||||
headers = {
|
||||
headers = {
|
||||
'Accept': 'application/json',
|
||||
}
|
||||
logging.error('self client:' + str(self.client))
|
||||
logging.error('mock get patchnotes' + str(mock_get_patchnotes))
|
||||
response = self.client.open(
|
||||
'/patchnotes',
|
||||
'/patchnotes/2025-01-02',
|
||||
method='GET',
|
||||
headers=headers)
|
||||
self.assert200(response,
|
||||
'Response body is : ' + response.data.decode('utf-8'))
|
||||
headers=headers
|
||||
)
|
||||
response_data = response.data.decode('utf-8').strip().strip('\"')
|
||||
logging.error(response_data + "response_data")
|
||||
response_data_type = type(response_data)
|
||||
logging.error("response_data_type:" + str(response_data_type))
|
||||
logging.error("response data" + response_data)
|
||||
response_data = datetime.strptime(response_data, '%Y-%m-%d').date()
|
||||
logging.error(str(response_data) + "response_data after format")
|
||||
try:
|
||||
formatted_date = response_data.strftime('%Y-%m-%d')
|
||||
logging.error(formatted_date)
|
||||
logging.info("valid date")
|
||||
except ValueError:
|
||||
logging.error("Not valid date")
|
||||
self.assert200(response, 'Response body is : ' + response.data.decode('utf-8'))
|
||||
|
||||
@unittest.mock.patch('openapi_server.controllers.patchnotes_controller.patchnotes_date_get')
|
||||
def test_get_patchnotes_404(self, mock_get_patchnotes): # DONE
|
||||
"""Test case for get_patchnotes
|
||||
|
||||
"""
|
||||
|
||||
headers = {
|
||||
'Accept': 'application/json',
|
||||
}
|
||||
|
||||
with self.app.test_request_context():
|
||||
full_url = url_for('get_patchnotes', date='2023-01-01', _external=True)
|
||||
logging.error("Full URL: " + full_url)
|
||||
url = '/api/patchnotes/{date}'.format(date='2023-01-01')
|
||||
logging.error(f"request URL: {url}")
|
||||
logging.error('self client:' + str(self.client))
|
||||
logging.error('mock get patchnotes' + str(mock_get_patchnotes))
|
||||
logging.error('self name stuff:' + str(self.app.config['SERVER_NAME']))
|
||||
response = self.client.open(
|
||||
url,
|
||||
method='GET',
|
||||
headers=headers
|
||||
)
|
||||
logging.error(f"Response Status Code: {response.status_code}")
|
||||
logging.error(f"Response Data: {response.data.decode('utf-8')}")
|
||||
self.assert404(response, 'Response body is : ' + response.data.decode('utf-8'))
|
||||
|
||||
@unittest.mock.patch('openapi_server.controllers.patchnotes_controller.patchnotes_patch_iddelete')
|
||||
def test_patch_note_delete(self, balala):
|
||||
|
||||
def test_patch_note_delete(self):
|
||||
"""Test case for patch_note_delete
|
||||
|
||||
|
||||
"""
|
||||
headers = {
|
||||
headers = {
|
||||
}
|
||||
response = self.client.open(
|
||||
'/patchnotes/{patch_id}'.format(patch_id='patch_id_example'),
|
||||
method='DELETE',
|
||||
headers=headers)
|
||||
self.assert200(response,
|
||||
'Response body is : ' + response.data.decode('utf-8'))
|
||||
|
||||
def test_post_patchnotes(self):
|
||||
patch_note_mock = {
|
||||
"changes": "test changes",
|
||||
"date": "2025-01-02",
|
||||
"patchID": "29e80bcc-5981-4a52-99e1-373442dea9b9",
|
||||
"title": "test patch"
|
||||
}
|
||||
|
||||
self.client.open(
|
||||
'/patchnotes',
|
||||
method='POST',
|
||||
headers=headers,
|
||||
data=json.dumps(patch_note_mock),
|
||||
content_type='application/json'
|
||||
)
|
||||
|
||||
response = self.client.open(
|
||||
'/patchnotes/{patch_id}'.format(patch_id=patch_note_mock['patchID']),
|
||||
method='DELETE',
|
||||
headers=headers
|
||||
)
|
||||
|
||||
self.assert200(response, 'Response body is : ' + response.data.decode('utf-8'))
|
||||
|
||||
@unittest.mock.patch('openapi_server.controllers.patchnotes_controller.patchnotes_patch_iddelete')
|
||||
def test_patch_note_delete_not_found(self, balala):
|
||||
|
||||
"""Test case for patch_note_delete
|
||||
|
||||
"""
|
||||
headers = {
|
||||
}
|
||||
|
||||
patch_note_mock = {
|
||||
"changes": "test changes",
|
||||
"date": "2025-01-02",
|
||||
"patchID": "29e80bcc-5981-4a52-99e1-373442dea9b9",
|
||||
"title": "test patch"
|
||||
}
|
||||
|
||||
response = self.client.open(
|
||||
'/patchnotes/{patch_id}'.format(patch_id=''),
|
||||
method='DELETE',
|
||||
headers=headers
|
||||
)
|
||||
|
||||
self.assert404(response, 'Response body is : ' + response.data.decode('utf-8'))
|
||||
|
||||
@unittest.mock.patch('openapi_server.controllers.patchnotes_controller.patchnotes_post')
|
||||
def test_post_patchnotes(self, balala):
|
||||
"""Test case for post_patchnotes
|
||||
|
||||
|
||||
"""
|
||||
patch_notes = openapi_server.PatchNotes()
|
||||
headers = {
|
||||
|
||||
post_patchnotes_mock = {
|
||||
"changes": "test changes",
|
||||
"date": "2025-01-02",
|
||||
"patchID": "29e80bcc-5981-4a52-99e1-373442dea9b9",
|
||||
"title": "test patch"
|
||||
}
|
||||
headers = {
|
||||
'Accept': 'application/json',
|
||||
'Content-Type': 'application/json',
|
||||
}
|
||||
|
||||
response = self.client.open(
|
||||
'/patchnotes',
|
||||
method='POST',
|
||||
headers=headers,
|
||||
data=json.dumps(patch_notes),
|
||||
content_type='application/json')
|
||||
self.assert200(response,
|
||||
'Response body is : ' + response.data.decode('utf-8'))
|
||||
data=json.dumps(post_patchnotes_mock),
|
||||
content_type='application/json'
|
||||
)
|
||||
|
||||
self.assert200(response, 'Response body is : ' + response.data.decode('utf-8'))
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
||||
Reference in New Issue
Block a user