Skip to content

Commit

Permalink
Merge pull request #28 from CSC-510-G55/p2/pytest
Browse files Browse the repository at this point in the history
chore: new test cases
  • Loading branch information
balaji305 authored Nov 2, 2024
2 parents 55a7432 + a40dbce commit c0acd2d
Showing 1 changed file with 2 additions and 92 deletions.
94 changes: 2 additions & 92 deletions backend/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,68 +159,6 @@ def delete_auth_token(token_to_delete, user_id):
def health_check():
return jsonify({"message": "Server up and running"}), 200

@app.route("/users/signupGoogle")
def signupGoogle():

oauth.register(
name="google",
client_id=GOOGLE_CLIENT_ID,
client_secret=GOOGLE_CLIENT_SECRET,
server_metadata_url=CONF_URL,
client_kwargs={"scope": "openid email profile"},
nonce="foobar",
)

# Redirect to google_auth function
redirect_uri = url_for("authorized", _external=True)
print(redirect_uri)

session["nonce"] = generate_token()
return oauth.google.authorize_redirect(redirect_uri, nonce=session["nonce"])

@app.route("/users/signupGoogle/authorized")
def authorized():
token = oauth.google.authorize_access_token()
user = oauth.google.parse_id_token(token, nonce=session["nonce"])
session["user"] = user

user_exists = Users.objects(email=user["email"]).first()

users_email = user["email"]
full_name = user["given_name"] + " " + user["family_name"]

if user["email_verified"]:
if user_exists is None:
userSave = Users(
id=get_new_user_id(),
fullName=full_name,
email=users_email,
authTokens=[],
applications=[],
skills=[],
job_levels=[],
locations=[],
phone_number="",
address="",
)
userSave.save()
unique_id = userSave["id"]
else:
unique_id = user_exists["id"]

userSaved = Users.objects(email=user["email"]).first()
expiry = datetime.now() + timedelta(days=1)
expiry_str = expiry.strftime("%m/%d/%Y, %H:%M:%S")
token_whole = str(unique_id) + "." + token["access_token"]
auth_tokens_new = userSaved["authTokens"] + [
{"token": token_whole, "expiry": expiry_str}
]
userSaved.update(authTokens=auth_tokens_new)

return redirect(
f"{os.environ.get("BASE_FRONTEND_URL")}/?token={token_whole}&expiry={expiry_str}&userId={unique_id}"
)

@app.route("/users/signup", methods=["POST"])
def sign_up():
"""
Expand Down Expand Up @@ -312,13 +250,6 @@ def updateProfilePreferences():
for key in data.keys():
user[key] = data[key]

if (
"picture" in data
and data["picture"]
and not data["picture"].startswith("data:image/png;base64,")
):
return jsonify({"error": "Invalid image format"}), 400

user.save()
return jsonify(user.to_json()), 200

Expand Down Expand Up @@ -715,14 +646,7 @@ def upload_resume():
@app.route("/resumeTemplates", methods=["GET"])
def get_resume_templates():
"""
Flask route to get a list of available resume templates.
This route handles GET requests to the "/resumeTemplates" endpoint and returns a list of available resume templates.
A resume template is considered available if it is a directory within the `../resume_templates` directory and contains a "sample.pdf" file.
Returns:
tuple: A list of available resume template names and an HTTP status code 200 on success.
If an error occurs, returns a JSON response with an error message and an HTTP status code 500.
Returns a list of available resume templates
"""
try:
base_path = "../resume_templates"
Expand All @@ -741,17 +665,7 @@ def get_resume_templates():
@app.route("/generateResume", methods=["POST"])
def generate_resume():
"""
Generates a resume based on the provided template and user data.
This endpoint expects a POST request with a JSON body containing the template name.
It retrieves the user data from the database, processes it according to the specified
template, and generates a PDF resume.
Returns:
Response: A PDF file of the generated resume.
Raises:
Exception: If there is an error during the resume generation process, a 500 Internal Server Error is returned.
Generates a resume based on the provided template and user data
"""
try:
userid = get_userid_from_header()
Expand All @@ -765,10 +679,6 @@ def generate_resume():

# Copy the template files to the temp directory
template_dir = f"../resume_templates/{template_name}"

if not template_name or not os.path.exists(template_dir):
return jsonify({"error": "Template not found"}), 404

for item in os.listdir(template_dir):
s = os.path.join(template_dir, item)
d = os.path.join(temp_dir, item)
Expand Down

0 comments on commit c0acd2d

Please sign in to comment.