-
Notifications
You must be signed in to change notification settings - Fork 0
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
Story 10: Content trigger #50
Conversation
Pull Request Test Coverage Report for Build 246
💛 - Coveralls |
…ive/collective.ifttt into story-10-content-trigger
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Shriyanshagro Now that you implemented rule creation code inside the form view class, how about refactoring those methods into a standalone functions? (The current implementation is not wrong, but refactoring would be just evolution for it.)
That might feel like significant amount of work, because you could no longer use self.something
variables from the form view instance, but you should pass rule context, request and parameters as function arguments.
On the other hand, the resulting code would be easier to reuse, less magical and maybe also easier to test with smaller tests.
So, in practice, methods like self.add_rule
, self.delete_rule
etc should be moved to some "library module", eg. utils.py
as collective.ifttt.utils
.
@datakurre Sure, I'll look into those code fragments. I'm not sure but seems like with this code refactoring, I should also bring in implementation for story 11 and 12. This would help me while refactoring. |
79d23d5
to
228bb89
Compare
@Shriyanshagro Regarding some of the currently failing tests, it's good to know that the Plone site id in plone test setup is I recall, that name is available for import as a string variable at
that detail is described here https://pypi.org/project/plone.app.testing/ |
And I trigger the 'Add IFTTT Content Trigger' action menu item | ||
When I fill Content Trigger form | ||
Then I see ' Successfully applied the IFTTT event test_event to Plone site' on success | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Shriyanshagro Please,
- fix indentation in these scenarios and keywords; indent by 4 spaces
- why there is leading space in ' Successfully ...'
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- the current branch contains unnecessary empty file
src/collective/ifttt/tests/test_content_trigger.py
src/collective/ifttt/utils.py
Outdated
) | ||
|
||
# HACK | ||
adding = self.context.restrictedTraverse('/Plone/+rule') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Shriyanshagro You cannot assume that the portal root name is Plone
.
You can get the portal object
portal = api.portal.get()
adding = portal.restrictedTraverse('+rule')
But possibly that is also available through adapter lookup (faster)
adding = getMultiAdapter((portal, self.request), name='+rule')
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Later you use multiadapter lookups, so it is also the right solution here.
This is probably also the reason why acceptance tests fail.
@Shriyanshagro Tests seem to be passing, but there is minor QA issue preventing this to be green
|
src/collective/ifttt/utils.py
Outdated
@@ -84,7 +87,8 @@ def configure_rule(self, data): | |||
self.rule_id = storage.values()[-1].id | |||
|
|||
# traverse to configuration page of content rule | |||
rule_url = '/Plone/' + self.rule_id | |||
portal = api.portal.get().__name__ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Interesting that you found __name__
for api.portal.get().__name__
. More usual one found in existing code is api.portal.get().getId()
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Minor fix: do not use os.sep
when joining web paths. It is \
on windows.
src/collective/ifttt/utils.py
Outdated
@@ -84,7 +87,8 @@ def configure_rule(self, data): | |||
self.rule_id = storage.values()[-1].id | |||
|
|||
# traverse to configuration page of content rule | |||
rule_url = '/Plone/' + self.rule_id | |||
portal = api.portal.get().__name__ | |||
rule_url = (os.sep).join(('', portal, self.rule_id)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
os.sep
is no no for web paths. Nowadays it is theoretical that someone runs Plone on Windows, but if one does, os.sep
is ’\
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Web is standard, so it should be safe to do '/'.join()
.
If you want to use a helper, you could use
from posixpath import join as urljoin
c = urljoin(a, b)
as in https://stackoverflow.com/a/15279799
It uses /
as separator on every OS.
bf74cb8
to
390da8d
Compare
390da8d
to
cb9d181
Compare
Related to #25 and in continuation to #47