def test_action_find_by_action_distinguish_actions(db, assignment_tree, user_johaannes): # Add a fetched action orm_action = Action( user_id=user_johaannes.id, assignment_id=assignment_tree.id, action=AssignmentActions.fetched, location="/some/random/path/to/a/file.tzg", ) db.add(orm_action) db.commit() found_by_pk = Action.find_by_pk(db, 1) # Without an action, we just get the last action found_recent = Action.find_most_recent_action(db, found_by_pk.assignment_id) assert found_recent.action == AssignmentActions.fetched # We can get different entries if we define the action found_recent_a = Action.find_most_recent_action(db, found_by_pk.assignment_id, AssignmentActions.fetched) assert found_recent_a.action == AssignmentActions.fetched found_recent_b = Action.find_most_recent_action(db, found_by_pk.assignment_id, AssignmentActions.released) assert found_recent_b.action == AssignmentActions.released assert found_recent_a.id != found_recent_b.id
def test_action_base_mathods_and_find_by_pk(db, assignment_tree, user_johaannes): # subscription set up earlier release_file = "/some/random/path/to/a/file.tzg" with pytest.raises(TypeError): found_by_pk = Action.find_by_pk() with pytest.raises(TypeError): found_by_pk = Action.find_by_pk(db) with pytest.raises(ValueError): found_by_pk = Action.find_by_pk(db, None) with pytest.raises(TypeError): found_by_pk = Action.find_by_pk(db, "abc") found_by_pk = Action.find_by_pk(db, 1) assert found_by_pk.id == 1 assert found_by_pk.action == AssignmentActions.released assert found_by_pk.location == release_file # check the relationships assert found_by_pk.user.name == user_johaannes.name assert found_by_pk.assignment.assignment_code == assignment_tree.assignment_code found_by_pk = Action.find_by_pk(db, 11) assert found_by_pk is None
def test_action_find_by_action(db): # subscription & action set up earlier with pytest.raises(TypeError): found_by_pk = Action.find_most_recent_action(db, None) with pytest.raises(TypeError): found_by_pk = Action.find_most_recent_action(db, "abc") with pytest.raises(TypeError): found_by_pk = Action.find_most_recent_action(db, 1, dict()) found_by_pk = Action.find_by_pk(db, 1) # released found_recent = Action.find_most_recent_action(db, found_by_pk.assignment_id, found_by_pk.action) assert found_recent.action == found_by_pk.action found_recent = Action.find_most_recent_action(db, found_by_pk.assignment_id, "released") assert found_recent.action == found_by_pk.action found_recent = Action.find_most_recent_action(db, found_by_pk.assignment_id, AssignmentActions.released) assert found_recent.action == found_by_pk.action found_recent = Action.find_most_recent_action(db, found_by_pk.assignment_id, AssignmentActions.feedback_fetched) assert found_recent is None
def test_action_relationships(db, user_johaannes): found_by_pk = Action.find_by_pk(db, 1) assert found_by_pk.user.name == user_johaannes.name assert found_by_pk.assignment.assignment_code == "tree 1" assert found_by_pk.assignment.course.course_code == "Strange"