Beispiel #1
0
 def test_login_with_proper_credentials(self):
     service = Service()
     response = service.login({
         "email": "*****@*****.**",
         "password": "******"
     })
     assert isinstance(response, object)
     assert response.token is not None
Beispiel #2
0
 def test_login_with_invalid_email_id(self):
     service = Service()
     response = service.login({
         "email": "*****@*****.**",
         "password": "******"
     })
     assert isinstance(response, str)
     assert response == "User not available"
Beispiel #3
0
 def test_login_with_wrong_password(self):
     service = Service()
     response = service.login({
         "email": "*****@*****.**",
         "password": "******"
     })
     assert isinstance(response, str)
     assert response == "Invalid Credentials"
Beispiel #4
0
def register():
    try:
        service = Service()
        data = request.json
        response = service.register(data)
        if isinstance(response, User):
            return jsonpickle.encode(response, unpicklable=False), 200
        else:
            return jsonify({'Error': response}), 500
    except Exception as e:
        return jsonify(e), 500
def register_fb_user():
    data = request.json
    try:
        response = Service.register_fb_user(data)
        if (response):
            response = Service.check_fb_user_existence(data['email'])
            return jsonpickle.encode(response, unpicklable=False), 200
        else:
            return jsonify({"Error": "Something went wrong"}), 500
    except Exception as e:
        return jsonify(e), 500
Beispiel #6
0
def check():
    data = request.json
    try:
        service = Service()
        response = service.login(data)
        if isinstance(response, User):
            return jsonpickle.encode(response, unpicklable=False), 200
        else:
            return jsonify({'Error': response}), 500
    except Exception as e:
        return jsonify(e), 500
 def test_registration_with_improper_email_id(self):
     service = Service()
     response = service.register({
         "email": "jhon_gmail.com",
         "password": "******",
         "firstName": "Jhon",
         "lastName": "Smith",
         "confirmPassword": "******",
         "dob": "11/02/1994"
     })
     assert isinstance(response, str)
     assert response == "Please enter proper email address"
 def test_registration_with_positive_scenarios(self):
     service = Service()
     response = service.register({
         "email": "*****@*****.**",
         "password": "******",
         "firstName": "Jhon",
         "lastName": "Smith",
         "confirmPassword": "******",
         "dob": "11/02/1994"
     })
     assert isinstance(response, object)
     assert response.user_id is not None
 def test_registration_with_mismatch_password(self):
     service = Service()
     response = service.register({
         "email": "*****@*****.**",
         "password": "******",
         "firstName": "Jhon",
         "lastName": "Smith",
         "confirmPassword": "******",
         "dob": "11/02/1994"
     })
     assert isinstance(response, str)
     assert response == "Password did not match"
def update_gpa_by_course(courseId, userId, gpa):
    try:
        token = request.headers.get('Authorization')
        if (Service.auth_token(token)):
            response = Service.update_gpa_by_course(courseId, userId, gpa)
            if (response):
                return jsonpickle.encode(response, unpicklable=False), 200
            else:
                return jsonify({'Error': 'Something went wrong'}), 500
        else:
            return jsonify({'Error': 'Unauthorized'}), 500
    except Exception as e:
        return jsonify(e), 500
def get_profile_details(userId, roleId):
    try:
        token = request.headers.get('Authorization')
        if (Service.auth_token(token)):
            response = Service.get_profile_details(userId, roleId)
            if (response):
                return jsonpickle.encode(response, unpicklable=False), 200
            else:
                return jsonify({'Error': 'Something went wrong'}), 500
        else:
            return jsonify({'Error': 'Unauthorized'}), 500
    except Exception as e:
        return jsonify(e), 500
def semesters():
    data = request.json
    try:
        token = request.headers.get('Authorization')
        if (Service.auth_token(token)):
            response = Service.semesters()
            if (response):
                return jsonpickle.encode(response, unpicklable=False), 200
            else:
                return jsonify({'Error': 'Something went wrong'}), 500
        else:
            return jsonify({'Error': 'Unauthorized'}), 500
    except Exception as e:
        return jsonify(e), 500
def save_comment():
    data = request.json
    try:
        token = request.headers.get('Authorization')
        if (Service.auth_token(token)):
            response = Service.save_comment(data)
            if (response == True):
                return jsonify({'data': data}), 200
            else:
                return jsonify({'Error': 'Something went wrong'}), 500
        else:
            return jsonify({'Error': 'Unauthorized'}), 500
    except Exception as e:
        return jsonify(e), 500
def update_password():
    try:
        data = request.json
        response = Service.update_password(data['password'], data['email'])
        return jsonify({'wasUpdateSuccessful': response}), 200
    except Exception as e:
        return jsonify(e), 500
def verify_security_answer():
    try:
        data = request.json
        response = Service.verify_security_answer(data['answer'],
                                                  data['email'])
        return jsonify({'wasAnswerCorrect': response}), 200
    except Exception as e:
        return jsonify(e), 500
def insert_courses():
    data = request.json
    try:
        token = request.headers.get('Authorization')
        if (Service.auth_token(token)):
            if (data['role_id'] == str(1)):
                response = Service.insert_courses(data)
                if (response == True):
                    return jsonify({'data': data}), 200
                else:
                    return jsonify({'Error': 'Something went wrong'}), 500
            else:
                return jsonify({'Error': 'Unauthorized'}), 500
        else:
            return jsonify({'Error': 'Unauthorized'}), 500
    except Exception as e:
        return jsonify(e), 500
def security_question(email):
    try:
        response = Service.security_question(email)
        if (response):
            return jsonify({'question': response}), 200
        else:
            return jsonify({'Error': "response"}), 500
    except Exception as e:
        return jsonify(e), 500
def send_receipt(email, cost, faid, reg, pay):
    try:
        response = Service.send_receipt(email, cost, faid, reg, pay)
        if (response == True):
            return jsonify({'email': email}), 200
        else:
            return jsonify({'Error': response}), 500
    except Exception as e:
        return jsonify(e), 500
def check_fb_user_existence(email):
    try:
        response = Service.check_fb_user_existence(email)
        if (response):
            return jsonpickle.encode(response, unpicklable=False), 200
        else:
            return jsonify({"Error": "Something went wrong"}), 500
    except Exception as e:
        return jsonify(e), 500
def send_otp(email, answer):
    try:
        response = Service.send_otp(email, answer)
        if (response == True):
            return jsonify({'data': response}), 200
        else:
            return jsonify({'Error': response}), 500
    except Exception as e:
        return jsonify(e), 500
def personal_details():
    data = request.json
    try:
        token = request.headers.get('Authorization')
        if (Service.auth_token(token)):
            response = Service.personal_details(data)
            if (response == True):
                if (data['image']):
                    data[
                        'image'] = "https://s3.amazonaws.com/course-360/u" + str(
                            data['userId']) + ".jpg"
                return jsonify({'data': data}), 200
            else:
                return jsonify({'Error': 'Something went wrong'}), 500
        else:
            return jsonify({'Error': 'Unauthorized'}), 500
    except Exception as e:
        return jsonify(e), 500
def activate_user(email):
    try:
        response = Service.activate_user(email)
        if (response == True):
            #return redirect("http://course360.herokuapp.com/activated", code=200)
            return jsonify({'data': 'Your account is activated'}), 200
        else:
            return jsonify({'Error': "response"}), 500
    except Exception as e:
        return jsonify(e), 500
def check():
    data = request.json
    try:
        response = Service.login(data)
        if (response):
            return jsonpickle.encode(response, unpicklable=False), 200
        else:
            return jsonify({'Error': "Something Went Wrong"}), 500
    except Exception as e:
        return jsonify(e), 500
def register():
    try:
        data = request.json
        response = Service.register(app, data)

        if (response == True):
            return jsonify({'data': data}), 200
        else:
            return jsonify({'Error': response}), 500
    except Exception as e:
        return jsonify(e), 500
def update_color_theme(theme, student):
    auth_header = request.headers.get('Authorization')
    try:
        status = Jwt.decode_auth_token(auth_header)
        if (status):
            response = Service.update_color_theme(theme, student)
            if (response == True):
                return jsonpickle.encode(response, unpicklable=False), 200
            else:
                return jsonify({"Error": "Something went wrong"}), 500
        else:
            return jsonify({"Error": "Invalid token"}), 500
    except Exception as e:
        return jsonify(e), 500
def get_students_by_course(id):
    auth_header = request.headers.get('Authorization')
    try:
        status = Jwt.decode_auth_token(auth_header)
        if (status):
            response = Service.get_students_by_course(id)
            if (response):
                return jsonpickle.encode(response, unpicklable=False), 200
            else:
                return jsonify({"Error": "Something went wrong"}), 500
        else:
            return jsonify({"Error": "Invalid token"}), 500
    except Exception as e:
        return jsonify(e), 500
def get_all_professors(start, end):
    auth_header = request.headers.get('Authorization')
    try:
        status = Jwt.decode_auth_token(auth_header)
        if (status):
            response = Service.get_all("PROFESSORS", start, end)
            if (response):
                return jsonpickle.encode(response, unpicklable=False), 200
            else:
                return jsonify({"Error": "Something went wrong"}), 500
        else:
            return jsonify({"Error": "Invalid token"}), 500
    except Exception as e:
        return jsonify(e), 500
def delete_from_cart(course, user, sem):
    auth_header = request.headers.get('Authorization')
    try:
        status = Jwt.decode_auth_token(auth_header)
        if (status):
            response = Service.delete_from_cart(course, user, sem)
            if (response):
                return jsonify({"response": "Success"}), 200
            else:
                return jsonify({"Error": "Something went wrong"}), 500
        else:
            return jsonify({"Error": "Invalid token"}), 500
    except Exception as e:
        return jsonify(e), 500
def drop_course(course_id, user_id, sem):
    auth_header = request.headers.get('Authorization')
    data = request.json
    try:
        status = Jwt.decode_auth_token(auth_header)
        if (status):
            response = Service.delete_enrolled_course(user_id, course_id, sem)
            if (response):
                return jsonify({'Success': "Dropped the course"}), 200
            else:
                return jsonify({'Error': "Something went wrong"}), 500
        else:
            return jsonify({"Error": "Invalid token"}), 500
    except Exception as e:
        return jsonify(e), 500
def enroll_courses():
    auth_header = request.headers.get('Authorization')
    data = request.json
    try:
        status = Jwt.decode_auth_token(auth_header)
        if (status):
            response = Service.enroll_courses(data)
            if (response):
                return jsonpickle.encode(response, unpicklable=False), 200
            else:
                return jsonify({'Error': "Course timings clash"}), 500
        else:
            return jsonify({"Error": "Invalid token"}), 500
    except Exception as e:
        return jsonify(e), 500