Example #1
0
    def test_complete_payload(self, client, session):
        pull_request = models.PullRequest(state=models.PRStatus.OPEN,
                                          number=1,
                                          merged=False,
                                          head_sha='abcdef12345',
                                          base_sha='12345abcdef',
                                          title='abc',
                                          head_repo_id=1,
                                          base_repo_id=1,
                                          head_branch='foo',
                                          base_branch='bar',
                                          created_at=datetime.now(),
                                          updated_at=datetime.now(),
                                          id=1)
        session.add(pull_request)
        session.commit()

        rv = client.post('/api/stability',
                         data=json.dumps(stability_payload),
                         content_type='application/json')

        stability_statuses = session.query(models.StabilityStatus).filter(
            models.StabilityStatus.job_id == 2,
            models.StabilityStatus.test_id == 'curb the dog').all()

        assert len(stability_statuses) == 2
Example #2
0
    def test_builds(self, client, session):
        """PR detail route displays builds when they exist."""
        owner = models.GitHubUser(login='******')
        head_repo = models.Repository(name='bar', owner=owner)
        base_repo = models.Repository(name='baz', owner=owner)
        pull_request = models.PullRequest(state=models.PRStatus.OPEN,
                                          number=1,
                                          merged=False,
                                          head_sha='abcdef12345',
                                          base_sha='12345abcdef',
                                          title='abc',
                                          head_repository=head_repo,
                                          base_repository=base_repo,
                                          head_branch='foo',
                                          base_branch='bar',
                                          created_at=datetime.now(),
                                          updated_at=datetime.now(),
                                          id=1)
        build = models.Build(number=123,
                             status=models.BuildStatus.PENDING,
                             started_at=datetime.now())

        pull_request.builds = [build]

        session.add(pull_request)
        session.commit()

        rv = client.get('/pull/1')
        assert b'Build Number' in rv.data
Example #3
0
    def test_complete_payload(self, client, session):
        pull_request = models.PullRequest(state=models.PRStatus.OPEN,
                                          number=1,
                                          merged=False,
                                          head_sha='abcdef12345',
                                          base_sha='12345abcdef',
                                          title='abc',
                                          head_repo_id=1,
                                          base_repo_id=1,
                                          head_branch='foo',
                                          base_branch='bar',
                                          created_at=datetime.now(),
                                          updated_at=datetime.now(),
                                          id=1)
        session.add(pull_request)
        session.commit()

        payload = {'issue_number': 1, 'url': 'abc'}
        rv = client.post('/api/test-mirror',
                         data=json.dumps(payload),
                         content_type='application/json')

        mirror = session.query(models.TestMirror).filter(
            models.TestMirror.pull_id == 1).one_or_none()

        assert mirror
        assert mirror.url == 'abc'
Example #4
0
    def test_no_jobs(self, client, session):
        """Build detail route says "No jobs" when pull has no job info."""
        owner = models.GitHubUser(login='******')
        head_repo = models.Repository(name='bar', owner=owner)
        base_repo = models.Repository(name='baz', owner=owner)
        pull_request = models.PullRequest(state=models.PRStatus.OPEN,
                                          number=1,
                                          merged=False,
                                          head_sha='abcdef12345',
                                          base_sha='12345abcdef',
                                          title='abc',
                                          head_repository=head_repo,
                                          base_repository=base_repo,
                                          head_branch='foo',
                                          base_branch='bar',
                                          created_at=datetime.now(),
                                          updated_at=datetime.now())
        build = models.Build(number=123,
                             status=models.BuildStatus.PENDING,
                             started_at=datetime.now(),
                             id=1,
                             pull_request=pull_request,
                             jobs=[])
        session.add(build)
        session.commit()

        rv = client.get('/build/123')
        assert b'No jobs' in rv.data
Example #5
0
    def test_pull_request_no_updated_at(self, session):
        """A pull_request without updated_at should throw Integrity Error."""
        pull_request = models.PullRequest(state=models.PRStatus.OPEN, number=1,
                                          merged=False, head_sha='abcdef12345',
                                          base_sha='12345abcdef', title='abc',
                                          head_repo_id=1, base_repo_id=1,
                                          head_branch='foo', base_branch='bar',
                                          created_at=datetime.now())

        session.add(pull_request)
        with pytest.raises(sqlalchemy.exc.IntegrityError):
            session.commit()
Example #6
0
    def test_pull_request_complete(self, session):
        """A pull_request with all required fields should be added to DB."""
        pull_request = models.PullRequest(state=models.PRStatus.OPEN, number=1,
                                          merged=False, head_sha='abcdef12345',
                                          base_sha='12345abcdef', title='abc',
                                          head_repo_id=1, base_repo_id=1,
                                          head_branch='foo', base_branch='bar',
                                          created_at=datetime.now(),
                                          updated_at=datetime.now())

        session.add(pull_request)
        session.commit()

        pull_requests = session.query(models.PullRequest).all()
        assert pull_request in pull_requests
Example #7
0
    def test_pulls(self, client, session):
        pull_request = models.PullRequest(state=models.PRStatus.OPEN,
                                          number=1,
                                          merged=False,
                                          head_sha='abcdef12345',
                                          base_sha='12345abcdef',
                                          title='abc',
                                          head_repo_id=1,
                                          base_repo_id=1,
                                          head_branch='foo',
                                          base_branch='bar',
                                          created_at=datetime.now(),
                                          updated_at=datetime.now())
        session.add(pull_request)
        session.commit()

        rv = client.get('/')
        assert b'Pull Request' in rv.data
Example #8
0
    def test_jobs(self, client, session):
        """Build detail route displays jobs when they exist."""
        owner = models.GitHubUser(login='******')
        head_repo = models.Repository(name='bar', owner=owner)
        base_repo = models.Repository(name='baz', owner=owner)
        pull_request = models.PullRequest(state=models.PRStatus.OPEN,
                                          number=1,
                                          merged=False,
                                          head_sha='abcdef12345',
                                          base_sha='12345abcdef',
                                          title='abc',
                                          head_repository=head_repo,
                                          base_repository=base_repo,
                                          head_branch='foo',
                                          base_branch='bar',
                                          created_at=datetime.now(),
                                          updated_at=datetime.now())
        build = models.Build(number=123,
                             status=models.BuildStatus.PENDING,
                             started_at=datetime.now(),
                             id=1,
                             pull_request=pull_request)

        product = models.Product(name='test:unstable')
        job = models.Job(number=1.1,
                         build=build,
                         product=product,
                         state=models.JobStatus.PASSED,
                         allow_failure=True,
                         started_at=datetime.now(),
                         finished_at=datetime.now())

        build.jobs = [job]

        session.add(build)
        session.commit()

        rv = client.get('/build/123')
        assert b'Job Number' in rv.data
Example #9
0
    def test_no_builds(self, client, session):
        """PR detail route says "No builds" when pull has no build info."""
        owner = models.GitHubUser(login='******')
        head_repo = models.Repository(name='bar', owner=owner)
        base_repo = models.Repository(name='baz', owner=owner)
        pull_request = models.PullRequest(state=models.PRStatus.OPEN,
                                          number=1,
                                          merged=False,
                                          head_sha='abcdef12345',
                                          base_sha='12345abcdef',
                                          title='abc',
                                          head_repository=head_repo,
                                          base_repository=base_repo,
                                          head_branch='foo',
                                          base_branch='bar',
                                          created_at=datetime.now(),
                                          updated_at=datetime.now(),
                                          id=1)
        session.add(pull_request)
        session.commit()

        rv = client.get('/pull/1')
        assert b'No builds' in rv.data