Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Initial attempt at grouped allowance endpoint #892

Merged
merged 4 commits into from
Jun 22, 2021

Conversation

mohtamba
Copy link
Contributor

@mohtamba mohtamba commented Jun 21, 2021

Added grouped allowance function within views and the endpoint within urls.py. Added test cases to test_views.py.

Description:

Describe in a couple of sentences how this pull request modifies the repository.

JIRA:

MST-845

Pre-Merge Checklist:

  • Updated the version number in edx_proctoring/__init__.py and package.json if these changes are to be released.
  • Described your changes in CHANGELOG.rst
  • Confirmed Github reports all automated tests/checks are passing.
  • Approved by at least one additional reviewer.

Post-Merge:

  • Create a tag matching the new version number.

Added grouped allowance function within views and the endpoint within urls.py. Added test cases to test_views.py.
Copy link
Contributor

@schenedx schenedx left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See my inline feedback. Good work. Most of my feedback are to help you make this a bit cleaner. But the logic is sound.

for allowance in all_allowances:
serialied_allowance = ProctoredExamStudentAllowanceSerializer(allowance).data
user_id = serialied_allowance['user']['id']
if user_id in grouped_allowances:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use setdefault function here would help simplify these 4 lines


**Expected Response**
HTTP GET:
The response will contain a dictionary with the allowances of a course grouped by student.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#NIT can you provide an example response here? It makes the comments on this function much easier to read.

grouped_allowances = response_data['grouped_allowances']
self.assertEqual(len(grouped_allowances), 3)
# Check that all users allowances are inputted correctly
first_user = str(user_list[0].id)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you write a function that would compare the returned dictionary with the expected dictionary? We have assertDictEqual function to help make sure all the elements are correct.

self.assertEqual(len(grouped_allowances[first_user]), 2)
self.assertNotEqual(grouped_allowances[first_user][0], grouped_allowances[first_user][1])

def test_get_grouped_allowances_non_staff(self):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are missing a test case where the user is a course staff, not a global staff. For example, see https://github.com/edx/edx-proctoring/blob/f1ebee0814ac45f7b11d030df4991f4ccea082bd/edx_proctoring/tests/test_views.py#L473

Added comments/refactored code to be more concise/readable. Adjust test case to be more thorough.
Copy link
Contributor

@schenedx schenedx left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@mohtamba mohtamba marked this pull request as ready for review June 22, 2021 18:31
@mohtamba mohtamba merged commit f6426e9 into master Jun 22, 2021
@mohtamba mohtamba deleted the mohtamba/get_bulk_allowances_endpoint branch June 22, 2021 18:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants