|
66 | 66 | from test.factories import UserFactory, CategoryFactory, ProjectFactory |
67 | 67 | from test.test_api import TestAPI |
68 | 68 | from pybossa.core import project_repo |
| 69 | +from pybossa.messages import DEPRECATED_PRODUCT_SUBPRODUCT_WARNING |
69 | 70 |
|
70 | 71 |
|
71 | 72 | class TestProjectWarningsAPI(TestAPI): |
72 | 73 | """Test Project API warnings functionality.""" |
73 | 74 |
|
74 | | - DEPRECATED_PRODUCT_SUBPRODUCT_WARNING_MESSAGE = ('Combination of selected Product and Subproduct has been deprecated ' |
75 | | - 'and will be removed in future. Refer to GIGwork documentation for ' |
76 | | - 'taxonomy updates.') |
77 | | - |
78 | 75 | @with_context |
79 | 76 | def test_post_valid_product_with_deprecated_subproduct_shows_warning(self): |
80 | 77 | """Test POST with valid product but deprecated subproduct shows warning.""" |
@@ -119,7 +116,7 @@ def test_post_valid_product_with_deprecated_subproduct_shows_warning(self): |
119 | 116 | # Verify warning is present when using valid product with deprecated subproduct |
120 | 117 | assert 'warnings' in response_data |
121 | 118 | assert len(response_data['warnings']) == 1 |
122 | | - assert self.DEPRECATED_PRODUCT_SUBPRODUCT_WARNING_MESSAGE == response_data['warnings'][0] |
| 119 | + assert DEPRECATED_PRODUCT_SUBPRODUCT_WARNING == response_data['warnings'][0] |
123 | 120 |
|
124 | 121 | # Verify project was saved to database |
125 | 122 | project = project_repo.get(response_data['id']) |
@@ -227,7 +224,7 @@ def test_post_deprecated_product_with_subproduct_shows_warning(self): |
227 | 224 | # Verify warning is present when using deprecated product |
228 | 225 | assert 'warnings' in response_data |
229 | 226 | assert len(response_data['warnings']) == 1 |
230 | | - assert self.DEPRECATED_PRODUCT_SUBPRODUCT_WARNING_MESSAGE == response_data['warnings'][0] |
| 227 | + assert DEPRECATED_PRODUCT_SUBPRODUCT_WARNING == response_data['warnings'][0] |
231 | 228 |
|
232 | 229 | # Verify project was saved to database |
233 | 230 | project = project_repo.get(response_data['id']) |
@@ -353,7 +350,7 @@ def test_put_valid_product_with_deprecated_subproduct_shows_warning(self): |
353 | 350 | # Verify warning is present when using valid product with deprecated subproduct |
354 | 351 | assert 'warnings' in response_data |
355 | 352 | assert len(response_data['warnings']) == 1 |
356 | | - assert self.DEPRECATED_PRODUCT_SUBPRODUCT_WARNING_MESSAGE == response_data['warnings'][0] |
| 353 | + assert DEPRECATED_PRODUCT_SUBPRODUCT_WARNING == response_data['warnings'][0] |
357 | 354 |
|
358 | 355 | # Verify project was updated in database |
359 | 356 | updated_project = project_repo.get(project.id) |
@@ -416,7 +413,7 @@ def test_put_deprecated_product_with_subproduct_shows_warning(self): |
416 | 413 | # Verify warning is present when using deprecated product |
417 | 414 | assert 'warnings' in response_data |
418 | 415 | assert len(response_data['warnings']) == 1 |
419 | | - assert self.DEPRECATED_PRODUCT_SUBPRODUCT_WARNING_MESSAGE == response_data['warnings'][0] |
| 416 | + assert DEPRECATED_PRODUCT_SUBPRODUCT_WARNING == response_data['warnings'][0] |
420 | 417 |
|
421 | 418 | # Verify project was updated in database |
422 | 419 | updated_project = project_repo.get(project.id) |
@@ -496,7 +493,7 @@ def test_project_warnings_not_persisted_after_multiple_operations(self): |
496 | 493 |
|
497 | 494 | # Verify PUT response has different warnings |
498 | 495 | assert 'warnings' in put_response |
499 | | - assert self.DEPRECATED_PRODUCT_SUBPRODUCT_WARNING_MESSAGE in put_response['warnings'] |
| 496 | + assert DEPRECATED_PRODUCT_SUBPRODUCT_WARNING in put_response['warnings'] |
500 | 497 |
|
501 | 498 | # Check database after PUT |
502 | 499 | project = project_repo.get(project_id) |
@@ -579,7 +576,7 @@ def test_customize_response_dict_handles_warnings_dynamically(self): |
579 | 576 | # Should generate warnings dynamically |
580 | 577 | assert 'warnings' in result |
581 | 578 | assert len(result['warnings']) == 1 |
582 | | - assert self.DEPRECATED_PRODUCT_SUBPRODUCT_WARNING_MESSAGE == result['warnings'][0] |
| 579 | + assert DEPRECATED_PRODUCT_SUBPRODUCT_WARNING == result['warnings'][0] |
583 | 580 |
|
584 | 581 | # Other fields should remain unchanged |
585 | 582 | assert result['id'] == 1 |
@@ -708,7 +705,7 @@ def test_warnings_survive_api_base_response_processing(self): |
708 | 705 | # Verify warnings are properly formatted |
709 | 706 | assert isinstance(response_data['warnings'], list) |
710 | 707 | assert len(response_data['warnings']) == 1 |
711 | | - assert self.DEPRECATED_PRODUCT_SUBPRODUCT_WARNING_MESSAGE == response_data['warnings'][0] |
| 708 | + assert DEPRECATED_PRODUCT_SUBPRODUCT_WARNING == response_data['warnings'][0] |
712 | 709 |
|
713 | 710 | # Verify info field integrity |
714 | 711 | assert response_data['info']['product'] == 'Old Product' |
@@ -763,7 +760,7 @@ def test_post_invalid_product_raises_bad_request_no_warnings(self): |
763 | 760 | url = '/api/project?api_key=%s' % user.api_key |
764 | 761 | res = self.app.post(url, data=json.dumps(project_data)) |
765 | 762 |
|
766 | | - # Should fail with 400 error due to ValueError during response generation |
| 763 | + # Should fail with 400 error when product/subproduct value is validated at repository layer |
767 | 764 | assert res.status_code == 400, res.data |
768 | 765 | response_data = json.loads(res.data) |
769 | 766 | assert 'exception_msg' in response_data |
@@ -808,7 +805,7 @@ def test_post_invalid_subproduct_raises_bad_request_no_warnings(self): |
808 | 805 | url = '/api/project?api_key=%s' % user.api_key |
809 | 806 | res = self.app.post(url, data=json.dumps(project_data)) |
810 | 807 |
|
811 | | - # Should fail with 400 error due to ValueError during response generation |
| 808 | + # Should fail with 400 error when product/subproduct value is validated at repository layer |
812 | 809 | assert res.status_code == 400, res.data |
813 | 810 | response_data = json.loads(res.data) |
814 | 811 | assert 'exception_msg' in response_data |
@@ -861,11 +858,12 @@ def test_put_invalid_product_raises_bad_request_no_warnings(self): |
861 | 858 | url = '/api/project/%s?api_key=%s' % (project.id, user.api_key) |
862 | 859 | res = self.app.put(url, data=json.dumps(update_data)) |
863 | 860 |
|
864 | | - # Should fail with 400 error due to ValueError during response generation |
| 861 | + # Should fail with 400 error when product/subproduct value is validated at repository layer |
865 | 862 | assert res.status_code == 400, res.data |
866 | 863 | response_data = json.loads(res.data) |
867 | 864 | assert 'exception_msg' in response_data |
868 | 865 | assert 'Invalid product' in response_data['exception_msg'] |
| 866 | + # check that invalid product is caught before warning generation check |
869 | 867 | assert 'warnings' not in response_data |
870 | 868 |
|
871 | 869 | @with_context |
@@ -913,10 +911,11 @@ def test_put_invalid_subproduct_raises_bad_request_no_warnings(self): |
913 | 911 | url = '/api/project/%s?api_key=%s' % (project.id, user.api_key) |
914 | 912 | res = self.app.put(url, data=json.dumps(update_data)) |
915 | 913 |
|
916 | | - # Should fail with 400 error due to ValueError during response generation |
| 914 | + # Should fail with 400 error when product/subproduct value is validated at repository layer |
917 | 915 | assert res.status_code == 400, res.data |
918 | 916 | response_data = json.loads(res.data) |
919 | 917 | assert 'exception_msg' in response_data |
920 | 918 | assert 'Invalid subproduct' in response_data['exception_msg'] |
| 919 | + # check that invalid subproduct is caught before warning generation check |
921 | 920 | assert 'warnings' not in response_data |
922 | 921 |
|
0 commit comments