zoomus icon indicating copy to clipboard operation
zoomus copied to clipboard

added requests session to ApiClient

Open seantibor opened this issue 5 years ago • 10 comments

Fixes #62 by adding requests session to ApiClient utility instances. This may be a naive approach, so please let me know if we need additional changes to support this.

  • added session instance to ApiClient
  • replaced requests.<method> with self.session.<method> calls
  • updated mock patches to use util.requests.Session object patches in test_util.py

seantibor avatar Apr 19 '20 03:04 seantibor

@seantibor Thank you for your work! We just switched over to using the responses library for better and cleaner testing. I'm going to leave this PR open but, my guess is that when you merge develop in to your branch, this will no longer be relevant.

That being said thank you for your effort in trying to improve this library!

prschmid avatar Apr 23 '20 11:04 prschmid

I was able to accept all of the incoming changes from develop, particularly in test_util. The util.ApiClient uses a session object from requests now, which should save some resources and time when making large numbers of requests sequentially.

seantibor avatar Apr 25 '20 03:04 seantibor

Ok -- this should be working now. I've implemented the context manager methods, added tests for the context manager and methods, but I have not added tests for the v2 client yet.

Do we want to write V2 client context manager tests too? I've added a lot of tests for the context manager code so I'm not sure if the value is there. Or we could move them to v2 client calls?

seantibor avatar May 08 '20 19:05 seantibor

Updated session approach to use setter, getter, and deleter property methods.

seantibor avatar May 08 '20 20:05 seantibor

Tests passed for all supported Python versions. Would like @prschmid to take a look before confirming merge.

mfldavidson avatar Mar 17 '21 14:03 mfldavidson

Ok -- I think I got it. I've run black on everything and merged develop. Tests are running against 3.6.13 and passing. Let me know if you need anything else.

seantibor avatar Apr 29 '21 15:04 seantibor

@seantibor Thanks for fixing up those tests! I just verified and they indeed do pass now. I did notice, however, that there still appears to be one file that is in need of formatting

(~/Development/zoomus:[feature/requests-session]) # black . --check
would reformat /Users/prschmid/Development/zoomus/tests/zoomus/test_util.py
Oh no! 💥 💔 💥
1 file would be reformatted, 95 files would be left unchanged.

Assuming you are running the same version of black as the repo (black==20.8b0) you should be able to just do black . and it will automatically format your files correctly.

Thanks for dealing with these formatting details!

prschmid avatar May 05 '21 12:05 prschmid

I'm trying to figure out why black keeps formatting this section differently from the command line vs. the pre-commit hook. Possibly a configuration variable I'm missing?

Screen Shot 2021-05-05 at 4 19 15 PM

Any ideas?

seantibor avatar May 05 '21 20:05 seantibor

I'm trying to figure out why black keeps formatting this section differently from the command line vs. the pre-commit hook. Possibly a configuration variable I'm missing?

Screen Shot 2021-05-05 at 4 19 15 PM

Any ideas?

Usually when that happens it's due to a black version mismatch. I would be sure to check through and make sure that the versions match up between what you have installed, what's listed in requirements, and what's listed in the pre-commit hook.

tarkatronic avatar May 05 '21 20:05 tarkatronic

Sorry for the many extra commits on this trying to get my pre-commit to work. I finally manually ran black 21.4b and skipped the pre-commit hook that was formatting the test_util.py wrong. I'm not entirely sure why my pre-commit got so messed up but this should bring it back in line.

seantibor avatar May 05 '21 22:05 seantibor