9
9
import os
10
10
import pytest
11
11
12
-
13
- # ------------------------------------------------------------
14
- # DuckDuckGo search fixtures
15
- # ------------------------------------------------------------
16
-
17
12
from pages .result import DuckDuckGoResultPage
18
13
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
20
16
21
17
18
+ # ------------------------------------------------------------
19
+ # DuckDuckGo search fixtures
20
+ # ------------------------------------------------------------
22
21
23
22
@pytest .fixture
24
23
def result_page (page : Page ) -> DuckDuckGoResultPage :
@@ -36,36 +35,39 @@ def search_page(page: Page) -> DuckDuckGoSearchPage:
36
35
37
36
# Environment variables
38
37
39
- def _get_env_var (varname ) :
38
+ def _get_env_var (varname : str ) -> str :
40
39
value = os .getenv (varname )
41
40
assert value , f'{ varname } is not set'
42
41
return value
43
42
44
43
45
44
@pytest .fixture (scope = 'session' )
46
- def gh_username ():
45
+ def gh_username () -> str :
47
46
return _get_env_var ('GITHUB_USERNAME' )
48
47
49
48
50
49
@pytest .fixture (scope = 'session' )
51
- def gh_password ():
50
+ def gh_password () -> str :
52
51
return _get_env_var ('GITHUB_PASSWORD' )
53
52
54
53
55
54
@pytest .fixture (scope = 'session' )
56
- def gh_access_token ():
55
+ def gh_access_token () -> str :
57
56
return _get_env_var ('GITHUB_ACCESS_TOKEN' )
58
57
59
58
60
59
@pytest .fixture (scope = 'session' )
61
- def gh_project_name ():
60
+ def gh_project_name () -> str :
62
61
return _get_env_var ('GITHUB_PROJECT_NAME' )
63
62
64
63
65
64
# Request context
66
65
67
66
@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
+
69
71
headers = {
70
72
"Accept" : "application/vnd.github.v3+json" ,
71
73
"Authorization" : f"token { gh_access_token } " }
@@ -81,10 +83,14 @@ def gh_context(playwright, gh_access_token):
81
83
# GitHub project requests
82
84
83
85
@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
+
85
91
resource = f'/users/{ gh_username } /projects'
86
92
response = gh_context .get (resource )
87
- assert response . ok
93
+ expect ( response ). to_be_ok ()
88
94
89
95
name_match = lambda x : x ['name' ] == gh_project_name
90
96
filtered = filter (name_match , response .json ())
@@ -95,15 +101,18 @@ def gh_project(gh_context, gh_username, gh_project_name):
95
101
96
102
97
103
@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
+
99
108
response = gh_context .get (gh_project ['columns_url' ])
100
- assert response . ok
109
+ expect ( response ). to_be_ok ()
101
110
102
111
columns = response .json ()
103
112
assert len (columns ) >= 2
104
113
return columns
105
114
106
115
107
116
@pytest .fixture ()
108
- def project_column_ids (project_columns ) :
117
+ def project_column_ids (project_columns : list [ dict ]) -> list [ str ] :
109
118
return list (map (lambda x : x ['id' ], project_columns ))
0 commit comments