def test_download_repo(self, mock_download_file): mock_download_file.side_effect = self.mock_download_file cwh = ClientWebhook() try: os.makedirs(cwh.base_temp_dir) except: pass cwh.download_repo('bible_bundle_master', ClientWebhookTest.base_temp_dir)
def setup_client_webhook_mock(self, repo_name, mock_download_file): App.gogs_url = self.resources_dir App.gogs_user_token = mock_utils.valid_token mock_download_file.side_effect = self.mock_download_file source = os.path.join(self.resources_dir, repo_name) commit_data = self.get_commit_data(source) self.cwh = ClientWebhook(commit_data) self.cwh.send_payload_to_converter = self.mock_send_payload_to_converter self.cwh.send_payload_to_linter = self.mock_send_payload_to_linter self.cwh.clear_commit_directory_in_cdn = self.mock_clear_commit_directory_in_cdn return self.cwh
def _handle(self, event, context): """ :param dict event: :param context: :return dict: """ # Gather arguments commit_data = self.retrieve(event, 'data', 'Payload') # Execute return ClientWebhook(commit_data).process_webhook()
def test_get_linter_module(self): job = TxJob(**self.job_data) cw = ClientWebhook() linter = cw.get_linter_module(job) self.assertIsNotNone(linter) self.assertEqual(linter.name, 'obs')
def test_get_converter_module(self): job = TxJob(**self.job_data) cw = ClientWebhook() converter = cw.get_converter_module(job) self.assertIsNotNone(converter) self.assertEqual(converter.name, 'md2html')
def do_conversion_job(self, base_url, commit_id, commit_path, commit_sha, repo, user): commit_data = { "after": commit_id, "ref": "refs/heads/master", "commits": [{ "id": "b9278437b27024e07d02490400138d4fd7d1677c", "message": "Fri Dec 16 2016 11:09:07 GMT+0530 (India Standard Time)\n", "url": base_url + commit_path, }], "compare_url": "", "repository": { "name": repo, "html_url": "https://git.door43.org/unfoldingWord/en_ulb", "default_branch": "master", "owner": { "id": 1234567890, "username": user, "full_name": user, "email": "*****@*****.**" }, }, "pusher": { "id": 123456789, "username": "******", "full_name": "", "email": "*****@*****.**" }, } start = time.time() if USE_WEB_HOOK_LAMBDA: headers = {"content-type": "application/json"} tx_client_webhook_url = "{0}/client/webhook".format(App.api_url) App.logger.debug( 'Making request to client/webhook URL {0} with payload:'. format(tx_client_webhook_url)) App.logger.debug(commit_data) response = requests.post(tx_client_webhook_url, json=commit_data, headers=headers) App.logger.debug('webhook finished with code:' + str(response.status_code)) App.logger.debug('webhook finished with text:' + str(response.text)) build_log_json = json.loads(response.text) if response.status_code == 504: # on timeout, could be multi-part, so try to get build build_log_json = self.poll_for_build_log( commit_sha, repo, user) elif response.status_code != 200: job_id = None if 'job_id' not in build_log_json else build_log_json[ 'job_id'] return build_log_json, False, job_id else: # do preconvert locally try: build_log_json = ClientWebhook( commit_data=commit_data).process_webhook() except Exception as e: message = "Exception: " + str(e) self.warn(message) return None, False, None App.logger.debug("webhook completed in " + str(elapsed_time(start)) + " seconds") if "build_logs" not in build_log_json: # if not multiple parts job_id = build_log_json['job_id'] if job_id is None: self.warn("Job ID missing in build_log") return None, False, None success, job = self.poll_until_job_finished(job_id) else: # multiple parts success, job = self.poll_until_all_jobs_finished( build_log_json['build_logs']) build_log_json = self.get_json_file(commit_sha, 'build_log.json', repo, user) if build_log_json is not None: App.logger.debug("Final results:\n" + str(build_log_json)) return build_log_json, success, job