Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[api] /receive/{id}/ > /topology/{id}/receive/ #62 #79

Merged
merged 1 commit into from
Aug 14, 2020

Conversation

NoumbissiValere
Copy link
Contributor

Closed issue by renaming /receive/{id}/ to /topology/{id}/receive/
while ensuring backward compatibility with warnings.

Closes #62

@coveralls
Copy link

Coverage Status

Coverage increased (+0.005%) to 98.967% when pulling 4434b33 on issue-62-change-api into bcd2203 on master.

@coveralls
Copy link

coveralls commented Jul 31, 2020

Coverage Status

Coverage increased (+0.01%) to 98.973% when pulling c874632 on issue-62-change-api into dff2357 on master.

@@ -75,7 +75,15 @@ def post(self, request, pk, format=None):
'with message "%s"'
) % (topology.get_parser_display(), e.__class__.__name__, e)
return Response({'detail': error}, status=400)
return Response({'detail': _('data received successfully')})
success_message = 'data received successfully'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should be success_message = _('data received successfully').

The marking for translation must be done this way, I think otherwise the i18n system would not recognize which string to be made translatable.

warning = (
". But this url is deprecated and will soon be removed."
" We now use /topology/{id}/receive/"
)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please also log the warning:

logger = logging.getLogger(__name__)
logger.warning( ....... )

" We now use /topology/{id}/receive/"
)
return Response({'detail': (success_message + warning)})
return Response({'detail': _(success_message)})
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

again... do not repeat yourself.

if request.path == deprecated_url:
     success_message = success_message + warning
return Response({'detail': success_message})

if request.path == deprecated_url:
warning = (
". But this url is deprecated and will soon be removed."
" We now use /topology/{id}/receive/"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Simplify: "This URL is depercated and will be removed in future versions, use /topology/{id}/receive/".

Make translatable at the moment of defining it here as well.

warning = _('This URL is depercated and will be removed in future versions, use /topology/{id}/receive/')
success_message = '{success_message}. {warning}'

@NoumbissiValere NoumbissiValere force-pushed the issue-62-change-api branch 2 times, most recently from 3359292 to 1940f9c Compare July 31, 2020 22:41
)
logger.warning(warning)
success_message = f'{success_message}. {warning}'
return Response({'detail': _(success_message)})
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should be success_message instead of _(success_message) because it was already marked as translatable before

if request.path == deprecated_url:
warning = _(
"This URL is depercated and will be removed in "
"future versions, use /topology/{id}/receive/"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use single quotes for consistency

@NoumbissiValere NoumbissiValere force-pushed the issue-62-change-api branch 3 times, most recently from 6a8a2a3 to 8cc436c Compare August 1, 2020 00:27
Copy link
Member

@nemesifier nemesifier left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good progress, it works, but the URL shown in the UI needs to be updated so the new one is used:

Screenshot from 2020-08-04 21-49-36

if request.path == deprecated_url:
warning = _(
'This URL is depercated and will be removed in '
'future versions, use /topology/{id}/receive/'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this here should be /api/v1/topology/{id}/receive/

self.node_model.objects.all().delete()
data = self._load('static/netjson-1-link.json')
t = self.topology_model.objects.first()
path = f'/api/v1/receive/{t.pk}/?key=test'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please use reverse(), do not hardcode URLs

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@nemesisdesign since we have two urls mapping to same view (because we are supporting backward compatibility), reverse will get confused which url to use since both of them have the same view name.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@NoumbissiValere the solution is to change the old URL to have receive_topology_deprecated and use reverse here.

@NoumbissiValere NoumbissiValere force-pushed the issue-62-change-api branch 4 times, most recently from 5d26e53 to 1e34993 Compare August 11, 2020 23:04
@@ -269,6 +269,7 @@ def test_monitoring_integration(self, *args):
'openwisp_monitoring.device',
'openwisp_monitoring.check',
'openwisp_controller.connection',
'openwisp_notifications',
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this test was failing without this line

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please remove this and the other thing related to markdown, if there's an issue with this part it must be resolved in another patch, not in this one

@@ -2,3 +2,4 @@ coveralls
responses
freezegun
openwisp-utils[qa]~=0.5.1
markdown
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

needed by openwisp-notifications during testing

@@ -269,6 +269,7 @@ def test_monitoring_integration(self, *args):
'openwisp_monitoring.device',
'openwisp_monitoring.check',
'openwisp_controller.connection',
'openwisp_notifications',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please remove this and the other thing related to markdown, if there's an issue with this part it must be resolved in another patch, not in this one

self.node_model.objects.all().delete()
data = self._load('static/netjson-1-link.json')
t = self.topology_model.objects.first()
path = f'/api/v1/receive/{t.pk}/?key=test'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@NoumbissiValere the solution is to change the old URL to have receive_topology_deprecated and use reverse here.

@@ -75,7 +77,16 @@ def post(self, request, pk, format=None):
'with message "%s"'
) % (topology.get_parser_display(), e.__class__.__name__, e)
return Response({'detail': error}, status=400)
return Response({'detail': _('data received successfully')})
success_message = _('data received successfully')
deprecated_url = f'/api/v1/receive/{pk}/'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do not hardcode URLs, use reverse()

if request.path == deprecated_url:
warning = _(
'This URL is depercated and will be removed in '
'future versions, use /api/v1/topology/{id}/receive/'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do not hardcode URLs, use reverse()

Closed issue by renaming /receive/{id}/ to /topology/{id}/receive/
while ensuring backward compatibility with warnings.

Closes #62
@nemesifier nemesifier merged commit 8711a9b into master Aug 14, 2020
@nemesifier nemesifier deleted the issue-62-change-api branch August 14, 2020 21:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[api] /receive/{id}/ > /topology/{id}/receive/
3 participants