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
Updated tests for esquery.py #64
Conversation
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.
@aswanipranjal did you notice that tests are failing? Could you please have a look at the Travis output, and try to fix them?
3cb2503
to
f376a3f
Compare
The problem with the test is that json.loads can extract the list in the dictionary in any order, which makes the test fail. I suggest that you write a simple auxiliary function to order the list (say, alphabetic order), and just apply it to the lists after json.loads... (of course, |
ed5109a
to
59988d4
Compare
@jgbarah please review. |
manuscripts/esquery.py
Outdated
@@ -64,7 +69,7 @@ def __get_query_filters(cls, filters={}, inverse=False): | |||
# trying to use es_dsl only and not creating hard coded queries | |||
query_filters.append(Q('match_phrase', **params)) | |||
|
|||
return query_filters | |||
return sorted(query_filters, key=lambda x: sort_order(x)) |
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 think it is better to do this in tests, instead of here. The main reason is performance (this is not really needed when working as usual, but the performance penalty of ordering will be paid every time you query), but also that the code does not ready this added complexity: tests do need, but not this code....
59988d4
to
76b718c
Compare
I changed the tests to sort the list only during the tests and not other wise in esquery.py The reason the tests are failing is this:
takes in a dictionary containing the filters to be applied to the Search object and returns a list of elasticsearch_dsl Query object (the filters were converted to these Query objects). But when this function is called internally (in esquery.py) in __get_query_basic, then there is no way that we can sort this list externally, and for testing the We will have to apply the sorting function in The same thing happens in |
Divided test_get_query_agg_ts and test_get_query_basic into 2 parts Sorting the list generated by get_query_filters to pass the tests
76b718c
to
02c151d
Compare
@jgbarah I was using self.filters as an |
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 for the changes!
Divided test_get_query_agg_ts and test_get_query_basic into 2 parts in test_esquery.py.
The tests might fail because they were changed in #63.