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

Fix various tests #236

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open

Conversation

kyluca
Copy link
Contributor

@kyluca kyluca commented Oct 16, 2024

Description

This PR fixes the second half of #194.

During #234, the tests were enabled on GHAs but they weren't passing.

Previous test result from master:

============================= test session starts ==============================
platform linux -- Python 3.12.7, pytest-7.4.4, pluggy-1.5.0
rootdir: /home/runner/work/pep8speaks/pep8speaks
plugins: mock-3.12.0, flask-1.3.0
collected 28 items

tests/test_workflow.py FFFF                                              [ 14%]
tests/local/test_server.py .FFFFFFFF                                     [ 46%]
tests/local/pep8speaks/test_utils.py FF............E                     [100%]
==================== 14 failed, 13 passed, 1 error in 1.13s ====================

Here I've made a few small tweaks to get the test suite passing locally at least (will have to see what happens on GHA):

screenshot_from_2024_10_16_16_36_46

I will try to comment on each fix in-line.

@kyluca
Copy link
Contributor Author

kyluca commented Oct 16, 2024

So the tests/local suite is now passing, but test/test_workflow.py is failing:

============================= test session starts ==============================
platform linux -- Python 3.12.7, pytest-7.4.4, pluggy-1.5.0
rootdir: /home/runner/work/pep8speaks/pep8speaks
plugins: mock-3.12.0, flask-1.3.0
collected 28 items

tests/test_workflow.py FFFF                                              [ 14%]
tests/local/test_server.py .........                                     [ 46%]
tests/local/pep8speaks/test_utils.py ...............                     [100%]

@Mr-Sunglasses are those failing tests designed to be run manually after deploying some test version of the app to Heroku? If that's the case I can exclude them from the GHA test command.

Otherwise, if they are meant to run during CI on every PR, what would the desired fix look like?

@@ -28,8 +28,14 @@ def query_request(query=None, method="GET", **kwargs):
"headers": {"Authorization": f"Bearer {GITHUB_TOKEN}"}
}

for kw in kwargs:
request_kwargs["headers"].update(kwargs[kw])
Copy link
Contributor Author

Choose a reason for hiding this comment

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

The old code had a bug where non-header parameters were being placed under the headers key, instead of at the top level

e.g.

# Incorrect
{
  "headers": {
    "a": 1,
    "json": {...},
  },
}

vs.

# Correct
{
  "headers": {"a": 1},
  "json": {...},
}

@@ -62,7 +68,9 @@ def update_dict(base, head):

def match_webhook_secret(request):
"""Match the webhook secret sent from GitHub"""
if os.environ.get("OVER_HEROKU", False):
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This bug was due to the fact that the string "False" actually evaluates as True when tested as a boolean, only the empty string "" gives a False value.

Fixed by accounting for all varieties of a "True" env var.

@@ -20,7 +20,6 @@ def test_request(self, mocker, query, method, json, data, headers, params):
assert mock_func.call_count == 1
assert mock_func.call_args[0][0] == method
assert mock_func.call_args[1]['headers'] == headers
assert mock_func.call_args[1]['auth'] == (os.environ['BOT_USERNAME'], os.environ['GITHUB_TOKEN'])
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed to use the current authentication method.

@@ -45,43 +44,45 @@ def test_request(self, mocker, query, method, json, data, headers, params):
def test_update_dict(self, base, head, expected):
assert update_dict(base, head) == expected

def test_match_webhook_secret(self, monkeypatch, request_ctx):
Copy link
Contributor Author

Choose a reason for hiding this comment

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

request_ctx no longer exists, fixed by using a MagicMock instead.

headers={"X-GitHub-Event": event},
# TODO: This test is not representative of the real JSON payloads sent by Github and should be updated at
# some point to have a sample payload fixture for each of the above types.
json={"a": "value", "b": 1},
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This json param was required, but missing. Ideally the value would look more like a real payload, but those are hundreds/thousands of lines long and I didn't have a good example to dump in here.

@kyluca
Copy link
Contributor Author

kyluca commented Oct 28, 2024

Hey @Mr-Sunglasses, just wondering if you'll have a chance to review this over the next few days?

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.

1 participant