Skip to content

Filter endpoint tests, unittest asserts, pylint cleanups (Closes #45) #60

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

Merged
merged 2 commits into from
Nov 14, 2020

Conversation

cdhorn
Copy link
Collaborator

@cdhorn cdhorn commented Nov 6, 2020

@DavidMStraub this actually touches things in five areas, which I know you won't be thrilled about, but I just struggled with doing things one way for test_filters.py and not fixing the other test cases I put together to be conformant.

  1. Changes /api/filters endpoint so delete now follows the more standard convention of having the item in the path as well as tweaks the two query parms on a get and apispec.yaml update.

  2. The remainder of the /api/filters tests in test_filters.py. Those cover create / update / apply / delete of a custom filter for each endpoint.

  3. It replaces all of the plain asserts in the test_endpoints modules with the more specific unittest ones like assertEqual, assertTrue, and assertIn which I realized I really should have done from the start.

  4. It renames rv to result in all the test_endpoints modules along with other changes to try to appease pylint as best I could.

  5. It includes two changes to .pylintrc that I had to make as it refused to run at all on my machine. The first removes the duplicate [MESSAGES CONTROL] section at the bottom and the second changes fail-under=10.0 to fail-under=10 as pylint wanted it to be an integer. I am unsure on this one, it clearly must be working on your system. I'm using 2.6.0.

Sorry again for the size. I know you are working on test cases too and may be some collision there. So if you're stuff is ready to merge maybe do that first and I can rebase and revise this. Let me know your thoughts.

@DavidMStraub
Copy link
Member

It replaces all of the plain asserts in the test_endpoints modules with the more specific unittest ones like assertEqual, assertTrue, and assertIn which I realized I really should have done from the start.

Well, assert is the pytest way of doing things, so as long as we use pytest I think it's fine both ways.

I know Gramps uses only unittest, but it actually still uses python setup.py test, which is officially deprecated.

Running plain unittest is much less useful/powerful for debugging compared to pytest in my view. And the alternatives to pytest like nose and nose2 look pretty much abandoned.

But it's true that pytest has a quite opinionated way of writing tests, so maybe the best approach is to keep them unittest compatible and use pytest only as a test runner.

@@ -74,6 +78,8 @@ def get_custom_filters(args: Dict[str, str], namespace: str) -> List[Dict]:
],
}
)
if "filters" in args and len(args["filters"]) != len(filter_list):
abort(404)
Copy link
Member

Choose a reason for hiding this comment

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

Why 404 and not 400, isn't this an invalid request?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

My thinking is that it did not find all the filters in the list because one was missing, and we would provide 404 for a missing object. I did the same for rules just above and do the same below in build filter.

Copy link
Member

Choose a reason for hiding this comment

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

Ok.

@@ -68,7 +68,8 @@ def register_endpt(resource: Type[Resource], url: str, name: str):
register_endpt(BookmarkResource, "/bookmarks/<string:namespace>", "bookmark")
register_endpt(BookmarksResource, "/bookmarks/", "bookmarks")
# Filter
register_endpt(FilterResource, "/filters/<string:namespace>", "filter")
register_endpt(FilterResource, "/filters/<string:namespace>/<string:name>", "filter")
register_endpt(FilterResource, "/filters/<string:namespace>", "filters")
Copy link
Member

Choose a reason for hiding this comment

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

So now you have multiple endpoints for the same resource class and the different verbs will have different number of arguments. Does that work? What if I send a GET request to /filters/namespace? Won't that cause a 500 server error? Don't you have do define name as a keyword argument (with default value) on all the verbs' methods? And return 405 if it's set on the wrong method?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Oh yeah, you're right, I'm not handling that right. I will fix that up, thanks!

Copy link
Collaborator Author

@cdhorn cdhorn Nov 7, 2020

Choose a reason for hiding this comment

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

Rebased as well. I think that is a bit better now. Boy I miss the obvious sometimes.

@cdhorn
Copy link
Collaborator Author

cdhorn commented Nov 7, 2020

Well, assert is the pytest way of doing things, so as long as we use pytest I think it's fine both ways.

Yeah, this is my first real experience writing extensive test cases so I don't really know the pros and cons of each framework and approach. I'm hoping what I did for the test cases overall is okay, it made sense to me but you are far more experienced than I.

@cdhorn
Copy link
Collaborator Author

cdhorn commented Nov 12, 2020

If this looks okay now could you consider merging it so I can rebase the others? Or merge one of the others so I can rebase what is left? Or do you want me to combine a couple of them?

@jralls
Copy link
Member

jralls commented Nov 12, 2020

I am unalterably and intensely opposed to having anything even vaguely resembling a web API in GnuCash, and even more opposed to one written by the Guile developers. That is a security hole so huge that no responsible development team without the requisite time and skills could foist upon its users.

If you want to support such a thing then write it as a plugin and host it yourself.

@cdhorn
Copy link
Collaborator Author

cdhorn commented Nov 12, 2020

I am unalterably and intensely opposed to having anything even vaguely resembling a web API in GnuCash, and even more opposed to one written by the Guile developers. That is a security hole so huge that no responsible development team without the requisite time and skills could foist upon its users.

Hi John, I am a little confused by this statement, what does GnuCash have to do with Gramps? Did you mean to say you are opposed to a REST API for Gramps?

@jralls
Copy link
Member

jralls commented Nov 12, 2020

I'm very sorry, I confused this PR with a GnuCash one also by someone named Christopher who has a habit of proclaiming his PRs ready to merge when they aren't. Please disregard the noise.

@DavidMStraub
Copy link
Member

Let's merge this before more opposition arises 😉

@DavidMStraub DavidMStraub merged commit b1f455d into gramps-project:master Nov 14, 2020
@cdhorn cdhorn deleted the filter-tests branch November 14, 2020 18:51
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