cornflow 1.1.1a1__py3-none-any.whl → 1.1.4__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (35) hide show
  1. cornflow/app.py +0 -4
  2. cornflow/cli/utils.py +1 -1
  3. cornflow/config.py +2 -10
  4. cornflow/endpoints/__init__.py +0 -14
  5. cornflow/endpoints/execution.py +1 -1
  6. cornflow/endpoints/login.py +1 -8
  7. cornflow/models/__init__.py +0 -2
  8. cornflow/models/execution.py +0 -8
  9. cornflow/models/meta_models.py +12 -23
  10. cornflow/schemas/execution.py +0 -3
  11. cornflow/shared/const.py +0 -21
  12. cornflow/shared/exceptions.py +9 -20
  13. cornflow/tests/const.py +0 -7
  14. cornflow/tests/{custom_live_server.py → custom_liveServer.py} +1 -3
  15. cornflow/tests/custom_test_case.py +3 -2
  16. cornflow/tests/integration/test_commands.py +1 -1
  17. cornflow/tests/integration/test_cornflowclient.py +28 -116
  18. cornflow/tests/unit/test_alarms.py +9 -22
  19. cornflow/tests/unit/test_cli.py +5 -10
  20. cornflow/tests/unit/test_commands.py +2 -6
  21. cornflow/tests/unit/test_executions.py +0 -5
  22. cornflow/tests/unit/test_main_alarms.py +0 -8
  23. cornflow/tests/unit/test_users.py +2 -5
  24. {cornflow-1.1.1a1.dist-info → cornflow-1.1.4.dist-info}/METADATA +7 -7
  25. {cornflow-1.1.1a1.dist-info → cornflow-1.1.4.dist-info}/RECORD +28 -35
  26. {cornflow-1.1.1a1.dist-info → cornflow-1.1.4.dist-info}/WHEEL +1 -1
  27. cornflow/endpoints/reports.py +0 -283
  28. cornflow/migrations/versions/83164be03c23_.py +0 -40
  29. cornflow/migrations/versions/96f00d0961d1_reports_table.py +0 -50
  30. cornflow/models/reports.py +0 -119
  31. cornflow/schemas/reports.py +0 -48
  32. cornflow/static/v1.json +0 -3854
  33. cornflow/tests/unit/test_reports.py +0 -308
  34. {cornflow-1.1.1a1.dist-info → cornflow-1.1.4.dist-info}/entry_points.txt +0 -0
  35. {cornflow-1.1.1a1.dist-info → cornflow-1.1.4.dist-info}/top_level.txt +0 -0
@@ -1,308 +0,0 @@
1
- """
2
- Unit test for the reports endpoints
3
- """
4
-
5
- import shutil
6
- import os
7
- import json
8
-
9
- from flask import current_app
10
-
11
- from cornflow.models import ReportModel, InstanceModel, ExecutionModel
12
- from cornflow.endpoints.reports import get_report_path
13
- from cornflow.tests.const import (
14
- INSTANCE_PATH,
15
- REPORT_PATH,
16
- REPORT_HTML_FILE_PATH,
17
- REPORT_URL,
18
- INSTANCE_URL,
19
- EXECUTION_PATH,
20
- EXECUTION_URL_NORUN,
21
- REPORT_PDF_FILE_PATH,
22
- )
23
- from cornflow.tests.custom_test_case import CustomTestCase
24
-
25
-
26
- class TestReportsListEndpoint(CustomTestCase):
27
- def setUp(self):
28
- # we create an instance, and an execution
29
- super().setUp()
30
-
31
- self.service_token = self.create_service_user()
32
-
33
- # instance:
34
- with open(INSTANCE_PATH) as f:
35
- payload = json.load(f)
36
- fk_id = self.create_new_row(INSTANCE_URL, InstanceModel, payload)
37
-
38
- def load_file_fk(_file, **kwargs):
39
- with open(_file) as f:
40
- temp = json.load(f)
41
- temp.update(kwargs)
42
- return temp
43
-
44
- # execution:
45
- fk_id = self.create_new_row(
46
- EXECUTION_URL_NORUN,
47
- ExecutionModel,
48
- payload=load_file_fk(EXECUTION_PATH, instance_id=fk_id),
49
- )
50
-
51
- self.payload = load_file_fk(REPORT_PATH, execution_id=fk_id)
52
-
53
- self.url = REPORT_URL
54
- self.model = ReportModel
55
-
56
- self.keys_to_check = [
57
- "id",
58
- "file_url",
59
- "name",
60
- "execution_id",
61
- "description",
62
- "created_at",
63
- "updated_at",
64
- "deleted_at",
65
- ]
66
-
67
- def tearDown(self):
68
- super().tearDown()
69
- my_directories = os.listdir(current_app.config["UPLOAD_FOLDER"])
70
- for _dir in my_directories:
71
- try:
72
- shutil.rmtree(os.path.join(current_app.config["UPLOAD_FOLDER"], _dir))
73
- except OSError:
74
- pass
75
-
76
- def test_new_report_html(self):
77
- with open(REPORT_HTML_FILE_PATH, "rb") as _file:
78
- response = self.client.post(
79
- self.url,
80
- data=dict(file=_file, **self.payload),
81
- follow_redirects=True,
82
- headers=self.get_header_with_auth(
83
- self.service_token, content_type="multipart/form-data"
84
- ),
85
- )
86
-
87
- self.assertEqual(201, response.status_code)
88
-
89
- for key in self.keys_to_check:
90
- self.assertTrue(key in response.json)
91
-
92
- for key, value in self.payload.items():
93
- self.assertEqual(response.json[key], value)
94
-
95
- # check that the file in the test folder and the one generated on the static fodler are equal
96
- with open(REPORT_HTML_FILE_PATH, "rb") as f:
97
- file = f.read()
98
-
99
- my_upload_path = get_report_path(response.json)
100
-
101
- with open(my_upload_path, "rb") as f:
102
- file2 = f.read()
103
-
104
- self.assertEqual(file, file2)
105
- return response.json
106
-
107
- def test_new_report_empty(self):
108
- response = self.client.post(
109
- self.url,
110
- data=dict(**self.payload),
111
- follow_redirects=True,
112
- headers=self.get_header_with_auth(
113
- self.service_token, content_type="multipart/form-data"
114
- ),
115
- )
116
-
117
- self.assertEqual(201, response.status_code)
118
-
119
- for key in self.keys_to_check:
120
- self.assertTrue(key in response.json)
121
-
122
- for key, value in self.payload.items():
123
- self.assertEqual(response.json[key], value)
124
-
125
- # check that we did not save any file
126
- my_upload_path = (
127
- f"{current_app.config['UPLOAD_FOLDER']}/"
128
- f"{self.payload['execution_id']}/{self.payload['name']}.html"
129
- )
130
- self.assertFalse(os.path.exists(my_upload_path))
131
-
132
- return response.json
133
-
134
- def test_new_report_pdf(self):
135
- response = self.client.post(
136
- self.url,
137
- data=dict(file=(open(REPORT_PDF_FILE_PATH, "rb")), **self.payload),
138
- follow_redirects=True,
139
- headers=self.get_header_with_auth(
140
- self.service_token, content_type="multipart/form-data"
141
- ),
142
- )
143
-
144
- self.assertEqual(201, response.status_code)
145
-
146
- for key in self.keys_to_check:
147
- self.assertTrue(key in response.json)
148
-
149
- for key, value in self.payload.items():
150
- self.assertEqual(response.json[key], value)
151
-
152
- # check that the file in the test folder and the one generated on the static fodler are equal
153
- with open(REPORT_PDF_FILE_PATH, "rb") as f:
154
- file = f.read()
155
-
156
- my_upload_path = get_report_path(response.json)
157
- with open(my_upload_path, "rb") as f:
158
- file2 = f.read()
159
-
160
- self.assertEqual(file, file2)
161
- return response.json
162
-
163
- def test_new_report_not_allowed(self):
164
- with open(REPORT_HTML_FILE_PATH, "rb") as _file:
165
- response = self.client.post(
166
- self.url,
167
- data=dict(file=_file, **self.payload),
168
- follow_redirects=True,
169
- headers=self.get_header_with_auth(
170
- self.token, content_type="multipart/form-data"
171
- ),
172
- )
173
-
174
- self.assertEqual(response.status_code, 403)
175
-
176
- def test_edit_report_not_allowed(self):
177
- item = self.test_new_report_html()
178
- payload = dict(name="new name2")
179
- response = self.client.put(
180
- f"{self.url}{item['id']}/edit/",
181
- data=payload,
182
- follow_redirects=True,
183
- headers=self.get_header_with_auth(
184
- self.token, content_type="multipart/form-data"
185
- ),
186
- )
187
-
188
- self.assertEqual(response.status_code, 403)
189
-
190
- def test_new_report_no_execution(self):
191
- payload = dict(self.payload)
192
- payload["execution_id"] = "bad_id"
193
- response = self.client.post(
194
- self.url,
195
- data=dict(file=(open(REPORT_HTML_FILE_PATH, "rb")), **payload),
196
- follow_redirects=True,
197
- headers=self.get_header_with_auth(
198
- self.service_token, content_type="multipart/form-data"
199
- ),
200
- )
201
-
202
- self.assertEqual(404, response.status_code)
203
- self.assertTrue("error" in response.json)
204
-
205
- def test_get_no_reports(self):
206
- self.get_no_rows(self.url)
207
-
208
- def test_get_all_reports(self):
209
- item = self.test_new_report_html()
210
- response = self.client.get(
211
- self.url, headers=self.get_header_with_auth(self.token)
212
- )
213
-
214
- self.assertEqual(1, len(response.json))
215
- self.assertEqual(item, response.json[0])
216
-
217
- def test_get_one_report(self):
218
- item = self.test_new_report_html()
219
- response = self.client.get(
220
- f"{self.url}{item['id']}/", headers=self.get_header_with_auth(self.token)
221
- )
222
-
223
- content = response.get_data()
224
-
225
- with open(REPORT_HTML_FILE_PATH, "rb") as f:
226
- file = f.read()
227
-
228
- self.assertEqual(200, response.status_code)
229
- self.assertEqual(content, file)
230
-
231
- def test_modify_report(self):
232
- item = self.test_new_report_html()
233
-
234
- payload = {"name": "new_name", "description": "some_description"}
235
-
236
- response = self.client.put(
237
- f"{self.url}{item['id']}/edit/",
238
- headers=self.get_header_with_auth(
239
- self.service_token, content_type="multipart/form-data"
240
- ),
241
- follow_redirects=True,
242
- data=payload,
243
- )
244
-
245
- self.assertEqual(response.status_code, 200)
246
-
247
- response = self.client.get(
248
- f"{self.url}{item['id']}/", headers=self.get_header_with_auth(self.token)
249
- )
250
- # response.json
251
- self.assertEqual(200, response.status_code)
252
- self.assertEqual("some_description", dict(response.headers)["File-Description"])
253
-
254
- def test_modify_report_file(self):
255
- item = self.test_new_report_empty()
256
-
257
- payload = {"name": "new_name", "description": "some_description"}
258
- response = self.client.get(
259
- f"{self.url}{item['id']}/",
260
- headers=self.get_header_with_auth(self.token),
261
- )
262
- self.assertEqual(response.status_code, 200)
263
-
264
- self.assertIsNone(response.json["file_url"])
265
-
266
- response = self.client.put(
267
- f"{self.url}{item['id']}/edit/",
268
- data=dict(file=(open(REPORT_HTML_FILE_PATH, "rb")), **payload),
269
- headers=self.get_header_with_auth(
270
- self.service_token, content_type="multipart/form-data"
271
- ),
272
- )
273
-
274
- self.assertEqual(response.status_code, 200)
275
-
276
- response = self.client.get(
277
- f"{self.url}{item['id']}/", headers=self.get_header_with_auth(self.token)
278
- )
279
-
280
- self.assertEqual(200, response.status_code)
281
- self.assertEqual("some_description", dict(response.headers)["File-Description"])
282
-
283
- # check that the file in the test folder and the one generated on the static folder are equal
284
- with open(REPORT_HTML_FILE_PATH, "rb") as f:
285
- file = f.read()
286
-
287
- content = response.get_data()
288
-
289
- self.assertEqual(file, content)
290
- return response.json
291
-
292
- def test_delete_report(self):
293
- item = self.test_new_report_html()
294
- response = self.client.delete(
295
- f"{self.url}{item['id']}/", headers=self.get_header_with_auth(self.token)
296
- )
297
-
298
- self.assertEqual(200, response.status_code)
299
- self.assertTrue("message" in response.json)
300
-
301
- my_upload_path = get_report_path(item)
302
-
303
- self.assertFalse(os.path.exists(my_upload_path))
304
-
305
- response = self.client.get(
306
- f"{self.url}{item['id']}/", headers=self.get_header_with_auth(self.token)
307
- )
308
- self.assertEqual(404, response.status_code)