-
Notifications
You must be signed in to change notification settings - Fork 107
Expand file tree
/
Copy pathconftest.py
More file actions
120 lines (82 loc) · 2.82 KB
/
conftest.py
File metadata and controls
120 lines (82 loc) · 2.82 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
"""
This module contains shared fixtures.
"""
# ------------------------------------------------------------
# Imports
# ------------------------------------------------------------
import os
import pytest
from playwright.sync_api import Playwright, APIRequestContext, Page, expect
from screenplay.pattern import Actor
from typing import Generator
# ------------------------------------------------------------
# Screenplay fixtures
# ------------------------------------------------------------
@pytest.fixture
def actor(page: Page) -> Actor:
actor = Actor()
actor.can_use(page=page)
return actor
@pytest.fixture
def gh_actor(actor: Actor, gh_context: APIRequestContext) -> Actor:
actor.can_use(gh_context=gh_context)
return actor
# ------------------------------------------------------------
# GitHub project fixtures
# ------------------------------------------------------------
# Environment variables
def _get_env_var(varname: str) -> str:
value = os.getenv(varname)
assert value, f'{varname} is not set'
return value
@pytest.fixture(scope='session')
def gh_username() -> str:
return _get_env_var('GITHUB_USERNAME')
@pytest.fixture(scope='session')
def gh_password() -> str:
return _get_env_var('GITHUB_PASSWORD')
@pytest.fixture(scope='session')
def gh_access_token() -> str:
return _get_env_var('GITHUB_ACCESS_TOKEN')
@pytest.fixture(scope='session')
def gh_project_name() -> str:
return _get_env_var('GITHUB_PROJECT_NAME')
# Request context
@pytest.fixture(scope='session')
def gh_context(
playwright: Playwright,
gh_access_token: str) -> Generator[APIRequestContext, None, None]:
headers = {
"Accept": "application/vnd.github.v3+json",
"Authorization": f"token {gh_access_token}"}
request_context = playwright.request.new_context(
base_url="https://api.github.com",
extra_http_headers=headers)
yield request_context
request_context.dispose()
# GitHub project requests
@pytest.fixture(scope='session')
def gh_project(
gh_context: APIRequestContext,
gh_username: str,
gh_project_name: str) -> dict:
resource = f'/users/{gh_username}/projects'
response = gh_context.get(resource)
expect(response).to_be_ok()
name_match = lambda x: x['name'] == gh_project_name
filtered = filter(name_match, response.json())
project = list(filtered)[0]
assert project
return project
@pytest.fixture()
def project_columns(
gh_context: APIRequestContext,
gh_project: dict) -> list[dict]:
response = gh_context.get(gh_project['columns_url'])
expect(response).to_be_ok()
columns = response.json()
assert len(columns) >= 2
return columns
@pytest.fixture()
def project_column_ids(project_columns: list[dict]) -> list[str]:
return list(map(lambda x: x['id'], project_columns))