Skip to content

Commit 500ab72

Browse files
author
schen1870
committed
address PR comments
1 parent b1f4539 commit 500ab72

File tree

4 files changed

+23
-24
lines changed

4 files changed

+23
-24
lines changed

pybossa/api/project.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
from pybossa.util import is_reserved_name, description_from_long_description, validate_ownership_id
3434
from pybossa.core import auditlog_repo, result_repo, http_signer
3535
from pybossa.auditlogger import AuditLogger
36+
from pybossa.messages import DEPRECATED_PRODUCT_SUBPRODUCT_WARNING
3637
from pybossa.data_access import ensure_user_assignment_to_project, set_default_amp_store
3738
from sqlalchemy.orm.base import _entity_descriptor
3839
from pybossa.cache import delete_memoized
@@ -262,10 +263,6 @@ def _generate_product_subproduct_warnings(self, product, subproduct):
262263
warnings = []
263264

264265
if product and self._is_product_or_subproduct_deprecated(product, subproduct):
265-
warnings.append(
266-
'Combination of selected Product and Subproduct has been deprecated '
267-
'and will be removed in future. Refer to GIGwork documentation for '
268-
'taxonomy updates.'
269-
)
266+
warnings.append(DEPRECATED_PRODUCT_SUBPRODUCT_WARNING)
270267

271268
return warnings

pybossa/messages.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,8 @@
3434
from werkzeug.exceptions import NotFound, BadRequest
3535

3636
__all__ = ['SUCCESS', 'ERROR', 'WARNING', 'FORBIDDEN', 'NOTFOUND', 'BADREQUEST',
37-
'INFO', 'FAILED', 'NOTFOUND', 'INTERNALSERVERERROR', 'UNAUTHORIZED', 'LOCKED']
37+
'INFO', 'FAILED', 'NOTFOUND', 'INTERNALSERVERERROR', 'UNAUTHORIZED', 'LOCKED',
38+
'DEPRECATED_PRODUCT_SUBPRODUCT_WARNING']
3839

3940
SUCCESS = "success"
4041

@@ -58,6 +59,10 @@
5859

5960
UNAUTHORIZED = Unauthorized.description
6061

62+
DEPRECATED_PRODUCT_SUBPRODUCT_WARNING = ('This combination of selected Product and Subproduct has been deprecated '
63+
'and will be removed in future. Refer to GIGwork documentation for '
64+
'taxonomy updates.')
65+
6166
assert SUCCESS
6267
assert ERROR
6368
assert WARNING

pybossa/view/projects.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@
8383
from pybossa.forms.admin_view_forms import SearchForm
8484
from pybossa.importers import BulkImportException
8585
from pybossa.pro_features import ProFeatureHandler
86+
from pybossa.messages import DEPRECATED_PRODUCT_SUBPRODUCT_WARNING
8687

8788
from pybossa.core import (project_repo, user_repo, task_repo, blog_repo,
8889
result_repo, webhook_repo, auditlog_repo,
@@ -114,9 +115,6 @@
114115

115116
cors_headers = ['Content-Type', 'Authorization']
116117

117-
# Warning message for deprecated products/subproducts
118-
DEPRECATED_PRODUCT_SUBPRODUCT_WARNING = 'Combination of selected Product and Subproduct has been deprecated and will be removed in future. Refer to GIGwork documentation for taxonomy updates.'
119-
120118
blueprint = Blueprint('project', __name__)
121119
blueprint_projectid = Blueprint('projectid', __name__)
122120

test/test_api/test_project_warnings_api.py

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -66,15 +66,12 @@
6666
from test.factories import UserFactory, CategoryFactory, ProjectFactory
6767
from test.test_api import TestAPI
6868
from pybossa.core import project_repo
69+
from pybossa.messages import DEPRECATED_PRODUCT_SUBPRODUCT_WARNING
6970

7071

7172
class TestProjectWarningsAPI(TestAPI):
7273
"""Test Project API warnings functionality."""
7374

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-
7875
@with_context
7976
def test_post_valid_product_with_deprecated_subproduct_shows_warning(self):
8077
"""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):
119116
# Verify warning is present when using valid product with deprecated subproduct
120117
assert 'warnings' in response_data
121118
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]
123120

124121
# Verify project was saved to database
125122
project = project_repo.get(response_data['id'])
@@ -227,7 +224,7 @@ def test_post_deprecated_product_with_subproduct_shows_warning(self):
227224
# Verify warning is present when using deprecated product
228225
assert 'warnings' in response_data
229226
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]
231228

232229
# Verify project was saved to database
233230
project = project_repo.get(response_data['id'])
@@ -353,7 +350,7 @@ def test_put_valid_product_with_deprecated_subproduct_shows_warning(self):
353350
# Verify warning is present when using valid product with deprecated subproduct
354351
assert 'warnings' in response_data
355352
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]
357354

358355
# Verify project was updated in database
359356
updated_project = project_repo.get(project.id)
@@ -416,7 +413,7 @@ def test_put_deprecated_product_with_subproduct_shows_warning(self):
416413
# Verify warning is present when using deprecated product
417414
assert 'warnings' in response_data
418415
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]
420417

421418
# Verify project was updated in database
422419
updated_project = project_repo.get(project.id)
@@ -496,7 +493,7 @@ def test_project_warnings_not_persisted_after_multiple_operations(self):
496493

497494
# Verify PUT response has different warnings
498495
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']
500497

501498
# Check database after PUT
502499
project = project_repo.get(project_id)
@@ -579,7 +576,7 @@ def test_customize_response_dict_handles_warnings_dynamically(self):
579576
# Should generate warnings dynamically
580577
assert 'warnings' in result
581578
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]
583580

584581
# Other fields should remain unchanged
585582
assert result['id'] == 1
@@ -708,7 +705,7 @@ def test_warnings_survive_api_base_response_processing(self):
708705
# Verify warnings are properly formatted
709706
assert isinstance(response_data['warnings'], list)
710707
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]
712709

713710
# Verify info field integrity
714711
assert response_data['info']['product'] == 'Old Product'
@@ -763,7 +760,7 @@ def test_post_invalid_product_raises_bad_request_no_warnings(self):
763760
url = '/api/project?api_key=%s' % user.api_key
764761
res = self.app.post(url, data=json.dumps(project_data))
765762

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
767764
assert res.status_code == 400, res.data
768765
response_data = json.loads(res.data)
769766
assert 'exception_msg' in response_data
@@ -808,7 +805,7 @@ def test_post_invalid_subproduct_raises_bad_request_no_warnings(self):
808805
url = '/api/project?api_key=%s' % user.api_key
809806
res = self.app.post(url, data=json.dumps(project_data))
810807

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
812809
assert res.status_code == 400, res.data
813810
response_data = json.loads(res.data)
814811
assert 'exception_msg' in response_data
@@ -861,11 +858,12 @@ def test_put_invalid_product_raises_bad_request_no_warnings(self):
861858
url = '/api/project/%s?api_key=%s' % (project.id, user.api_key)
862859
res = self.app.put(url, data=json.dumps(update_data))
863860

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
865862
assert res.status_code == 400, res.data
866863
response_data = json.loads(res.data)
867864
assert 'exception_msg' in response_data
868865
assert 'Invalid product' in response_data['exception_msg']
866+
# check that invalid product is caught before warning generation check
869867
assert 'warnings' not in response_data
870868

871869
@with_context
@@ -913,10 +911,11 @@ def test_put_invalid_subproduct_raises_bad_request_no_warnings(self):
913911
url = '/api/project/%s?api_key=%s' % (project.id, user.api_key)
914912
res = self.app.put(url, data=json.dumps(update_data))
915913

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
917915
assert res.status_code == 400, res.data
918916
response_data = json.loads(res.data)
919917
assert 'exception_msg' in response_data
920918
assert 'Invalid subproduct' in response_data['exception_msg']
919+
# check that invalid subproduct is caught before warning generation check
921920
assert 'warnings' not in response_data
922921

0 commit comments

Comments
 (0)