Skip to content

Commit

Permalink
test: update the rescan tests
Browse files Browse the repository at this point in the history
Full disclosure: I haven't thought hard about what rescanning should do
now, and haven't added the new label->Jira logic into the rescan tests.
  • Loading branch information
Ned Batchelder committed Sep 27, 2023
1 parent 992479d commit 6a2f954
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 17 deletions.
6 changes: 3 additions & 3 deletions openedx_webhooks/tasks/github.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,9 +169,9 @@ def rescan_repository(
else:
if result.changed_jira_issues:
changed[pull_request["number"]] = result.changed_jira_issues

Check warning on line 171 in openedx_webhooks/tasks/github.py

View check run for this annotation

Codecov / codecov/patch

openedx_webhooks/tasks/github.py#L171

Added line #L171 was not covered by tests
if dry_run:
assert actions is not None
dry_run_actions[pull_request["number"]] = actions.action_calls
if dry_run:
assert actions is not None
dry_run_actions[pull_request["number"]] = actions.action_calls

if not dry_run:
logger.info(
Expand Down
22 changes: 8 additions & 14 deletions tests/test_rescan.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,10 @@ def test_rescan_repository(rescannable_repo, pull_request_changed_fn, allpr):
prnums = [c.args[0]["number"] for c in pull_request_changed_fn.call_args_list]
if allpr:
assert prnums == [102, 106, 108, 110]
assert changed == {102: None, 106: None, 108: None, 110: None}
assert changed == {}
else:
assert prnums == [102, 106]
assert set(changed.keys()) == {102, 106}
assert changed == {}

# If we rescan again, nothing should happen.
ret = rescan_repository(rescannable_repo.full_name, allpr=allpr)
Expand All @@ -92,41 +92,36 @@ def test_rescan_repository_dry_run(rescannable_repo, fake_github, fake_jira, pul
fake_jira.assert_readonly()

# These are the OSPR tickets for the pull requests.
assert ret["changed"] == {
102: None,
106: None,
108: None,
110: None,
}
assert ret["changed"] == {}

# Get the names of the actions. We won't worry about the details, those
# are tested in the non-dry-run tests of rescanning pull requests.
actions = {k: [name for name, kwargs in actions] for k, actions in ret["dry_run_actions"].items()}
assert actions == {
102: [
"set_cla_status",
"initial_state",
"set_cla_status",
"update_labels_on_pull_request",
"add_comment_to_pull_request",
"add_pull_request_to_project",
],
106: [
"set_cla_status",
"initial_state",
"set_cla_status",
"update_labels_on_pull_request",
"add_comment_to_pull_request",
"add_pull_request_to_project",
],
108: [
"set_cla_status",
"initial_state",
"set_cla_status",
"update_labels_on_pull_request",
"add_comment_to_pull_request",
"add_pull_request_to_project",
],
110: [
"set_cla_status",
"initial_state",
"set_cla_status",
"update_labels_on_pull_request",
"add_comment_to_pull_request",
"add_pull_request_to_project",
Expand All @@ -136,7 +131,6 @@ def test_rescan_repository_dry_run(rescannable_repo, fake_github, fake_jira, pul
# The value returned should be json-encodable.
json.dumps(ret)


@pytest.mark.parametrize("earliest, latest, nums", [
("", "", [102, 106, 108, 110]),
("2019-06-01", "", [108, 110]),
Expand Down Expand Up @@ -184,7 +178,7 @@ def flaky_pull_request_changed(pr, actions):
mocker.patch("openedx_webhooks.tasks.github.pull_request_changed", flaky_pull_request_changed)
ret = rescan_repository(rescannable_repo.full_name, allpr=True)

assert list(ret["changed"]) == [102, 106, 108, 110]
assert list(ret["changed"]) == []
err = ret["errors"][108]
assert err.startswith("Traceback (most recent call last):\n")
assert " in flaky_pull_request_changed\n" in err
Expand Down

0 comments on commit 6a2f954

Please sign in to comment.