-
Notifications
You must be signed in to change notification settings - Fork 53
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add tests for Conferences script (#404)
* Add tests for parsing Conference Issues * Refactor top-level logic into testable functions * Run pre-commit linters * Only add to conference list if the conference details could actually be parse * Move gh token env var to function We don't always need to use the GITHUB_TOKEN during tests, so let's make it an explicit call if we need it * Add sleep command to playwright tests This should allow playwright to finish setting up before running tests * Add delay between each test to make CI tests more consistent * Linter fixes * Reduce startup time so tests don't take as long to run * Reduce delay between tests to 1 second * Update _conferences/__main__.py Co-authored-by: Jay Miller <[email protected]> * Fix linter issues --------- Co-authored-by: Jay Miller <[email protected]>
- Loading branch information
1 parent
9e90858
commit b6ce359
Showing
3 changed files
with
234 additions
and
69 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,10 @@ | ||
import time | ||
|
||
import pytest | ||
from playwright.sync_api import Page, expect | ||
|
||
from _conferences.__main__ import parse_conference_details | ||
|
||
live_server_url = "http://127.0.0.1:4000" | ||
|
||
routes = [ | ||
|
@@ -11,6 +15,13 @@ | |
] | ||
|
||
|
||
# Add a delay to each test to help with playwright race conditions | ||
@pytest.fixture(autouse=True) | ||
def slow_down_tests(): | ||
yield | ||
time.sleep(1) | ||
|
||
|
||
@pytest.mark.parametrize("url", routes) | ||
def test_destination( | ||
page: Page, | ||
|
@@ -101,3 +112,113 @@ def test_mailto_bpdevs(page: Page) -> None: | |
page.goto(f"{live_server_url}") | ||
mailto = page.get_by_role("link", name="email") | ||
expect(mailto).to_have_attribute("href", "mailto:[email protected]") | ||
|
||
|
||
def test_conference_parsing_valid_url(): | ||
example_conf_issue = """### Conference Name | ||
Test Conference Title | ||
### URL | ||
https://microsoft.com | ||
### Conference Dates | ||
10 - 15 Sep 2050 | ||
### Conference Type | ||
both | ||
### Conference Location | ||
Redmond, WA, USA | ||
### Summary | ||
Test Conference Summary | ||
### Speaking | ||
* [Satya Nadella](https://www.linkedin.com/in/satyanadella/) | ||
""" | ||
expected_name = "Test Conference Title" | ||
expected_url = "https://microsoft.com" | ||
parsed_conf = parse_conference_details(issue_body=example_conf_issue) | ||
|
||
assert parsed_conf["name"] == expected_name | ||
assert parsed_conf["url"] == expected_url | ||
|
||
|
||
def test_conference_parsing_logic_no_url_scheme(): | ||
example_conf_issue = """### Conference Name | ||
Test Conference Title | ||
### URL | ||
microsoft.com | ||
### Conference Dates | ||
10 - 15 Sep 2050 | ||
### Conference Type | ||
both | ||
### Conference Location | ||
Redmond, WA, USA | ||
### Summary | ||
Test Conference Summary | ||
### Speaking | ||
* [Satya Nadella](https://www.linkedin.com/in/satyanadella/) | ||
""" | ||
expected_name = "Test Conference Title" | ||
expected_url = "https://microsoft.com" | ||
parsed_conf = parse_conference_details(issue_body=example_conf_issue) | ||
|
||
assert parsed_conf["name"] == expected_name | ||
assert parsed_conf["url"] == expected_url | ||
|
||
|
||
def test_conference_parsing_logic_no_url(): | ||
example_conf_issue = """### Conference Name | ||
Test Conference Title | ||
### URL | ||
### Conference Dates | ||
10 - 15 Sep 2050 | ||
### Conference Type | ||
both | ||
### Conference Location | ||
Redmond, WA, USA | ||
### Summary | ||
Test Conference Summary | ||
### Speaking | ||
* [Satya Nadella](https://www.linkedin.com/in/satyanadella/) | ||
""" | ||
expected_name = "Test Conference Title" | ||
expected_url = None | ||
parsed_conf = parse_conference_details(issue_body=example_conf_issue) | ||
|
||
assert parsed_conf["name"] == expected_name | ||
assert parsed_conf["url"] == expected_url |