Skip to content
This repository was archived by the owner on Dec 8, 2022. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions CodeChallenge/api/vote.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,21 @@ def get_contestants():

contestants = []
for ans in p.items: # type: Answer

display = None
if ans.user.studentfirstname \
and ans.user.studentlastname:
display = f"{ans.user.studentfirstname} " \
f"{ans.user.studentlastname[0]}."

contestants.append(dict(
id=ans.id,
text=ans.text,
numVotes=len(ans.votes),
firstName=ans.user.studentfirstname,
lastName=ans.user.studentlastname,
username=ans.user.username,
display=display
))

return jsonify(
Expand Down
1 change: 1 addition & 0 deletions CodeChallenge/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ class Answer(db.Model):
text = db.Column(db.String(2000))
correct = db.Column(db.Boolean)
question = db.relationship("Question", lazy=True, uselist=False)
user = db.relationship("Users", lazy=True, uselist=False)
votes = db.relationship("Vote", cascade="all,delete",
lazy=True, uselist=True)

Expand Down
7 changes: 6 additions & 1 deletion tests/test_question.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ def register(client, email, username, password, firstname, lastname, studentemai
return client.post("/api/v1/users/register", json=dict(
username=username, parentEmail=email, password=password,
parentFirstName=firstname, parentLastName=lastname, DOB="1994-04-13",
studentEmail=studentemail
studentEmail=studentemail, studentFirstName="Sam", studentLastName="Hoffman"
), follow_redirects=True)


Expand Down Expand Up @@ -364,6 +364,11 @@ def test_vote_ballot(client_challenge_lastq):
assert "id" in items[0]
assert "numVotes" in items[0]
assert "text" in items[0]
assert items[0]["firstName"] == "Sam"
assert items[0]["lastName"] == "Hoffman"
assert items[0]["username"] == "cwhqsam"
assert items[0]["display"] == "Sam H."

VALID_ANSWER = items[0]["id"]


Expand Down