forked from MeltanoLabs/tap-github
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfixtures.py
More file actions
134 lines (111 loc) · 4.23 KB
/
fixtures.py
File metadata and controls
134 lines (111 loc) · 4.23 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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
from __future__ import annotations
import datetime
import logging
import os
import sys
from typing import TYPE_CHECKING
import pytest
from tap_github.utils.filter_stdout import FilterStdOutput
if TYPE_CHECKING:
from singer_sdk.helpers.types import Context
# Filter out singer output during tests
sys.stdout = FilterStdOutput(sys.stdout, r'{"type": ')
@pytest.fixture
def search_config():
return {
"metrics_log_level": "warning",
"start_date": datetime.datetime.now(datetime.timezone.utc).strftime("%Y-%m-%d"),
"searches": [
{
"name": "tap_something",
"query": "tap-+language:Python",
}
],
}
@pytest.fixture
def repo_list_config(request):
"""
Get a default list of repos or pass your own by decorating your test with
@pytest.mark.repo_list(['org1/repo1', 'org2/repo2'])
"""
marker = request.node.get_closest_marker("repo_list")
if marker is None:
repo_list = ["MeltanoLabs/tap-github", "mapswipe/mapswipe"]
else:
repo_list = marker.args[0]
return {
"metrics_log_level": "warning",
"start_date": datetime.datetime.now(datetime.timezone.utc).strftime("%Y-%m-%d"),
"repositories": repo_list,
"rate_limit_buffer": 100,
}
@pytest.fixture
def username_list_config(request):
"""
Get a default list of usernames or pass your own by decorating your test with
@pytest.mark.username_list(['ericboucher', 'aaronsteers'])
"""
marker = request.node.get_closest_marker("username_list")
username_list = ["ericboucher", "aaronsteers"] if marker is None else marker.args[0]
return {
"metrics_log_level": "warning",
"start_date": datetime.datetime.now(datetime.timezone.utc).strftime("%Y-%m-%d"),
"user_usernames": username_list,
"rate_limit_buffer": 100,
}
@pytest.fixture
def user_id_list_config(request):
"""
Get a default list of usernames or pass your own by decorating your test with
@pytest.mark.user_id_list(['ericboucher', 'aaronsteers'])
"""
marker = request.node.get_closest_marker("user_id_list")
user_id_list = [1, 2] if marker is None else marker.args[0]
return {
"metrics_log_level": "warning",
"start_date": datetime.datetime.now(datetime.timezone.utc).strftime("%Y-%m-%d"),
"user_ids": user_id_list,
"rate_limit_buffer": 100,
}
@pytest.fixture
def organization_list_config(request):
"""
Get a default list of organizations or pass your own by decorating your test with
@pytest.mark.organization_list(['MeltanoLabs', 'oviohub'])
"""
marker = request.node.get_closest_marker("organization_list")
organization_list = ["MeltanoLabs"] if marker is None else marker.args[0]
return {
"metrics_log_level": "warning",
"start_date": datetime.datetime.now(datetime.timezone.utc).strftime("%Y-%m-%d"),
"organizations": organization_list,
"rate_limit_buffer": 100,
}
def alternative_sync_chidren(
self,
child_context: Context,
no_sync: bool = True,
) -> None:
"""
Override for Stream._sync_children.
Enabling us to use an ORG_LEVEL_TOKEN for the collaborators stream.
"""
for child_stream in self.child_streams:
# Use org:write access level credentials for collaborators stream
if child_stream.name == "collaborators":
ORG_LEVEL_TOKEN = os.environ.get("ORG_LEVEL_TOKEN") # noqa: N806
# TODO - Fix collaborators tests, likely by mocking API responses directly.
# Currently we have to bypass them as they are failing frequently.
if not ORG_LEVEL_TOKEN or no_sync:
logging.warning(
'No "ORG_LEVEL_TOKEN" found. Skipping collaborators stream sync.'
)
continue
SAVED_GTHUB_TOKEN = os.environ.get("GITHUB_TOKEN") # noqa: N806
os.environ["GITHUB_TOKEN"] = ORG_LEVEL_TOKEN
child_stream.sync(context=child_context)
os.environ["GITHUB_TOKEN"] = SAVED_GTHUB_TOKEN or ""
continue
# default behavior:
if child_stream.selected or child_stream.has_selected_descendents:
child_stream.sync(context=child_context)