forked from nbialostosky/sample-python-cfd
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_image_controller.py
More file actions
85 lines (71 loc) · 2.29 KB
/
test_image_controller.py
File metadata and controls
85 lines (71 loc) · 2.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
# coding: utf-8
from __future__ import absolute_import
import unittest
from unittest import mock
from flask import json
from six import BytesIO
from openapi_server.models.error import Error # noqa: E501
from openapi_server.models.inline_response200 import InlineResponse200 # noqa: E501
from openapi_server.test import BaseTestCase
from openapi_server.controllers import image_controller
class TestImageController(BaseTestCase):
"""ImageController integration test stubs"""
# @unittest.skip('reason')
def test_add_image(self):
"""Test case for add_image
Add an image to the restaraunt
"""
headers = {
"Accept": "application/json",
"Content-Type": "multipart/form-data",
}
data = dict(fileName=(BytesIO(b"some file data"), "file.png"))
response = self.client.open(
"/CFD/1.0.0/image",
method="POST",
headers=headers,
data=data,
content_type="multipart/form-data",
)
try:
e = None
self.assert200(
response, "Response body is : " + response.data.decode("utf-8")
)
except BaseException as e:
raise
finally:
image_controller.delete_image(response.get_json().get("imageId"))
@mock.patch("os.remove")
def test_delete_image(self, mock_remove):
"""Test case for delete_image
Remove image
"""
headers = {
"Accept": "application/json",
}
response = self.client.open(
"/CFD/1.0.0/image/{image_id}".format(image_id=0),
method="DELETE",
headers=headers,
)
self.assertStatus(
response, 204, "Response body is : " + response.data.decode("utf-8")
)
assert mock_remove.call_count == 1
def test_get_image(self):
"""Test case for get_image
Get image
"""
self.test_add_image()
headers = {
"Accept": "image/png application/json",
}
response = self.client.open(
"/CFD/1.0.0/image/{image_id}".format(image_id=0),
method="GET",
headers=headers,
)
self.assert200(response)
if __name__ == "__main__":
unittest.main()