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

Story 10: Content trigger #50

Merged
merged 17 commits into from
Jul 10, 2018
Merged

Story 10: Content trigger #50

merged 17 commits into from
Jul 10, 2018

Conversation

Shriyanshagro
Copy link
Collaborator

Related to #25 and in continuation to #47

@datakurre datakurre self-requested a review July 1, 2018 07:27
@coveralls
Copy link

coveralls commented Jul 1, 2018

Pull Request Test Coverage Report for Build 246

  • 67 of 77 (87.01%) changed or added relevant lines in 2 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage increased (+1.2%) to 90.0%

Changes Missing Coverage Covered Lines Changed/Added Lines %
src/collective/ifttt/utils.py 59 60 98.33%
src/collective/ifttt/browser/content_trigger.py 8 17 47.06%
Totals Coverage Status
Change from base Build 238: 1.2%
Covered Lines: 216
Relevant Lines: 240

💛 - Coveralls

Copy link
Collaborator

@datakurre datakurre left a 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.

@Shriyanshagro
Copy link
Collaborator Author

Shriyanshagro commented Jul 1, 2018

@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.

@datakurre
Copy link
Collaborator

@Shriyanshagro Regarding some of the currently failing tests, it's good to know that the Plone site id in plone test setup is plone in lowercase.

I recall, that name is available for import as a string variable at

from plone.app.testing.interfaces import PLONE_SITE_ID

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

Copy link
Collaborator

@datakurre datakurre Jul 6, 2018

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 ...'

Copy link
Collaborator

@datakurre datakurre Jul 6, 2018

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

)

# HACK
adding = self.context.restrictedTraverse('/Plone/+rule')
Copy link
Collaborator

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')

Copy link
Collaborator

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.

@datakurre
Copy link
Collaborator

@Shriyanshagro Tests seem to be passing, but there is minor QA issue preventing this to be green

/home/travis/build/collective/collective.ifttt/src/collective/ifttt/tests/test_utils.py:8:80: E501 line too long (86 > 79 characters)

@@ -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__
Copy link
Collaborator

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().

Copy link
Collaborator

@datakurre datakurre left a 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.

@@ -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))
Copy link
Collaborator

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 ’\.

Copy link
Collaborator

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.

@datakurre datakurre mentioned this pull request Jul 8, 2018
@datakurre datakurre merged commit 09929ad into master Jul 10, 2018
@datakurre datakurre deleted the story-10-content-trigger branch July 10, 2018 17:47
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.

3 participants