-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: support numeric usernames on get_user method
- Loading branch information
1 parent
65ddeae
commit e706107
Showing
2 changed files
with
35 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,25 +3,30 @@ | |
""" | ||
from unittest.mock import patch | ||
|
||
from ddt import data, ddt | ||
from django.test import TestCase | ||
|
||
from event_routing_backends.helpers import ( | ||
get_anonymous_user_id, | ||
get_block_id_from_event_referrer, | ||
get_course_from_id, | ||
get_user, | ||
get_user_email, | ||
get_uuid5, | ||
) | ||
from event_routing_backends.tests.factories import UserFactory | ||
|
||
|
||
@ddt | ||
class TestHelpers(TestCase): | ||
""" | ||
Test the helper methods. | ||
""" | ||
|
||
def setUp(self): | ||
super().setUp() | ||
UserFactory.create(username='edx', email='[email protected]') | ||
self.edx_user = UserFactory.create(username='edx', email='[email protected]') | ||
UserFactory.create(username='10228945687', email='[email protected]') | ||
|
||
def test_get_block_id_from_event_referrer_with_error(self): | ||
sample_event = { | ||
|
@@ -83,3 +88,24 @@ def test_get_course_from_id_unknown_course(self, mock_get_course_overviews): | |
mock_get_course_overviews.return_value = [] | ||
with self.assertRaises(ValueError): | ||
get_course_from_id("foo") | ||
|
||
@data("edx", "10228945687") | ||
def test_get_user_by_username(self, username): | ||
"""Test that the method get_user returns the right user based on given username parameter. | ||
Expected behavior: | ||
- Returned user corresponds to the username. | ||
""" | ||
user = get_user(username) | ||
|
||
self.assertEqual(username, user.username) | ||
|
||
def test_get_user_by_id(self): | ||
""" Test that the method get_user returns the right user based on the user id. | ||
Expected behavior: | ||
- Returned user is the edx_user | ||
""" | ||
user = get_user(self.edx_user.id) | ||
|
||
self.assertEqual(self.edx_user, user) |