def test_register_with_full_commit(self, client, **kwargs): git_commit = Commit( repository_id='safari', branch='main', hash='8eba280e32daaf5fddbbb65aea37932ea9ad85df', timestamp=1601650100, order=0, author='*****@*****.**', message='custom commit', ) print(Commit.Encoder().default(git_commit)) self.assertEqual( 200, client.post(self.URL + '/api/commits', json=Commit.Encoder().default(git_commit)).status_code) response = client.get(self.URL + '/api/commits?repository_id=safari') self.assertEqual(200, response.status_code) self.assertEqual(Commit.from_json(response.json()[0]), git_commit) svn_commit = Commit( repository_id='webkit', branch='main', revision='1234', timestamp=1601650100, order=0, author='*****@*****.**', message='custom commit', ) self.assertEqual( 200, client.post(self.URL + '/api/commits', json=Commit.Encoder().default(svn_commit)).status_code) response = client.get(self.URL + '/api/commits?repository_id=webkit') self.assertEqual(200, response.status_code) self.assertEqual(Commit.from_json(response.json()[0]), svn_commit)
def test_commits_branch(self): with mocks.remote.Svn(), OutputCapture(): svn = remote.Svn(self.remote) self.assertEqual(Commit.Encoder().default([ svn.commit(revision='r7'), svn.commit(revision='r3'), svn.commit(revision='r2'), svn.commit(revision='r1'), ]), Commit.Encoder().default(list(svn.commits(begin=dict(argument='r1'), end=dict(argument='r7')))))
def test_commits(self): with mocks.local.Svn(self.path), OutputCapture(): svn = local.Svn(self.path) self.assertEqual(Commit.Encoder().default([ svn.commit(revision='r6'), svn.commit(revision='r4'), svn.commit(revision='r2'), svn.commit(revision='r1'), ]), Commit.Encoder().default(list(svn.commits(begin=dict(revision='r1'), end=dict(revision='r6')))))
def test_commits(self): self.maxDiff = None with mocks.remote.Svn(): svn = remote.Svn(self.remote) self.assertEqual(Commit.Encoder().default([ svn.commit(revision='r6'), svn.commit(revision='r4'), svn.commit(revision='r2'), svn.commit(revision='r1'), ]), Commit.Encoder().default(list(svn.commits(begin=dict(revision='r1'), end=dict(revision='r6')))))
def test_commits_branch(self): with mocks.remote.GitHub(): git = remote.GitHub(self.remote) self.assertEqual( Commit.Encoder().default([ git.commit(hash='621652ad'), git.commit(hash='a30ce849'), git.commit(hash='fff83bb2'), git.commit(hash='9b8311f2'), ]), Commit.Encoder().default( list( git.commits(begin=dict(argument='9b8311f2'), end=dict(argument='621652ad')))))
def test_commits(self): with mocks.remote.GitHub(): git = remote.GitHub(self.remote) self.assertEqual( Commit.Encoder().default([ git.commit(hash='bae5d1e9'), git.commit(hash='1abe25b4'), git.commit(hash='fff83bb2'), git.commit(hash='9b8311f2'), ]), Commit.Encoder().default( list( git.commits(begin=dict(hash='9b8311f2'), end=dict(hash='bae5d1e9')))))
def find(self): AssertRequest.is_type() result = self._find(**request.args.to_dict(flat=False)) if not result: abort( 404, description='No commits found matching the specified criteria') return jsonify(Commit.Encoder().default(result))
def test_commits_branch(self): for mock in [ mocks.local.Git(self.path), mocks.local.Git(self.path, git_svn=True) ]: with mock: git = local.Git(self.path) self.assertEqual( Commit.Encoder().default([ git.commit(hash='621652ad'), git.commit(hash='a30ce849'), git.commit(hash='fff83bb2'), git.commit(hash='9b8311f2'), ]), Commit.Encoder().default( list( git.commits(begin=dict(argument='9b8311f2'), end=dict(argument='621652ad')))))
def test_commits(self): for mock in [ mocks.local.Git(self.path), mocks.local.Git(self.path, git_svn=True) ]: with mock: git = local.Git(self.path) self.assertEqual( Commit.Encoder().default([ git.commit(hash='bae5d1e9'), git.commit(hash='1abe25b4'), git.commit(hash='fff83bb2'), git.commit(hash='9b8311f2'), ]), Commit.Encoder().default( list( git.commits(begin=dict(hash='9b8311f2'), end=dict(hash='bae5d1e9')))))
def commit(self, **kwargs): with self.commit_context: commit = self._single_commit() repositories = list(self.commit_context.repositories.keys()) repositories.remove(commit.repository_id) siblings = self.commit_context.sibling_commits( commit, repositories) repositories = [commit.repository_id] + sorted( [str(key) for key, lst in siblings.items() if lst]) return self.environment.get_template('commit.html').render( title=self.site_menu.title + ': ' + str(commit), commit=commit, repository_ids=repositories, commits=Commit.Encoder().default( [commit] + [item for lst in siblings.values() for item in lst]), **kwargs)
def previous(self, limit=None, **kwargs): AssertRequest.is_type() AssertRequest.query_kwargs_empty(limit=limit) with self.commit_context: commits = self._find(**kwargs) if not commits: abort(404, description= 'No commits found matching the specified criteria') if len(commits) > 1: abort( 404, description= f'{len(commits)} commits found matching the specified criteria' ) commit = self.commit_context.previous_commit(commits[0]) return jsonify( Commit.Encoder().default([commit] if commit else []))
def siblings(self, limit=None, **kwargs): AssertRequest.is_type() AssertRequest.query_kwargs_empty(limit=limit) with self.commit_context: commits = self._find(**kwargs) if not commits: abort(404, description= 'No commits found matching the specified criteria') if len(commits) > 1: abort( 404, description= f'{len(commits)} commits found matching the specified criteria' ) repositories = sorted(self.commit_context.repositories.keys()) repositories.remove(commits[0].repository_id) return jsonify(Commit.Encoder().default( self.commit_context.sibling_commits(commits[0], repositories)))