示例#1
0
def make_comment_test():
    """
    Tests /project/<id>/comments endpoint, with a valid request.
    """
    add_project("111", "Test Project", "*****@*****.**",
                "8bde3e84-a964-479c-9c7b-4d7991717a1b")
    path = BASE_URL + "/projects/111/comments"

    for access_token, username in [(ACCESS_TOKEN_1, USERNAME_1),
                                   (ACCESS_TOKEN_2, USERNAME_2)]:
        headers = {
            "Accept": "application/json",
            "Content-Type": "application/json",
            "Authorization": "Bearer " + access_token
        }

        r = requests.post(path,
                          headers=headers,
                          data=json.dumps(
                              {"message": 'Comments are great ' + username}))
        data = r.json()
        for k in data:
            print k, data[k]
    print("here are the comments:")
    print(get_comments_for_project("111"))
    delete_project("111")
示例#2
0
def complete_sync():
    global git
    with open('app.json') as raw:
        data = json.loads(raw.read())
        git = Github(data['githubAccessToken'])
    raw.close()

    # Do a complete sync of all metadata
    for org in data['organizations']:
        print("# Organisation: %s" % org)
        orgobj = git.get_organization(org)
        db.add_organization(org, vars(orgobj)['_rawData'])

        for project in orgobj.get_repos(type='all'):
            print("## Project: %s" % project.name)
            db.add_project(org, project.name, vars(project)['_rawData'])

            # Add all the project data
            db.add_branches(org, project.name, project.get_branches())
            db.add_collaborators(org, project.name,
                                 project.get_collaborators())
            db.add_commits(org, project.name, project.get_commits())
            db.add_contributors(org, project.name, project.get_contributors())
            db.add_issues(org, project.name, project.get_issues())
            db.add_languages(project.name, project.get_languages())
            db.add_prs(org, project.name, project.get_pulls())
            db.add_stars(project.name, project.get_stargazers())
示例#3
0
文件: projects.py 项目: 380sq/minim
def index():
    error = None
    if request.method == "POST":
        project_path_with_namespace = request.form.get('path_with_namespace')
        if project_path_with_namespace is not None:
            err, project = gitlab_get_project(project_path_with_namespace)
            if err:
                error = json.dumps(err)
            else:
                add_project(project)
        else:
            error = "no project selected"

    projects = get_projects()

    return render_template('index.html', projects=projects, error=error)
示例#4
0
def project_post(r):
    """
    POST request to projects.
    Reponse contains
    project_id: the project id of the submitted project
    owner_id: owner of the submitted project.
    owner_username: username of the owner
    project_name: name of the submitted project
    comments: Comments on the project, initialized to an empty list.
    """
    # get bearer token from auth header
    auth_header = request.headers.get("authorization")
    access_token = auth_header[len("Bearer "):]

    # get username and user id to respond with
    try:
        user_info = get_user_info(access_token)
    except ValueError:
        return bad_auth()

    username = user_info["username"]
    user_id = user_info["user_id"]
    print("Posting user ID is {}.".format(user_id))

    data = json.loads(r.data)
    # Make a unique identifier for the new project
    project_id = str(uuid.uuid1())
    if 'project_name' not in data:
        return bad_request()
    project_name = data['project_name']

    # Actually add the project to the database
    add_project(project_id, project_name, username, user_id)

    response_dict = {
        "message": "Post Projects",
        "project_id": project_id,
        "owner_id": user_id,
        "owner_username": username,
        "project_name": project_name,
        "comments": []
    }
    return Response(json.dumps(response_dict),
                    status=200,
                    mimetype='application/json')
示例#5
0
def delete_project_test():
    add_project("111", "Test Project", "*****@*****.**",
                "8bde3e84-a964-479c-9c7b-4d7991717a1b")
    add_comment("0", "55555", "fake user", "fake user's message", "111")
    add_comment("1", "55555", "fake user", "fake user's second message", "111")
    add_comment("2", "55555", "fake user", "fake user's last message", "111")
    path = BASE_URL + "/projects/111"

    headers = {
        "Accept": "application/json",
        "Content-Type": "application/json",
        "Authorization": "Bearer " + ACCESS_TOKEN_1
    }

    r = requests.delete(path, headers=headers)
    data = r.json()
    for k in data:
        print k, data[k]
示例#6
0
def add_project(conn, owner_id, project_name):
    """add_project - Add a new project
    :param conn: sqllite3 db connection
    :param owner_id: (string) owner's uuid
    :param project_name: (string) name of new project
    :return: a dict with the project / owner info
    """

    # Passed authorization, so add this project
    project_id = str(uuid.uuid1())
    return db.add_project(conn, project_id, owner_id, project_name)
示例#7
0
def get_project_test():
    """
    Tests get method on /projects/<id> endpoint.
    """
    add_project("111", "Test Project", "*****@*****.**",
                "8bde3e84-a964-479c-9c7b-4d7991717a1b")
    add_comment("0", "55555", "fake user", "fake user's message", "111")
    add_comment("1", "55555", "fake user", "fake user's second message", "111")
    add_comment("2", "55555", "fake user", "fake user's last message", "111")
    path = BASE_URL + "/projects/111"

    for access_token, username in [(ACCESS_TOKEN_1, USERNAME_1),
                                   (ACCESS_TOKEN_2, USERNAME_2)]:
        headers = {
            "Accept": "application/json",
            "Content-Type": "application/json",
            "Authorization": "Bearer " + access_token
        }

        r = requests.get(path, headers=headers)
        data = r.json()
        for k in data:
            print k, data[k]
    delete_project("111")