-
-
Notifications
You must be signed in to change notification settings - Fork 57
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
Issue #533: Implement API get_vocabulary & get_vocabularies_name #557
Issue #533: Implement API get_vocabulary & get_vocabularies_name #557
Conversation
@ujsquared thanks for creating this Pull Request and helping to improve Plone! TL;DR: Finish pushing changes, pass all other checks, then paste a comment:
To ensure that these changes do not break other parts of Plone, the Plone test suite matrix needs to pass, but it takes 30-60 min. Other CI checks are usually much faster and the Plone Jenkins resources are limited, so when done pushing changes and all other checks pass either start all Jenkins PR jobs yourself, or simply add the comment above in this PR to start all the jobs automatically. Happy hacking! |
@jenkins-plone-org please run jobs |
@ujsquared please edit the pull request description as described in Item 2, second bullet point, in https://6.docs.plone.org/contributing/first-time.html#create-a-pull-request-from-your-fork. |
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.
Docs look good to me. Minor changes requested to the change log. Thank you!
Needs technical review. Also where and when do we run and verify the doctests, that is, the lines of code with a leading %
in the docs?
Direct links to pull request preview:
- https://ploneapi--557.org.readthedocs.build/content.html#get-vocabulary
- https://ploneapi--557.org.readthedocs.build/content.html#get-all-vocabulary-names
- https://ploneapi--557.org.readthedocs.build/api/content.html#plone.api.content.get_vocabularies_names
- https://ploneapi--557.org.readthedocs.build/api/content.html#plone.api.content.get_vocabulary
Strange, we say to include doctests in https://6.docs.plone.org/plone.api/contribute.html#add-a-function-to-an-existing-module, but don't say how to actually run them or verify them in CI. What did I miss? As a quick hack, I added this to sphinx-build -b doctest -d _build/docs/doctrees docs _build/docs/doctest And running Doctest summary
===============
0 tests
0 failures in tests
0 failures in setup code
0 failures in cleanup code @ksuess do you have any idea? I recall you worked on this 2 or 3 years ago. |
I have no idea too, |
src/plone/api/content.py
Outdated
try: | ||
vocab = getUtility(IVocabularyFactory, name) | ||
except ComponentLookupError: | ||
raise InvalidParameterError(f"No vocabulary with name '{name}' available.") |
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.
Thanks a lot for your contribution!
It might be interesting to have an error message consistent with the one raised by the get_view
function:
plone.api/src/plone/api/content.py
Lines 534 to 554 in c9a35d7
except ComponentLookupError: | |
# Getting all available views | |
sm = getSiteManager() | |
available_views = sm.adapters.lookupAll( | |
required=(providedBy(context), providedBy(request)), | |
provided=Interface, | |
) | |
# Check if the requested view is available | |
# by getting the names of all available views | |
available_view_names = [view[0] for view in available_views] | |
if name not in available_view_names: | |
# Raise an error if the requested view is not available. | |
raise InvalidParameterError( | |
"Cannot find a view with name '{name}'.\n" | |
"Available views are:\n" | |
"{views}".format( | |
name=name, | |
views="\n".join(sorted(available_view_names)), | |
), | |
) |
What do you think?
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.
Agreed. Making the changes.
src/plone/api/content.py
Outdated
:return: A list of vocabularies names. | ||
""" | ||
all_vocabs = getUtilitiesFor(IVocabularyFactory) | ||
return [v[0] for v in all_vocabs] |
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.
What do you think about:
return [v[0] for v in all_vocabs] | |
return sorted([name for name, vocabulary in getUtilitiesFor(IVocabularyFactory)]) |
?
src/plone/api/tests/test_content.py
Outdated
self.assertTrue(vocab) | ||
self.assertTrue(hasattr(vocab, "__iter__")) # Verify it's iterable |
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.
I would replace these lines with a self.assertIsInstance
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.
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.
Nope, sorry. I was referring to something like:
self.assertTrue(vocab) | |
self.assertTrue(hasattr(vocab, "__iter__")) # Verify it's iterable | |
self.assertIsInstance(vocabulary, SimpleVocabulary) |
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.
Great work!
Thanks for your contribution.
I added some suggestion.
I would not be cheap with variable names.
I would replace vocab
with vocabulary
and vocabs
with vocabularies
.
Well, yes, the "contributing" chapter lacks the mentioning of |
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.
Thanks a lot for your contribution! Awesome.
I think, as most of the vocabularies are not context sensitive, these two new methods would fit better in api.portal
than in api.content
src/plone/api/tests/test_content.py
Outdated
self.assertIn("private", states) | ||
self.assertIn("published", states) | ||
|
||
def test_vocabulary_context_sensitivity(self): |
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.
This test on context sensitivity would need a vocabulary that is context sensitive to be meaningful.
I would say this test is not really needed, as the new plone.api method api.content.get_vocabulary
is simply calling getUtility(IVocabularyFactory, name)
and applying this vocabulary to the context. So the underlying code is testing the context sensitivity already.
Further opinions are welcome.
src/plone/api/tests/test_portal.py
Outdated
vocabulary = portal.get_vocabulary(name="plone.app.vocabularies.PortalTypes") | ||
self.assertIsInstance( | ||
vocabulary, SimpleVocabulary | ||
) # Check for correct interface |
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.
this tests on being vocabulary an instance of a class. The comment is not correct. Better no comment.
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.
Earlier, I was testing for IVocabularyTokenized interface. Missed updating the comment
@jenkins-plone-org please run jobs |
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.
Looks good to me. Well done, @ujsquared.
The failing test is unrelated.
I approve.
@ksuess I am not really sure about that. Maybe some other people might share their feelings about where these helpers should go. CC @plone/framework-team |
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.
This looks fine to me.
Please wait the other reviewers approval before merging.
as suggested by @ale-rt Co-authored-by: Alessandro Pisa <[email protected]>
@jenkins-plone-org please run jobs |
@stevepiercy I am merging this, I hope you are fine with that. |
@ale-rt please wait for me to complete my review. There is no rush. |
@ksuess I don't see how |
Tests in doctests/*.md, both code snippets and invisible code blocks, are tested in https://github.com/plone/plone.api/blob/main/src/plone/api/tests/test_doctests.py. It uses manuel TestSuite. |
To verify, I altered one of the doctests in However, when I change a doctest in % self.assertEqual(user.getProperty('email'), '[email protected]')
So maybe the test itself does not get called? Ah, there is a missing symlink for |
Yes, it would make sense to test the example tests. Would you be so kind to add a symlink in tests/doctests? Thank you! |
@stevepiercy @ksuess Done in 3d1ae92 |
…ssue-533-add-get-vocabulary
…squared/plone.api into issue-533-add-get-vocabulary
- Align label and target with heading - Use `{func}` for function
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.
This looks great! Let's merge when green.
@jenkins-plone-org please run jobs |
Co-authored-by: Alessandro Pisa <[email protected]>
@jenkins-plone-org please run jobs |
Looks like Jenkins does not like some tests. What should we do? |
And now they're all green. |
Fixes Issue #533
📚 Documentation preview 📚: https://ploneapi--557.org.readthedocs.build/