Exemplo n.º 1
0
    def test_project_unique(self):
        db.session.add(Project('job1'))
        db.session.commit()

        with self.assertRaises(IntegrityError):
            db.session.add(Project('job1'))
            db.session.commit()
Exemplo n.º 2
0
    def test_list_triggers(self):
        p = Project('p')
        db.session.add(p)
        db.session.flush()
        db.session.add(ProjectTrigger('user', 1, p, 'repo', 'file', {}))
        db.session.add(ProjectTrigger('use4', 2, p, 'rep0', 'fil3', {}))
        db.session.commit()
        triggers = self.get_signed_json('/project-triggers/')
        self.assertEqual(2, len(triggers))
        self.assertIn('id', triggers[0])
        self.assertEqual('p', triggers[0]['project'])
        self.assertEqual('user', triggers[0]['user'])
        self.assertEqual('repo', triggers[0]['definition_repo'])
        self.assertEqual('git_poller', triggers[0]['type'])
        self.assertEqual({}, triggers[0]['secrets'])

        self.assertEqual('p', triggers[1]['project'])
        self.assertEqual('use4', triggers[1]['user'])
        self.assertEqual('rep0', triggers[1]['definition_repo'])
        self.assertEqual('github_pr', triggers[1]['type'])

        triggers = self.get_signed_json('/project-triggers/',
                                        query_string='type=git_poller')
        self.assertEqual(1, len(triggers))
        self.assertEqual('git_poller', triggers[0]['type'])
        self.assertEqual('file', triggers[0]['definition_file'])

        triggers = self.get_signed_json('/projects/p/triggers/',
                                        query_string='type=github_pr')
        self.assertEqual(1, len(triggers))
        self.assertEqual('rep0', triggers[0]['definition_repo'])

        r = self.client.get('/projects/p/triggers/')
        self.assertEqual(401, r.status_code)
Exemplo n.º 3
0
    def test_list_triggers(self):
        p = Project("p")
        db.session.add(p)
        db.session.flush()
        db.session.add(ProjectTrigger("user", 1, p, "repo", "file", {}))
        db.session.add(ProjectTrigger("use4", 2, p, "rep0", "fil3", {}))
        db.session.commit()
        triggers = self.get_signed_json("/project-triggers/")
        self.assertEqual(2, len(triggers))
        self.assertIn("id", triggers[0])
        self.assertEqual("p", triggers[0]["project"])
        self.assertEqual("user", triggers[0]["user"])
        self.assertEqual("repo", triggers[0]["definition_repo"])
        self.assertEqual("git_poller", triggers[0]["type"])
        self.assertEqual({}, triggers[0]["secrets"])

        self.assertEqual("p", triggers[1]["project"])
        self.assertEqual("use4", triggers[1]["user"])
        self.assertEqual("rep0", triggers[1]["definition_repo"])
        self.assertEqual("github_pr", triggers[1]["type"])

        triggers = self.get_signed_json("/project-triggers/",
                                        query_string="type=git_poller")
        self.assertEqual(1, len(triggers))
        self.assertEqual("git_poller", triggers[0]["type"])
        self.assertEqual("file", triggers[0]["definition_file"])

        triggers = self.get_signed_json("/projects/p/triggers/",
                                        query_string="type=github_pr")
        self.assertEqual(1, len(triggers))
        self.assertEqual("rep0", triggers[0]["definition_repo"])

        r = self.client.get("/projects/p/triggers/")
        self.assertEqual(401, r.status_code)
Exemplo n.º 4
0
def project_create():
    d = request.get_json() or {}
    proj = d.get('name')
    if not proj:
        raise ApiError(401, 'Missing required parameter: "name"')
    sync = d.get('synchronous-builds', False)

    permissions.assert_internal_user()
    db.session.add(Project(proj, sync))
    db.session.commit()

    url = url_for('api_project.project_get', proj=proj, _external=True)
    return jsendify({'url': url}, 201)
Exemplo n.º 5
0
 def test_simple(self):
     db.session.add(Project('job1'))
     db.session.commit()
     projs = Project.query.all()
     self.assertEqual(1, len(projs))
     self.assertEqual('job1', projs[0].name)
Exemplo n.º 6
0
 def create_projects(self, *names):
     for n in names:
         db.session.add(Project(n))
     db.session.commit()
Exemplo n.º 7
0
def project_create(name):
    db.session.add(Project(name))
    db.session.commit()