Skip to content
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

Improve get_apikey method and its tests #19

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

victor-torres
Copy link
Contributor

@victor-torres victor-torres commented Aug 25, 2020

This pull request:

  • avoid problems when executing tests on local environment with populated variables
  • avoid problems when environment variables are undefined or blank strings

@codecov
Copy link

codecov bot commented Aug 25, 2020

Codecov Report

Merging #19 into master will decrease coverage by 0.26%.
The diff coverage is 71.42%.

@@            Coverage Diff             @@
##           master      #19      +/-   ##
==========================================
- Coverage   59.82%   59.55%   -0.27%     
==========================================
  Files          14       14              
  Lines         448      450       +2     
  Branches       57       58       +1     
==========================================
  Hits          268      268              
- Misses        179      181       +2     
  Partials        1        1              
Impacted Files Coverage Δ
autoextract/apikey.py 85.71% <71.42%> (-14.29%) ⬇️

@victor-torres victor-torres requested a review from kmike August 25, 2020 14:41
try:
return os.environ[ENV_VARIABLE]
except KeyError:
if not key:
Copy link
Contributor

Choose a reason for hiding this comment

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

This is a behavior change - it was intentional that empty string is different from not passing a key. Do you have this issue because of Scrapy integration, where it is hard to set a setting to None from the command line?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

it was intentional that empty string is different from not passing a key

What's the desired outcome with this behavior?

Do you have this issue because of Scrapy integration, where it is hard to set a setting to None from the command line?

Actually, no. Tests have failed on my machine because I had this variable set and I thought about "fixing" this blank string problem while creating a fixture that patched system environment during tests.

I don't understand why it would be desired to have a blank string returned from the get_apikey() method since it's an invalid value and will culminate in a failed request. But if you'd like me to I can just revert the logic and keep focused on the test fixture to avoid failing because of my own environment.

Copy link
Contributor

Choose a reason for hiding this comment

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

Thanks for the explanation @victor-torres! I'm fine with this change, but we need to make sure we mention it in the changelog as technically backwards incompatible.

@@ -9,6 +9,6 @@ def test_get_apikey(autoextract_env_variable):
assert get_apikey() == autoextract_env_variable


def test_get_apikey_missing():
def test_get_apikey_missing(autoextract_blank_env_variable):
Copy link
Contributor

Choose a reason for hiding this comment

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

hm, technically this is a different test case, and previous case (an absent env varibale) is not covered now

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.

2 participants