Skip to content
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
5 changes: 2 additions & 3 deletions cms/djangoapps/contentstore/views/tests/test_entrance_exam.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
from unittest.mock import patch

from django.conf import settings
from django.contrib.auth.models import User # lint-amnesty, pylint: disable=imported-auth-user
from django.test.client import RequestFactory
from milestones.tests.utils import MilestonesTestCaseMixin
from opaque_keys.edx.keys import UsageKey
Expand Down Expand Up @@ -173,7 +172,7 @@ def test_contentstore_views_entrance_exam_delete(self):
resp = self.client.get(self.exam_url)
self.assertEqual(resp.status_code, 404)

user = User.objects.create(
user = UserFactory.create(
username='test_user',
email='[email protected]',
is_active=True,
Expand Down Expand Up @@ -287,7 +286,7 @@ def test_contentstore_views_entrance_exam_get_invalid_user(self):
"""
Unit Test: test_contentstore_views_entrance_exam_get_invalid_user
"""
user = User.objects.create(
user = UserFactory.create(
username='test_user',
email='[email protected]',
is_active=True,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
from enterprise.models import EnterpriseCustomer, EnterpriseCustomerUser
from pytest import mark

from common.djangoapps.student.tests.factories import UserFactory


@mark.django_db
class ChangeEnterpriseUserUsernameCommandTests(TestCase):
Expand All @@ -25,7 +27,7 @@ def test_user_not_enterprise(self, logger_mock):
"""
Test that the command does not update a user's username if it is not linked to an Enterprise.
"""
user = User.objects.create(is_active=True, username='old_username', email='[email protected]')
user = UserFactory.create(is_active=True, username='old_username', email='[email protected]')
new_username = 'new_username'

post_save_handler = mock.MagicMock()
Expand All @@ -41,7 +43,7 @@ def test_username_updated_successfully(self, logger_mock):
"""
Test that the command updates the user's username when the user is linked to an Enterprise.
"""
user = User.objects.create(is_active=True, username='old_username', email='[email protected]')
user = UserFactory.create(is_active=True, username='old_username', email='[email protected]')
site, _ = Site.objects.get_or_create(domain='example.com')
enterprise_customer = EnterpriseCustomer.objects.create(
name='Test EnterpriseCustomer',
Expand Down
10 changes: 5 additions & 5 deletions common/djangoapps/student/tests/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -763,7 +763,7 @@ def test_enrollment(self):

def test_enrollment_non_existent_user(self):
# Testing enrollment of newly unsaved user (i.e. no database entry)
user = User(username="rusty", email="[email protected]")
user = UserFactory(username="rusty", email="[email protected]")
course_id = CourseLocator("edX", "Test101", "2013")
course = CourseOverviewFactory.create(id=course_id)

Expand All @@ -781,7 +781,7 @@ def test_enrollment_non_existent_user(self):

@unittest.skipUnless(settings.ROOT_URLCONF == 'lms.urls', 'Test only valid in lms')
def test_enrollment_by_email(self):
user = User.objects.create(username="jack", email="[email protected]")
user = UserFactory.create(username="jack", email="[email protected]")
course_id = CourseLocator("edX", "Test101", "2013")
course = CourseOverviewFactory.create(id=course_id)

Expand Down Expand Up @@ -818,7 +818,7 @@ def test_enrollment_by_email(self):

@unittest.skipUnless(settings.ROOT_URLCONF == 'lms.urls', 'Test only valid in lms')
def test_enrollment_multiple_classes(self):
user = User(username="rusty", email="[email protected]")
user = UserFactory(username="rusty", email="[email protected]")
course_id1 = CourseLocator("edX", "Test101", "2013")
course_id2 = CourseLocator("MITx", "6.003z", "2012")
course1 = CourseOverviewFactory.create(id=course_id1)
Expand All @@ -843,7 +843,7 @@ def test_enrollment_multiple_classes(self):

@unittest.skipUnless(settings.ROOT_URLCONF == 'lms.urls', 'Test only valid in lms')
def test_activation(self):
user = User.objects.create(username="jack", email="[email protected]")
user = UserFactory.create(username="jack", email="[email protected]")
course_id = CourseLocator("edX", "Test101", "2013")
course = CourseOverviewFactory.create(id=course_id)
assert not CourseEnrollment.is_enrolled(user, course_id)
Expand Down Expand Up @@ -881,7 +881,7 @@ def test_activation(self):
self.assert_enrollment_event_was_emitted(user, course_id, course, enrollment)

def test_change_enrollment_modes(self):
user = User.objects.create(username="justin", email="[email protected]")
user = UserFactory.create(username="justin", email="[email protected]")
course_id = CourseLocator("edX", "Test101", "2013")
course = CourseOverviewFactory.create(id=course_id)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from unittest.mock import patch

from django.conf import settings
from django.contrib.auth.models import AnonymousUser, User # lint-amnesty, pylint: disable=imported-auth-user
from django.contrib.auth.models import AnonymousUser
from django.db import connections
from django.test import TestCase
from django.test.utils import override_settings
Expand Down Expand Up @@ -525,7 +525,7 @@ def setUp(self):

if self.CREATE_USER:
# Create the user so we can log them in.
self.user = User.objects.create_user(uname, email, self.user_password)
self.user = UserFactory.create(username=uname, email=email, password=self.user_password)

# Note that we do not actually need to do anything
# for registration if we directly mark them active.
Expand All @@ -542,7 +542,7 @@ def create_non_staff_user(self):
"""
uname = 'teststudent'
password = 'foo'
nonstaff_user = User.objects.create_user(uname, '[email protected]', password)
nonstaff_user = UserFactory.create(username=uname, email='[email protected]', password=password)

# Note that we do not actually need to do anything
# for registration if we directly mark them active.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@

import ddt
import pytest
from django.contrib.auth import get_user_model
from django.core.management import CommandError, call_command

from common.djangoapps.student.tests.factories import UserFactory
from common.djangoapps.student.models import CourseEnrollment
from lms.djangoapps.grades.config.models import ComputeGradesSetting
from lms.djangoapps.grades.management.commands import compute_grades
Expand All @@ -32,7 +32,7 @@ def setUpClass(cls):

cls.courses = [CourseFactory.create() for _ in range(cls.num_courses)]
cls.course_keys = [str(course.id) for course in cls.courses]
cls.users = [get_user_model().objects.create(username=f'user{idx}') for idx in range(cls.num_users)]
cls.users = [UserFactory.create(username=f'user{idx}') for idx in range(cls.num_users)]

for user in cls.users:
for course in cls.courses:
Expand Down
3 changes: 2 additions & 1 deletion openedx/core/djangoapps/credit/tests/test_services.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ def setUp(self):
self.service = CreditService()
self.course = CourseFactory.create(org='edX', number='DemoX', display_name='Demo_Course')
self.credit_course = CreditCourse.objects.create(course_key=self.course.id, enabled=True)
self.profile = UserProfile.objects.create(user_id=self.user.id, name='Foo Bar')
self.user.profile.name = 'Foo Bar'
self.user.profile.save()

def enroll(self, course_id=None, mode=CourseMode.VERIFIED):
"""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ def setUp(self):
self.url = reverse('login_api')

def _create_user(self, username, user_email):
user = UserFactory.build(username=username, email=user_email)
user = UserFactory.create(username=username, email=user_email)
user.set_password(self.password)
user.save()
return user
Expand Down