def put(self, id): edit_schema = IssueSchema(only=tuple(IssueSchema.issue_fields.keys())) parsed_data = edit_schema.load(request.get_json()) if (len(parsed_data.errors.items()) > 0): return f"Errors encountered with the request: {parsed_data.errors}", 416 updated_issue = parsed_data.data issue = None httpStatus: HTTPStatus = None headers = {} handler = IssueHandler() if (not handler.does_issue_exist(id)): issue = handler.store_issue(updated_issue, "create", True) hash = hashlib.sha256( b"{regular_schema.dump(issue).data}").hexdigest() print(f"Hash: {hash}") headers["ETag"] = hash httpStatus = HTTPStatus.CREATED else: current_issue = handler.get_issue_from_issue_id(id) if (updated_issue.id != id): return "Given issue ID does not match url", 416 updated_issue.date = current_issue.date # Ensure date NEVER changes issue = handler.store_issue(updated_issue, "edit") result = to_payload(GitUser(), issue, IssueSchema) return result.data, HTTPStatus.OK
def test_store_issue_stores_file(regular_issue, test_repo): ih = IssueHandler() ih.store_issue(regular_issue, None, True) result = ih.get_issue_from_issue_id(regular_issue.id) regular_issue.id = "ISSUE-11" # 11 because tracker is mocked to have 10 entries assert regular_issue == result
def test_create_resolution(issue_1: Issue, issue_2: Issue, monkeypatch, first_repo: git.Repo): handler = IssueHandler() issue_1_path = handler.get_issue_path(issue_1) issue_2_path = handler.get_issue_path(issue_2) issues = [issue_1, issue_2] os.chdir(first_repo.working_dir) monkeypatch.setattr("git_issue.git_manager.GitManager.get_choice_from_user", lambda x, y: True) monkeypatch.setattr("builtins.input", lambda x: 'Y') uuids = [UUIDTrack(issue_1.uuid, issue_1.id), UUIDTrack(issue_2.uuid, issue_2.id)] resolution = CreateResolutionTool(issues, Tracker(len(uuids), uuids)) resolution.resolve() GitManager().commit("-m", "merge conflict resolution") assert issue_1_path.exists() assert issue_2_path.exists() result_1 = handler.get_issue_from_issue_id(issues[0].id) result_2 = handler.get_issue_from_issue_id(issues[1].id) assert issues[0] == result_1 assert issues[1] == result_2
def get(self, id): handler = IssueHandler() if (not handler.does_issue_exist(id)): abort(HTTPStatus.NOT_FOUND) issue = handler.get_issue_from_issue_id(id) result = to_payload(GitUser(), issue, IssueSchema) return result.data
def test_divergence_resolution(issue_3, first_repo, monkeypatch): os.chdir(first_repo.working_dir) monkeypatch.setattr("builtins.input", lambda x: 'Y') resolution = DivergenceResolutionTool([issue_3]) resolution.resolve() handler = IssueHandler() result = handler.get_issue_from_issue_id(issue_3.id) assert issue_3 == result
def generate_resolution(self): """ Resolves conflicts by re-ordering the issues based on their creation date. The conflicts are resolved by giving the oldest issue the first conflicting issue ID. Returns a tuple containing the list of resolved conflicts, and an updated tracker. These resolved conflicts are NOT stored to fie by this method. This is left as a job for the consumer. """ # Create copies of data to avoid mutating them as a side affect conflicts = [] for info in self.conflicts: for issue in info.conflicts: conflicts.append(issue) if self.tracker is None: tracker = Tracker.obtain_tracker() else: tracker = Tracker(self.tracker.issue_count, self.tracker.tracked_uuids.copy()) complete = False handler = IssueHandler(tracker) ids = [issue.id for issue in conflicts] while not complete: to_add = [] for issue in conflicts: next_id = handler.next_issue_id(issue.id) while next_id in ids: next_id = handler.next_issue_id(next_id) if next_id not in ids: if handler.does_issue_exist(next_id): missing = handler.get_issue_from_issue_id(next_id) to_add.append(missing) ids.append(next_id) for issue in to_add: conflicts.append(issue) ids.append(issue.id) complete = len(to_add) == 0 conflicts.sort(key=lambda x: x.date) sorted_ids = list(set(ids)) sorted_ids.sort() assert len(sorted_ids) >= len(conflicts) index = 0 for issue in conflicts: new_id = sorted_ids[index] issue.id = new_id tracker.track_or_update_uuid(issue.uuid, new_id) index += 1 return CreateResolutionTool(conflicts, tracker)