예제 #1
0
def make_submission(class_name, project_name):
    json_data = get_json_data()
    owner = json_data.get("owner")
    url_name = class_name + "_" + project_name
    parent_url = class_name + '/' + project_name
    dbw = DatabaseWrapper(GITOLITE_ADMIN_PATH, DATABASE_PORT)
    try:
        dbw.create_submission(url_name, project_name, parent_url, owner)
        return jsonify(submission_made=url_name)
    except UrlNameAlreadyTakenError as e:
        return jsonify({"error": "Url name was already taken!", "exception": str(e)}), 403
    except ProjectDoesNotExistError as e:
        return jsonify({"error": "That project does not exist!", "exception": str(e)}), 404
    except ClassDoesNotExistError as e:
        return jsonify({"error": "Class does not exist!", "exception": str(e)}), 404
    except UserDoesNotExistError as e:
        return jsonify({"error": "Sorry! You need to upload a public key in order to do this!", "exception": str(e)}), 400
    dbw.create_user("teacher2", "*****@*****.**", password, "Teacher", "Two")
    dbw.create_user("teacher_usable", "*****@*****.**", password, "Teacher", "Usable")
    dbw.create_user("student_usable", "*****@*****.**", password, "Student", "Usable")
    dbw.create_user("spencer", "*****@*****.**", password, "Spencer", "Hawkins")  # because of some hardcoded stuff, heh
    dbw.create_user("konrad", "*****@*****.**", password, "Konrad", "Ryce")  # because of some hardcoded stuff, heh

    dbw.create_class("intro_to_computers", "Introduction to Computers", "Introduction to Computers description", "teacher1")
    dbw.create_class("adv_computers", "Advanced Computers", "Advanced Computers description", "teacher2")
    dbw.create_class("test_class", "a test class usable for actual git tests", "description", "teacher_usable")

    dbw.add_student_to_class("intro_to_computers", "student1")
    dbw.add_student_to_class("adv_computers", "student2")
    dbw.add_student_to_class("test_class", "student_usable")

    dbw.create_project("turn_on_a_computer", "Turn on a computer", "Turn on a computer description",
                       "intro_to_computers", False, (datetime.datetime.now() + datetime.timedelta(days=5)).strftime("%Y-%m-%d"), "teacher1")

    dbw.create_project("use_a_computer", "Use a computer", "Use a computer description",
                       "adv_computers", False, (datetime.datetime.now() + datetime.timedelta(days=2)).strftime("%Y-%m-%d"), "teacher2")

    dbw.create_project("test_project", "a test project", "description",
                       "test_class", False, (datetime.datetime.now() + datetime.timedelta(days=2)).strftime("%Y-%m-%d"), "teacher_usable")

    dbw.ssh_host = args.ssh_host
    dbw.create_submission("turned_on_a_computer", "Student 1 turned on a computer", "intro_to_computers/turn_on_a_computer", "student1")
    dbw.create_submission("used_a_computer", "Student 2 used a computer", "adv_computers/use_a_computer", "student2")
    dbw.create_submission("test_submission", "a test submission", "test_class/test_project", "student_usable")