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

Welcome message should use ADMINS set in environment and link to them #97

Merged

Conversation

bbelderbos
Copy link
Collaborator

This PR includes the changes of https://github.com/PyBites-Open-Source/karmabot/pull/96/files as I needed them here. I tested it in my env and admins are now used from the corresponding env variable and are properly linked:

image

@@ -41,10 +43,18 @@
What other programming languages do you know and/or use?"""


def _get_admins() -> str:
admins_env = get_env_var("KARMABOT_ADMINS", default=KARMABOT_ID).split(",")
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I needed to do this here in order to properly mock it in the test

Copy link
Member

Choose a reason for hiding this comment

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

Do you need to mock it? Can't we just extend

"KARMABOT_ADMINS": "FAKE_ADMIN",

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

probably, as long as it has multiple admins = more realistic - how to do it please?

Copy link
Member

Choose a reason for hiding this comment

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

In noxfile.py change it to

"KARMABOT_ADMINS": "FAKE_ADMIN1,FAKE_ADMIN2,FAKE_ADMIN3",

and then use FAKE_ADMIN1 etc. as values in the test

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

sweet, thanks, done

Copy link
Collaborator Author

@bbelderbos bbelderbos Sep 8, 2021

Choose a reason for hiding this comment

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

So you always run your tests with poetry run nox -rs tests?
I ask because this is the first test to break poetry run pytest if we do it this way ...
Also, do we need to add poetry run to the nox commands in the README?

Copy link
Member

Choose a reason for hiding this comment

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

Yes it should always be run with nox. Inside the venv you can just use the nox command.

If you want to run pytest directly you have to have a valid .karmabot file or env variables anyway. That was already a restriction before these changes. As some tests rely on the env variables.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Gotcha thanks. Anything else I need to change?

src/karmabot/settings.py Show resolved Hide resolved
src/karmabot/settings.py Show resolved Hide resolved
@@ -91,8 +94,29 @@ def test_reply_commands_unknown(capfd, test_message, expected):
assert out.strip() == expected


def test_welcome_new_user():
pass
@patch("karmabot.commands.welcome.choice")
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

tests/test_bot.py Outdated Show resolved Hide resolved
tests/test_settings.py Show resolved Hide resolved
def test_welcome_new_user(choice_mock):
choice_mock.return_value = "What is your favorite Python module?"
admins = "U4RTDPKUH,U4TN52NG6,U4SJVFMEG"
with patch.dict(os.environ, {"KARMABOT_ADMINS": admins}):
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

not leaving env variables to chance in testing

@codecov-commenter
Copy link

codecov-commenter commented Sep 8, 2021

Codecov Report

Merging #97 (a06ef62) into develop (0eaeefa) will increase coverage by 1.57%.
The diff coverage is 100.00%.

Impacted file tree graph

@@             Coverage Diff             @@
##           develop      #97      +/-   ##
===========================================
+ Coverage    54.01%   55.58%   +1.57%     
===========================================
  Files           23       23              
  Lines          735      743       +8     
  Branches        87       89       +2     
===========================================
+ Hits           397      413      +16     
+ Misses         318      312       -6     
+ Partials        20       18       -2     
Impacted Files Coverage Δ
src/karmabot/commands/welcome.py 100.00% <100.00%> (+44.44%) ⬆️
src/karmabot/settings.py 89.65% <100.00%> (+15.58%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 0eaeefa...a06ef62. Read the comment docs.

Copy link
Member

@pogross pogross left a comment

Choose a reason for hiding this comment

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

LGTM

@pogross pogross merged commit 8b3a204 into PyBites-Open-Source:develop Sep 9, 2021
@bbelderbos
Copy link
Collaborator Author

Thanks

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