generated from rochacbruno/python-project-template
-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#36: Move event details into json files
- Loading branch information
Showing
5 changed files
with
27 additions
and
128 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
from g2w import Alert | ||
import unittest | ||
from .conftest import AbstractTest | ||
|
||
|
||
class AlertTest(unittest.TestCase): | ||
class AlertTest(AbstractTest): | ||
def test_comment(self): | ||
self.assertGreater(Alert().desc('{"user":"Tom"}').find("user%22%3A%22Tom"), 0) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,8 @@ | ||
import os | ||
import pytest | ||
from fastapi.testclient import TestClient | ||
import unittest | ||
from .conftest import AbstractTest | ||
|
||
|
||
from g2w.__main__ import app | ||
|
||
|
@@ -13,15 +14,7 @@ | |
# - https://stackoverflow.com/a/52065289/6916890 | ||
|
||
|
||
# @todo #/DEV Move push event details into a separate *.json file. | ||
# For example, the `json.load` or `pkg_resources` from `setuptools` might | ||
# be used: | ||
# - https://stackoverflow.com/a/37151805/6916890 | ||
# - https://stackoverflow.com/a/1396657/6916890 | ||
# - https://setuptools.pypa.io/en/latest/pkg_resources.html | ||
|
||
|
||
class ClientTest(unittest.TestCase): | ||
class ClientTest(AbstractTest): | ||
@pytest.mark.skipif(os.getenv("WS_ADMIN_EMAIL") is None, reason="Environment variable 'WS_ADMIN_EMAIL' is absent") | ||
@pytest.mark.skipif(os.getenv("WS_URL_ALL_USERS") is None, reason="Environment variable 'WS_URL_ALL_USERS' is absent") | ||
@pytest.mark.skipif(os.getenv("WS_URL_POST_COMMENT") is None, reason="Environment variable 'WS_URL_POST_COMMENT' is absent") | ||
|
@@ -31,74 +24,7 @@ def test_e2e_push(self): | |
# requests_mock.get('http://test.com', text='data') | ||
response = TestClient(app).post( | ||
"/gitlab/push/223728", | ||
json={ | ||
"object_kind": "push", | ||
"event_name": "push", | ||
"before": "95790bf891e76fee5e1747ab589903a6a1f80f22", | ||
"after": "da1560886d4f094c3e6c9ef40349f7d38b5d27d7", | ||
"ref": "refs/heads/master", | ||
"checkout_sha": "da1560886d4f094c3e6c9ef40349f7d38b5d27d7", | ||
"user_id": 4, | ||
"user_name": "John Smith", | ||
"user_username": "jsmith", | ||
"user_email": "[email protected]", | ||
"user_avatar": "https://s.gravatar.com/avatar/d4c74594d841139328695756648b6bd6?s=8://s.gravatar.com/avatar/d4c74594d841139328695756648b6bd6?s=80", | ||
"project_id": 15, | ||
"project": { | ||
"id": 15, | ||
"name": "Diaspora", | ||
"description": "", | ||
"web_url": "https://example.com/mike/diaspora", | ||
"avatar_url": None, | ||
"git_ssh_url": "[email protected]:mike/diaspora.git", | ||
"git_http_url": "https://example.com/mike/diaspora.git", | ||
"namespace": "Mike", | ||
"visibility_level": 0, | ||
"path_with_namespace": "mike/diaspora", | ||
"default_branch": "master", | ||
"homepage": "https://example.com/mike/diaspora", | ||
"url": "[email protected]:mike/diaspora.git", | ||
"ssh_url": "[email protected]:mike/diaspora.git", | ||
"http_url": "https://example.com/mike/diaspora.git", | ||
}, | ||
"repository": { | ||
"name": "Diaspora", | ||
"url": "[email protected]:mike/diaspora.git", | ||
"description": "", | ||
"homepage": "https://example.com/mike/diaspora", | ||
"git_http_url": "https://example.com/mike/diaspora.git", | ||
"git_ssh_url": "[email protected]:mike/diaspora.git", | ||
"visibility_level": 0, | ||
}, | ||
"commits": [ | ||
{ | ||
"id": "b6568db1bc1dcd7f8b4d5a946b0b91f9dacd7327", | ||
"message": "Update Catalan translation to e38cb41.\n\nSee https://gitlab.com/gitlab-org/gitlab for more information", | ||
"title": "Update Catalan translation to e38cb41.", | ||
"timestamp": "2011-12-12T14:27:31+02:00", | ||
"url": "https://example.com/mike/diaspora/commit/b6568db1bc1dcd7f8b4d5a946b0b91f9dacd7327", | ||
"author": {"name": "Jordi Mallach", "email": "[email protected]"}, | ||
"added": ["CHANGELOG"], | ||
"modified": ["app/controller/application.rb"], | ||
"removed": [], | ||
}, | ||
{ | ||
"id": "da1560886d4f094c3e6c9ef40349f7d38b5d27d7", | ||
"message": "#WS-6231285: fixed readme", | ||
"title": "#WS-6231285: fixed readme", | ||
"timestamp": "2012-01-03T23:36:29+02:00", | ||
"url": "https://example.com/mike/diaspora/commit/da1560886d4f094c3e6c9ef40349f7d38b5d27d7", | ||
"author": { | ||
"name": "GitLab dev user", | ||
"email": "gitlabdev@dv6700.(none)", | ||
}, | ||
"added": ["CHANGELOG"], | ||
"modified": ["app/controller/application.rb"], | ||
"removed": [], | ||
}, | ||
], | ||
"total_commits_count": 2, | ||
}, | ||
json=self.body("sample2_commits.json") | ||
) | ||
self.assertEqual(response.status_code, 200) | ||
self.assertGreater(int(response.json()["comments"][0]["id"]), 0) | ||
|
@@ -109,49 +35,10 @@ def test_e2e_push(self): | |
def test_e2e_alert(self): | ||
response = TestClient(app).post( | ||
"/grafana/alert/223728", | ||
json={ | ||
"receiver": "My Super Webhook", | ||
"status": "firing", | ||
"orgId": 1, | ||
"alerts": [ | ||
{ | ||
"status": "firing", | ||
"labels": {"alertname": "High memory usage", "team": "blue", "zone": "us-1"}, | ||
"annotations": {"description": "The system has high memory usage", "runbook_url": "https://myrunbook.com/runbook/1234", "summary": "This alert was triggered for zone us-1"}, | ||
"startsAt": "2021-10-12T09:51:03.157076+02:00", | ||
"endsAt": "0001-01-01T00:00:00Z", | ||
"generatorURL": "https://play.grafana.org/alerting/1afz29v7z/edit", | ||
"fingerprint": "c6eadffa33fcdf37", | ||
"silenceURL": "https://play.grafana.org/alerting/silence/new?alertmanager=grafana&matchers=alertname%3DT2%2Cteam%3Dblue%2Czone%3Dus-1", | ||
"dashboardURL": "", | ||
"panelURL": "", | ||
"valueString": "[ metric='' labels={} value=14151.331895396988 ]", | ||
}, | ||
{ | ||
"status": "firing", | ||
"labels": {"alertname": "High CPU usage", "team": "blue", "zone": "eu-1"}, | ||
"annotations": {"description": "The system has high CPU usage", "runbook_url": "https://myrunbook.com/runbook/1234", "summary": "This alert was triggered for zone eu-1"}, | ||
"startsAt": "2021-10-12T09:56:03.157076+02:00", | ||
"endsAt": "0001-01-01T00:00:00Z", | ||
"generatorURL": "https://play.grafana.org/alerting/d1rdpdv7k/edit", | ||
"fingerprint": "bc97ff14869b13e3", | ||
"silenceURL": "https://play.grafana.org/alerting/silence/new?alertmanager=grafana&matchers=alertname%3DT1%2Cteam%3Dblue%2Czone%3Deu-1", | ||
"dashboardURL": "", | ||
"panelURL": "", | ||
"valueString": "[ metric='' labels={} value=47043.702386305304 ]", | ||
}, | ||
], | ||
"groupLabels": {}, | ||
"commonLabels": {"team": "blue"}, | ||
"commonAnnotations": {}, | ||
"externalURL": "https://play.grafana.org/", | ||
"version": "1", | ||
"groupKey": "{}:{}", | ||
"truncatedAlerts": 0, | ||
"title": "[FIRING:2] (blue)", | ||
"state": "alerting", | ||
"message": "**Firing**\n\nLabels:\n - alertname = T2\n - team = blue\n - zone = us-1\nAnnotations:\n - description = This is the alert rule checking the second system\n - runbook_url = https://myrunbook.com\n - summary = This is my summary\nSource: https://play.grafana.org/alerting/1afz29v7z/edit\nSilence: https://play.grafana.org/alerting/silence/new?alertmanager=grafana&matchers=alertname%3DT2%2Cteam%3Dblue%2Czone%3Dus-1\n\nLabels:\n - alertname = T1\n - team = blue\n - zone = eu-1\nAnnotations:\nSource: https://play.grafana.org/alerting/d1rdpdv7k/edit\nSilence: https://play.grafana.org/alerting/silence/new?alertmanager=grafana&matchers=alertname%3DT1%2Cteam%3Dblue%2Czone%3Deu-1\n", | ||
}, | ||
json=self.body("sample1_alert.json") | ||
) | ||
self.assertEqual(response.status_code, 200) | ||
self.assertGreater(response.json()["created"]["id"], 0) | ||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters