Describe the bug
There are six errors and two failures in unit test for the new datetime data format due to type mismatch.
To Reproduce
Steps to reproduce the behavior:
run 'green' unit test
Expected behavior
OK (passes=47)
Observed behavior
When running 'green'
tests.test_models
TestPromotionResourceModel
F Test creating a promotion using the deserialize method
tests.test_routes
E It should return 400 Bad Request if the data is invalid
F It should respond to a proper create with 201 status code and return the data.
E Test that deleting an expired promotion returns a 405 HTTP status code.
E Test the deletion of a non-expired promotion. The test verifies that the response status
E It should return 415 Unsupported Media Type when Content-Type is not supported
E It should not update an expired Promotion
E Create a Promotion and then update it
Name Stmts Miss Cover Missing
----------------------------------------------------------------
service/__init__.py 17 2 88% 31-32
service/common/__init__.py 0 0 100%
service/common/cli_commands.py 7 0 100%
service/common/error_handlers.py 41 6 85% 98-100, 113-115
service/common/log_handlers.py 11 1 91% 35
service/common/status.py 45 0 100%
service/config.py 5 0 100%
service/models.py 99 6 94% 79, 95, 97, 99, 101, 103
service/routes.py 67 19 72% 103-112, 133-152
----------------------------------------------------------------
TOTAL 292 34 88%
Ran 47 tests in 1.970s using 1 process
Coverage of 88% is below minimum level of 95%
FAILED (errors=6, failures=2, passes=39)
Coverage of 88% is below minimum level of 95%
Screenshots
If applicable, add screenshots to help explain your problem.
Additional context
Failure in tests.test_models.TestPromotionResourceModel.test_create_with_deserialize
File "/usr/local/lib/python3.11/unittest/case.py", line 57, in testPartExecutor
yield
File "/usr/local/lib/python3.11/unittest/case.py", line 623, in run
self._callTestMethod(testMethod)
File "/usr/local/lib/python3.11/unittest/case.py", line 579, in _callTestMethod
if method() is not None:
^^^^^^^^
File "/app/tests/test_models.py", line 384, in test_create_with_deserialize
self.assertEqual(fetched_promotion.start, datetime(2023, 1, 1))
File "/usr/local/lib/python3.11/unittest/case.py", line 873, in assertEqual
assertion_func(first, second, msg=msg)
File "/usr/local/lib/python3.11/unittest/case.py", line 866, in _baseAssertEqual
raise self.failureException(msg)
AssertionError: datetime.date(2023, 1, 1) != datetime.datetime(2023, 1, 1, 0, 0)
Error in tests.test_routes.TestPromotionResourceModel.test_bad_request
File "/usr/local/lib/python3.11/unittest/case.py", line 57, in testPartExecutor
yield
File "/usr/local/lib/python3.11/unittest/case.py", line 623, in run
self._callTestMethod(testMethod)
File "/usr/local/lib/python3.11/unittest/case.py", line 579, in _callTestMethod
if method() is not None:
^^^^^^^^
File "/app/tests/test_routes.py", line 117, in test_bad_request
response = self.client.put(
^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/site-packages/werkzeug/test.py", line 1252, in put
return self.open(*args, **kw)
^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/site-packages/flask/testing.py", line 219, in open
response = super().open(
^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/site-packages/werkzeug/test.py", line 1196, in open
response = self.run_wsgi_app(request.environ, buffered=buffered)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/site-packages/werkzeug/test.py", line 1068, in run_wsgi_app
rv = run_wsgi_app(self.application, environ, buffered=buffered)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/site-packages/werkzeug/test.py", line 1344, in run_wsgi_app
app_rv = app(environ, start_response)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/site-packages/flask/app.py", line 2213, in __call__
return self.wsgi_app(environ, start_response)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/site-packages/flask/app.py", line 2193, in wsgi_app
response = self.handle_exception(e)
^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/site-packages/flask/app.py", line 2190, in wsgi_app
response = self.full_dispatch_request()
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/site-packages/flask/app.py", line 1486, in full_dispatch_request
rv = self.handle_user_exception(e)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/site-packages/flask/app.py", line 1484, in full_dispatch_request
rv = self.dispatch_request()
^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/site-packages/flask/app.py", line 1469, in dispatch_request
return self.ensure_sync(self.view_functions[rule.endpoint])(**view_args)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/app/service/routes.py", line 132, in update_promotion
if datetime.now() > promotion.expired:
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: can't compare datetime.datetime to datetime.date
Failure in tests.test_routes.TestPromotionResourceModel.test_create
File "/usr/local/lib/python3.11/unittest/case.py", line 57, in testPartExecutor
yield
File "/usr/local/lib/python3.11/unittest/case.py", line 623, in run
self._callTestMethod(testMethod)
File "/usr/local/lib/python3.11/unittest/case.py", line 579, in _callTestMethod
if method() is not None:
^^^^^^^^
File "/app/tests/test_routes.py", line 222, in test_create
self.assertEqual(response_json, data_orig)
File "/usr/local/lib/python3.11/unittest/case.py", line 873, in assertEqual
assertion_func(first, second, msg=msg)
File "/usr/local/lib/python3.11/unittest/case.py", line 1172, in assertDictEqual
self.fail(self._formatMessage(msg, standardMsg))
File "/usr/local/lib/python3.11/unittest/case.py", line 703, in fail
raise self.failureException(msg)
AssertionError: {'code': 'c4d49ec2-cc48-4fa5-b661-d414aba3c[147 chars]True} != {'name': 'Fundamental system-worthy product[179 chars]0.37}
{'code': 'c4d49ec2-cc48-4fa5-b661-d414aba3cc94',
- 'expired': '2023-11-17',
+ 'expired': '2023-11-17T08:26:25.762875',
? ++++++++++++++++
'name': 'Fundamental system-worthy product',
'promo_type': 4,
- 'start': '2023-11-17',
+ 'start': '2023-11-17T04:27:23.357840',
'value': 10.37,
'whole_store': True}
Error in tests.test_routes.TestPromotionResourceModel.test_delete_expired_promotion
File "/usr/local/lib/python3.11/unittest/case.py", line 57, in testPartExecutor
yield
File "/usr/local/lib/python3.11/unittest/case.py", line 623, in run
self._callTestMethod(testMethod)
File "/usr/local/lib/python3.11/unittest/case.py", line 579, in _callTestMethod
if method() is not None:
^^^^^^^^
File "/app/tests/test_routes.py", line 194, in test_delete_expired_promotion
response = self.client.delete(f"/promotions/{promotion.id}")
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/site-packages/werkzeug/test.py", line 1257, in delete
return self.open(*args, **kw)
^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/site-packages/flask/testing.py", line 219, in open
response = super().open(
^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/site-packages/werkzeug/test.py", line 1196, in open
response = self.run_wsgi_app(request.environ, buffered=buffered)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/site-packages/werkzeug/test.py", line 1068, in run_wsgi_app
rv = run_wsgi_app(self.application, environ, buffered=buffered)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/site-packages/werkzeug/test.py", line 1344, in run_wsgi_app
app_rv = app(environ, start_response)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/site-packages/flask/app.py", line 2213, in __call__
return self.wsgi_app(environ, start_response)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/site-packages/flask/app.py", line 2193, in wsgi_app
response = self.handle_exception(e)
^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/site-packages/flask/app.py", line 2190, in wsgi_app
response = self.full_dispatch_request()
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/site-packages/flask/app.py", line 1486, in full_dispatch_request
rv = self.handle_user_exception(e)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/site-packages/flask/app.py", line 1484, in full_dispatch_request
rv = self.dispatch_request()
^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/site-packages/flask/app.py", line 1469, in dispatch_request
return self.ensure_sync(self.view_functions[rule.endpoint])(**view_args)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/app/service/routes.py", line 102, in delete_promotion
if datetime.now() > promotion.expired:
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: can't compare datetime.datetime to datetime.date
Error in tests.test_routes.TestPromotionResourceModel.test_delete_promotion_success
File "/usr/local/lib/python3.11/unittest/case.py", line 57, in testPartExecutor
yield
File "/usr/local/lib/python3.11/unittest/case.py", line 623, in run
self._callTestMethod(testMethod)
File "/usr/local/lib/python3.11/unittest/case.py", line 579, in _callTestMethod
if method() is not None:
^^^^^^^^
File "/app/tests/test_routes.py", line 171, in test_delete_promotion_success
response = self.client.delete(f"/promotions/{promotion.id}")
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/site-packages/werkzeug/test.py", line 1257, in delete
return self.open(*args, **kw)
^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/site-packages/flask/testing.py", line 219, in open
response = super().open(
^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/site-packages/werkzeug/test.py", line 1196, in open
response = self.run_wsgi_app(request.environ, buffered=buffered)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/site-packages/werkzeug/test.py", line 1068, in run_wsgi_app
rv = run_wsgi_app(self.application, environ, buffered=buffered)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/site-packages/werkzeug/test.py", line 1344, in run_wsgi_app
app_rv = app(environ, start_response)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/site-packages/flask/app.py", line 2213, in __call__
return self.wsgi_app(environ, start_response)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/site-packages/flask/app.py", line 2193, in wsgi_app
response = self.handle_exception(e)
^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/site-packages/flask/app.py", line 2190, in wsgi_app
response = self.full_dispatch_request()
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/site-packages/flask/app.py", line 1486, in full_dispatch_request
rv = self.handle_user_exception(e)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/site-packages/flask/app.py", line 1484, in full_dispatch_request
rv = self.dispatch_request()
^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/site-packages/flask/app.py", line 1469, in dispatch_request
return self.ensure_sync(self.view_functions[rule.endpoint])(**view_args)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/app/service/routes.py", line 102, in delete_promotion
if datetime.now() > promotion.expired:
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: can't compare datetime.datetime to datetime.date
Error in tests.test_routes.TestPromotionResourceModel.test_unsupported_media_type
File "/usr/local/lib/python3.11/unittest/case.py", line 57, in testPartExecutor
yield
File "/usr/local/lib/python3.11/unittest/case.py", line 623, in run
self._callTestMethod(testMethod)
File "/usr/local/lib/python3.11/unittest/case.py", line 579, in _callTestMethod
if method() is not None:
^^^^^^^^
File "/app/tests/test_routes.py", line 144, in test_unsupported_media_type
response = self.client.put(
^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/site-packages/werkzeug/test.py", line 1252, in put
return self.open(*args, **kw)
^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/site-packages/flask/testing.py", line 219, in open
response = super().open(
^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/site-packages/werkzeug/test.py", line 1196, in open
response = self.run_wsgi_app(request.environ, buffered=buffered)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/site-packages/werkzeug/test.py", line 1068, in run_wsgi_app
rv = run_wsgi_app(self.application, environ, buffered=buffered)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/site-packages/werkzeug/test.py", line 1344, in run_wsgi_app
app_rv = app(environ, start_response)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/site-packages/flask/app.py", line 2213, in __call__
return self.wsgi_app(environ, start_response)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/site-packages/flask/app.py", line 2193, in wsgi_app
response = self.handle_exception(e)
^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/site-packages/flask/app.py", line 2190, in wsgi_app
response = self.full_dispatch_request()
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/site-packages/flask/app.py", line 1486, in full_dispatch_request
rv = self.handle_user_exception(e)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/site-packages/flask/app.py", line 1484, in full_dispatch_request
rv = self.dispatch_request()
^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/site-packages/flask/app.py", line 1469, in dispatch_request
return self.ensure_sync(self.view_functions[rule.endpoint])(**view_args)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/app/service/routes.py", line 132, in update_promotion
if datetime.now() > promotion.expired:
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: can't compare datetime.datetime to datetime.date
Error in tests.test_routes.TestPromotionResourceModel.test_update_expired_promotion
File "/usr/local/lib/python3.11/unittest/case.py", line 57, in testPartExecutor
yield
File "/usr/local/lib/python3.11/unittest/case.py", line 623, in run
self._callTestMethod(testMethod)
File "/usr/local/lib/python3.11/unittest/case.py", line 579, in _callTestMethod
if method() is not None:
^^^^^^^^
File "/app/tests/test_routes.py", line 131, in test_update_expired_promotion
response = self.client.put(
^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/site-packages/werkzeug/test.py", line 1252, in put
return self.open(*args, **kw)
^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/site-packages/flask/testing.py", line 219, in open
response = super().open(
^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/site-packages/werkzeug/test.py", line 1196, in open
response = self.run_wsgi_app(request.environ, buffered=buffered)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/site-packages/werkzeug/test.py", line 1068, in run_wsgi_app
rv = run_wsgi_app(self.application, environ, buffered=buffered)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/site-packages/werkzeug/test.py", line 1344, in run_wsgi_app
app_rv = app(environ, start_response)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/site-packages/flask/app.py", line 2213, in __call__
return self.wsgi_app(environ, start_response)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/site-packages/flask/app.py", line 2193, in wsgi_app
response = self.handle_exception(e)
^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/site-packages/flask/app.py", line 2190, in wsgi_app
response = self.full_dispatch_request()
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/site-packages/flask/app.py", line 1486, in full_dispatch_request
rv = self.handle_user_exception(e)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/site-packages/flask/app.py", line 1484, in full_dispatch_request
rv = self.dispatch_request()
^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/site-packages/flask/app.py", line 1469, in dispatch_request
return self.ensure_sync(self.view_functions[rule.endpoint])(**view_args)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/app/service/routes.py", line 132, in update_promotion
if datetime.now() > promotion.expired:
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: can't compare datetime.datetime to datetime.date
Error in tests.test_routes.TestPromotionResourceModel.test_update_valid_promotion
File "/usr/local/lib/python3.11/unittest/case.py", line 57, in testPartExecutor
yield
File "/usr/local/lib/python3.11/unittest/case.py", line 623, in run
self._callTestMethod(testMethod)
File "/usr/local/lib/python3.11/unittest/case.py", line 579, in _callTestMethod
if method() is not None:
^^^^^^^^
File "/app/tests/test_routes.py", line 98, in test_update_valid_promotion
response = self.client.put(
^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/site-packages/werkzeug/test.py", line 1252, in put
return self.open(*args, **kw)
^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/site-packages/flask/testing.py", line 219, in open
response = super().open(
^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/site-packages/werkzeug/test.py", line 1196, in open
response = self.run_wsgi_app(request.environ, buffered=buffered)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/site-packages/werkzeug/test.py", line 1068, in run_wsgi_app
rv = run_wsgi_app(self.application, environ, buffered=buffered)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/site-packages/werkzeug/test.py", line 1344, in run_wsgi_app
app_rv = app(environ, start_response)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/site-packages/flask/app.py", line 2213, in __call__
return self.wsgi_app(environ, start_response)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/site-packages/flask/app.py", line 2193, in wsgi_app
response = self.handle_exception(e)
^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/site-packages/flask/app.py", line 2190, in wsgi_app
response = self.full_dispatch_request()
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/site-packages/flask/app.py", line 1486, in full_dispatch_request
rv = self.handle_user_exception(e)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/site-packages/flask/app.py", line 1484, in full_dispatch_request
rv = self.dispatch_request()
^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/site-packages/flask/app.py", line 1469, in dispatch_request
return self.ensure_sync(self.view_functions[rule.endpoint])(**view_args)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/app/service/routes.py", line 132, in update_promotion
if datetime.now() > promotion.expired:
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: can't compare datetime.datetime to datetime.date
Describe the bug There are six errors and two failures in unit test for the new datetime data format due to type mismatch.
To Reproduce Steps to reproduce the behavior: run 'green' unit test
Expected behavior OK (passes=47)
Observed behavior When running 'green'
Screenshots If applicable, add screenshots to help explain your problem.
Additional context