def test_prefix_ambiguous(self): repository = self._create_repository() revision_1 = self.create_revision(repository=repository, sha=self.sha) revision_2 = self.create_revision(repository=repository, sha=self.sha_similiar) with pytest.raises(MultipleResultsFound): Revision.get_by_sha_prefix_query(repository.id, '73a5').scalar()
def get(self, project_id, commit_id): project = Project.get(project_id) if not project: return '', 404 repo = project.repository try: revision = Revision.get_by_sha_prefix_query( repo.id, commit_id, ).options( joinedload('author') ).scalar() except MultipleResultsFound: return '', 404 else: if not revision: return '', 404 context = self.serialize(revision) context.update({ 'repository': repo, }) return self.respond(context)
def revision(repository, author, message=None): message = message or '\n\n'.join(get_paragraphs(2)) result = Revision( repository=repository, sha=uuid4().hex, author=author, repository_id=repository.id, author_id=author.id, message=message, branches=['default', 'foobar'], ) db.session.add(result) return result
def revision(repository, author): result = Revision( repository=repository, sha=uuid4().hex, author=author, message='\n\n'.join(get_paragraphs(2)), branches=['default', 'foobar'], ) db.session.add(result) return result
def create_revision(self, **kwargs): kwargs.setdefault('sha', uuid4().hex) if not kwargs.get('repository'): kwargs['repository'] = self.create_repo() kwargs['repository_id'] = kwargs['repository'].id if not kwargs.get('author'): kwargs['author'] = self.create_author() kwargs['author_id'] = kwargs['author'].id if not kwargs.get('message'): message = get_sentences(1)[0][:128] + '\n' message += '\n\n'.join(get_paragraphs(2)) kwargs['message'] = message revision = Revision(**kwargs) db.session.add(revision) db.session.commit() return revision
def test_simple(): revision = Revision( sha='33846695b2774b29a71795a009e8168a', repository=Repository(), author=Author( name='Foo Bar', email='*****@*****.**', ), parents=['a' * 40], branches=['master'], message='hello world', date_created=datetime(2013, 9, 19, 22, 15, 22), ) result = serialize(revision) assert result['id'] == '33846695b2774b29a71795a009e8168a' assert result['author']['name'] == 'Foo Bar' assert result['author']['email'] == '*****@*****.**' assert result['message'] == 'hello world' assert result['dateCreated'] == '2013-09-19T22:15:22' assert result['parents'] == ['a' * 40] assert result['branches'] == ['master']
def get(self, project_id, commit_id): project = Project.get(project_id) if not project: return '', 404 repo = project.repository try: revision = Revision.get_by_sha_prefix_query( repo.id, commit_id, ).options(joinedload('author')).scalar() except MultipleResultsFound: return '', 404 else: if not revision: return '', 404 context = self.serialize(revision) context.update({ 'repository': repo, }) return self.respond(context)
def test_prefix_full(self): repository = self._create_repository() revision = self.create_revision(repository=repository, sha=self.sha) assert Revision.get_by_sha_prefix_query(repository.id, self.sha).scalar() == revision