forked from app-sre/qontract-reconcile
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_glitchtip.py
56 lines (48 loc) · 1.68 KB
/
test_glitchtip.py
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
from pytest_mock import MockerFixture
from reconcile.glitchtip.integration import (
fetch_current_state,
fetch_desired_state,
)
from reconcile.gql_definitions.glitchtip.glitchtip_project import GlitchtipProjectsV1
from reconcile.test.fixtures import Fixtures
from reconcile.utils.glitchtip import (
GlitchtipClient,
Organization,
)
def sort_all(orgs: list[Organization]) -> list[Organization]:
"""sort everything for easier comparison"""
for org in orgs:
for proj in org.projects:
proj.teams.sort()
for team in proj.teams:
team.users.sort()
org.projects.sort()
for team in org.teams:
team.users.sort()
org.teams.sort()
org.users.sort()
orgs.sort()
return orgs
def test_fetch_current_state(
glitchtip_client: GlitchtipClient,
glitchtip_server_full_api_response: None,
fx: Fixtures,
) -> None:
current_state = fetch_current_state(
glitchtip_client, ignore_users=["sd-app-sre+glitchtip@nasa.com"]
)
expected_current_state = [
Organization(**i) for i in fx.get_anymarkup("current_state_expected.yml")
]
assert sort_all(current_state) == sort_all(expected_current_state)
def test_desire_state(mocker: MockerFixture, fx: Fixtures) -> None:
projects = [
GlitchtipProjectsV1(**i) for i in fx.get_anymarkup("desire_state_projects.yml")
]
desired_state = fetch_desired_state(
glitchtip_projects=projects, mail_domain="nasa.com"
)
expected_desire_state = [
Organization(**i) for i in fx.get_anymarkup("desire_state_expected.yml")
]
assert sort_all(desired_state)[1] == sort_all(expected_desire_state)[1]