Skip to content
This repository has been archived by the owner on May 4, 2021. It is now read-only.

Commit

Permalink
Fixed bug and code coverage due to SQLAlchemy returning UUID objects …
Browse files Browse the repository at this point in the history
…vs strings
  • Loading branch information
Dantemss committed Sep 10, 2019
1 parent c0fa035 commit 2cd9400
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 4 deletions.
1 change: 0 additions & 1 deletion sparfa_server/biglearn/clients.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
from logging import getLogger
from json import dumps
from requests import Session

from .. import __version__
Expand Down
7 changes: 5 additions & 2 deletions sparfa_server/tasks/calcs.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,16 +148,19 @@ def calculate_exercises():
)

response_dicts_by_calculation_uuid = defaultdict(list)
# Beware that uuid columns return UUID objects (not strings) when using from_statement()
for result in session.query('calculation_uuid', Response).from_statement(text(dedent("""
SELECT "values"."calculation_uuid", "responses".*
FROM "responses" INNER JOIN (VALUES {}) AS "values"
("calculation_uuid", "ecosystem_uuid", "student_uuid")
ON "responses"."student_uuid" = "values"."student_uuid"
AND "responses"."ecosystem_uuid" = "values"."ecosystem_uuid"
""".format(', '.join(calculation_values))).strip())).all():
calc_uuid = result.calculation_uuid
calc_uuid = str(result.calculation_uuid)
response = result.Response
if response.exercise_uuid in known_exercise_uuids_by_calculation_uuid[calc_uuid]:
if str(
response.exercise_uuid
) in known_exercise_uuids_by_calculation_uuid[calc_uuid]:
response_dicts_by_calculation_uuid[calc_uuid].append(response.dict_for_algs)

exercise_calculation_requests = []
Expand Down
7 changes: 6 additions & 1 deletion tests/unit/tasks/test_calcs.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,12 @@


def test_calculate_ecosystem_matrices(transaction):
ecosystem_1 = Ecosystem(uuid=str(uuid4()), metadata_sequence_number=0, sequence_number=1)
ecosystem_1 = Ecosystem(
uuid=str(uuid4()),
metadata_sequence_number=0,
sequence_number=1,
last_ecosystem_matrix_update_calculation_uuid=str(uuid4())
)

calculation_uuid = str(uuid4())
ecosystem_matrix_updates = [{
Expand Down

0 comments on commit 2cd9400

Please sign in to comment.