-
Notifications
You must be signed in to change notification settings - Fork 88
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
Make similarity client a stateful class #1432
base: master
Are you sure you want to change the base?
Conversation
I've updated this to create an instance of the similarity client for both the normal server and the indexing server. This removes the requirement to have separate methods for add/save. There are still some things that need to be improved:
I still need to test with a real running similarity server |
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.
It looks good to me, and the missing changes you mention also look reasonable. About testing (once we pass query params as dict instead of building URL manually), I guess we just need to do assert_called_with
and also check the params
dict. Or if requests
module has some method to "build URL" we could split the request in two parts, first build URL then call requests.get
and we could mock requests.get
. Doing a quick search I found you can do something like this:
requests.Request('GET', 'https://example.com/api', params=dict(param1='arg1',param2='arg2')).prepare().url
Maybe this would work. Use this first then mock requests.get
and do assert_called_with
with the full URL.
|
||
|
||
similarity_client = Similarity(settings.SIMILARITY_ADDRESS) | ||
indexing_similarity_client = Similarity(settings.INDEXING_SIMILARITY_ADDRESS) |
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.
cool, love that
yeah, I found the |
Hi @ffont, I can't remember why we never finished this work. Was it really just because I couldn't agree on how to construct the test URLs? If that's it, then I propose that we quickly fix this and merge it. I'll try and resolve the conflicts. |
Yeah, I guess that was it! Also similar thing should be done for tag recommendation, although I want to refactor it as a celery task and running on py3 so maybe there's no need to make this update now. |
Description
When I was looking at this similarity client for some gaia testing, I noticed that you can't have 2 clients, each pointing to a different host.
This change lets you pass in a host into the constructor.
There are still some changes to make - we need to read the settings file to get the host where this client is created.
I also changed to using requests, but we should improve the methods to pass GET args as a dict instead of constructing them manually.