Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 2699d5a

Browse files
Updated part 6 code and instructions
1 parent 87b75c2 commit 2699d5a

File tree

3 files changed

+100
-57
lines changed

3 files changed

+100
-57
lines changed

‎tests/conftest.py‎

Lines changed: 26 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,15 @@
99
import os
1010
import pytest
1111

12-
13-
# ------------------------------------------------------------
14-
# DuckDuckGo search fixtures
15-
# ------------------------------------------------------------
16-
1712
from pages.result import DuckDuckGoResultPage
1813
from pages.search import DuckDuckGoSearchPage
19-
from playwright.sync_api import Page
14+
from playwright.sync_api import Playwright, APIRequestContext, Page, expect
15+
from typing import Generator
2016

2117

18+
# ------------------------------------------------------------
19+
# DuckDuckGo search fixtures
20+
# ------------------------------------------------------------
2221

2322
@pytest.fixture
2423
def result_page(page: Page) -> DuckDuckGoResultPage:
@@ -36,36 +35,39 @@ def search_page(page: Page) -> DuckDuckGoSearchPage:
3635

3736
# Environment variables
3837

39-
def _get_env_var(varname):
38+
def _get_env_var(varname: str) ->str:
4039
value = os.getenv(varname)
4140
assert value, f'{varname} is not set'
4241
return value
4342

4443

4544
@pytest.fixture(scope='session')
46-
def gh_username():
45+
def gh_username()->str:
4746
return _get_env_var('GITHUB_USERNAME')
4847

4948

5049
@pytest.fixture(scope='session')
51-
def gh_password():
50+
def gh_password()->str:
5251
return _get_env_var('GITHUB_PASSWORD')
5352

5453

5554
@pytest.fixture(scope='session')
56-
def gh_access_token():
55+
def gh_access_token()->str:
5756
return _get_env_var('GITHUB_ACCESS_TOKEN')
5857

5958

6059
@pytest.fixture(scope='session')
61-
def gh_project_name():
60+
def gh_project_name()->str:
6261
return _get_env_var('GITHUB_PROJECT_NAME')
6362

6463

6564
# Request context
6665

6766
@pytest.fixture(scope='session')
68-
def gh_context(playwright, gh_access_token):
67+
def gh_context(
68+
playwright: Playwright,
69+
gh_access_token: str) -> Generator[APIRequestContext, None, None]:
70+
6971
headers = {
7072
"Accept": "application/vnd.github.v3+json",
7173
"Authorization": f"token {gh_access_token}"}
@@ -81,10 +83,14 @@ def gh_context(playwright, gh_access_token):
8183
# GitHub project requests
8284

8385
@pytest.fixture(scope='session')
84-
def gh_project(gh_context, gh_username, gh_project_name):
86+
def gh_project(
87+
gh_context: APIRequestContext,
88+
gh_username: str,
89+
gh_project_name: str) -> dict:
90+
8591
resource = f'/users/{gh_username}/projects'
8692
response = gh_context.get(resource)
87-
assertresponse.ok
93+
expect(response).to_be_ok()
8894

8995
name_match = lambda x: x['name'] == gh_project_name
9096
filtered = filter(name_match, response.json())
@@ -95,15 +101,18 @@ def gh_project(gh_context, gh_username, gh_project_name):
95101

96102

97103
@pytest.fixture()
98-
def project_columns(gh_context, gh_project):
104+
def project_columns(
105+
gh_context: APIRequestContext,
106+
gh_project: dict) -> list[dict]:
107+
99108
response = gh_context.get(gh_project['columns_url'])
100-
assertresponse.ok
109+
expect(response).to_be_ok()
101110

102111
columns = response.json()
103112
assert len(columns) >= 2
104113
return columns
105114

106115

107116
@pytest.fixture()
108-
def project_column_ids(project_columns):
117+
def project_column_ids(project_columns: list[dict]) ->list[str]:
109118
return list(map(lambda x: x['id'], project_columns))

‎tests/test_github_project.py‎

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,16 @@
88

99
import time
1010

11-
from playwright.sync_api import expect
11+
from playwright.sync_api import APIRequestContext, Page, expect
1212

1313

1414
# ------------------------------------------------------------
1515
# A pure API test
1616
# ------------------------------------------------------------
1717

18-
def test_create_project_card(gh_context, project_column_ids):
18+
def test_create_project_card(
19+
gh_context: APIRequestContext,
20+
project_column_ids: list[str]) -> None:
1921

2022
# Prep test data
2123
now = time.time()
@@ -25,21 +27,27 @@ def test_create_project_card(gh_context, project_column_ids):
2527
c_response = gh_context.post(
2628
f'/projects/columns/{project_column_ids[0]}/cards',
2729
data={'note': note})
28-
assertc_response.ok
30+
expect(c_response).to_be_ok()
2931
assert c_response.json()['note'] == note
3032

3133
# Retrieve the newly created card
3234
card_id = c_response.json()['id']
3335
r_response = gh_context.get(f'/projects/columns/cards/{card_id}')
34-
assertr_response.ok
36+
expect(r_response).to_be_ok()
3537
assert r_response.json() == c_response.json()
3638

3739

3840
# ------------------------------------------------------------
3941
# A hybrid UI/API test
4042
# ------------------------------------------------------------
4143

42-
def test_move_project_card(gh_context, gh_project, project_column_ids, page, gh_username, gh_password):
44+
def test_move_project_card(
45+
gh_context: APIRequestContext,
46+
gh_project: dict,
47+
project_column_ids: list[str],
48+
page: Page,
49+
gh_username: str,
50+
gh_password: str) -> None:
4351

4452
# Prep test data
4553
source_col = project_column_ids[0]
@@ -51,7 +59,7 @@ def test_move_project_card(gh_context, gh_project, project_column_ids, page, gh_
5159
c_response = gh_context.post(
5260
f'/projects/columns/{source_col}/cards',
5361
data={'note': note})
54-
assertc_response.ok
62+
expect(c_response).to_be_ok()
5563

5664
# Log in via UI
5765
page.goto(f'https://github.com/login')
@@ -76,5 +84,5 @@ def test_move_project_card(gh_context, gh_project, project_column_ids, page, gh_
7684
# Verify the backend is updated via API
7785
card_id = c_response.json()['id']
7886
r_response = gh_context.get(f'/projects/columns/cards/{card_id}')
79-
assertr_response.ok
87+
expect(r_response).to_be_ok()
8088
assert r_response.json()['column_url'].endswith(str(dest_col))

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /