From 2e1d28b14caa1d2d1ba67e45e3fba59d8232eee4 Mon Sep 17 00:00:00 2001 From: Silvie Chlupova Date: Jan 09 2020 08:35:29 +0000 Subject: frontend: tests for pagure events Fixes: #803 --- diff --git a/frontend/coprs_frontend/config/copr_unit_test.conf b/frontend/coprs_frontend/config/copr_unit_test.conf index 5f80e13..02baa96 100644 --- a/frontend/coprs_frontend/config/copr_unit_test.conf +++ b/frontend/coprs_frontend/config/copr_unit_test.conf @@ -63,3 +63,9 @@ STORAGE_DIR = os.path.join(LOCAL_TMP_DIR, "srpm_storage") # %check section start redis-server on this port REDIS_HOST = "127.0.0.1" REDIS_PORT = 7777 + +PAGURE_EVENTS = { + 'io.pagure.prod.pagure.git.receive' : 'https://pagure.io/', + 'io.pagure.prod.pagure.pull-request.new' : 'https://pagure.io/', + 'io.pagure.prod.pagure.pull-request.comment.added' : 'https://pagure.io/', +} diff --git a/frontend/coprs_frontend/tests/test_pagure_events.py b/frontend/coprs_frontend/tests/test_pagure_events.py new file mode 100644 index 0000000..fd7f4a5 --- /dev/null +++ b/frontend/coprs_frontend/tests/test_pagure_events.py @@ -0,0 +1,52 @@ +from pagure_events import event_info_from_pr_comment, event_info_from_push, event_info_from_pr +from tests.coprs_test_case import CoprsTestCase + + +class TestPagureEvents(CoprsTestCase): + data = { + "msg": { + "agent": "test", + "pullrequest": { + "branch": "master", + "branch_from": "test_PR", + "id": 1, + "commit_start": "78a74b02771506daf8927b3391a669cbc32ccf10", + "commit_stop": "da3d120f2ff24fa730067735c19a0b52c8bc1a44", + "repo_from": { + "fullname": "test/copr/copr", + "url_path": "test/copr/copr", + }, + "project": { + "fullname": "test/copr/copr", + "url_path": "test/copr/copr", + }, + 'status': 'Open', + "comments": [] + } + } + } + base_url = "https://pagure.io/" + + def test_negative_event_info_from_pr_comment(self): + event_info = event_info_from_pr_comment(self.data, self.base_url) + assert not event_info + + def test_positive_event_info_from_pr_comment(self): + self.data['msg']['pullrequest']["comments"].append({"comment": "[copr-build]"}) + event_info = event_info_from_pr_comment(self.data, self.base_url) + assert event_info.base_clone_url == "https://pagure.io/test/copr/copr" + + def test_positive_event_info_from_pr(self): + event_info = event_info_from_pr(self.data, self.base_url) + assert event_info.base_clone_url == "https://pagure.io/test/copr/copr" + + def test_positive_event_info_from_push(self): + self.data['msg'] = { + "branch": "master", + "start_commit": "61bba3a6bd95fe83c651339018c1d36eae48b620", + 'end_commit': '61bba3a6bd95fe83c651339018c1d36eae48b620', + "agent": "test" + } + self.data['msg']['repo'] = {"fullname": "test", "url_path": "test"} + event_info = event_info_from_push(self.data, self.base_url) + assert event_info.base_clone_url == "https://pagure.io/test"