Esempio n. 1
0
    def test_identify_call_on_profile_change(self):
        profile = UserProfileFactory(user=UserFactory())

        with patch('openedx.core.djangoapps.user_authn.signals.segment') as mock_segment:
            profile.gender = 'f'
            profile.save()
        assert mock_segment.identify.call_count == 1
        assert mock_segment.identify.call_args[0] == (profile.user_id, {'gender': 'Female'})
Esempio n. 2
0
 def setUp(self):
     super(CookieTests, self).setUp()  # lint-amnesty, pylint: disable=super-with-arguments
     self.user = UserFactory.create()
     self.user.profile = UserProfileFactory.create(user=self.user)
     self.request = RequestFactory().get('/')
     self.request.user = self.user
     self.request.session = self._get_stub_session()
Esempio n. 3
0
 def setUp(self):
     super().setUp()
     self.user = UserFactory.create()
     self.user.profile = UserProfileFactory.create(user=self.user)
     self.request = RequestFactory().get('/')
     self.request.user = self.user
     self.request.session = self._get_stub_session()
Esempio n. 4
0
def user_with_user_profile(request):
    """
    Fixture which returns a user with profile.
    """
    user = UserFactory()
    UserProfileFactory(user=user)
    return user
Esempio n. 5
0
def test_get_user_first_name(first_name, full_name, expected_first_name):
    """
    Tests `get_user_first_name` helper
    """
    user = UserFactory(first_name=first_name)
    UserProfileFactory(user=user, name=full_name)

    assert get_user_first_name(user) == expected_first_name
Esempio n. 6
0
 def setUp(self):  # pylint: disable=arguments-differ
     super().setUp()
     self.course = CourseFactory.create()
     self.user = UserFactory.create(
         username="******",
         email="*****@*****.**",
         password="******",
     )
     self.user_profile = UserProfileFactory.create(user=self.user,
                                                   name="Test Example")
Esempio n. 7
0
    def setUp(self):
        """
        Create data that will be used in all tests of MandrillCourseEnrollmentEmails class
        """

        super(MandrillCourseEnrollmentEmails, self).setUp()
        self.user = UserFactory()
        UserProfileFactory(user=self.user)
        self.course = CourseFactory()
        self.course_overview = CourseOverviewFactory.create(id=self.course.id)
Esempio n. 8
0
def test_application_listing_view_get_queryset(search_query, omni_status,
                                               bu_status, business_unit,
                                               adg_admin):
    """
    Test that the filtering of the applications works correctly in the `get_quertset` method
    of the listing view
    """
    for _, application_type in UserApplication.STATUS_CHOICES:
        expected_applications = []
        if search_query:
            user_with_queried_name = UserFactory()
            UserProfileFactory(user=user_with_queried_name, name=search_query)
            application_with_test_user = UserApplicationFactory(
                user=user_with_queried_name, status=application_type)
            ApplicationHubFactory(user=application_with_test_user.user,
                                  is_written_application_completed=True)
            expected_applications.append(application_with_test_user)

        if omni_status:
            application_with_omni_status = UserApplicationFactory(
                status=application_type)
            ApplicationHubFactory(
                user=application_with_omni_status.user,
                program_prereq_courses_status=int(omni_status[0]),
                is_written_application_completed=True,
            )
            expected_applications.append(application_with_omni_status)

        if bu_status:
            application_with_bu_status = UserApplicationFactory(
                status=application_type)
            ApplicationHubFactory(
                user=application_with_bu_status.user,
                bu_prereq_courses_status=int(bu_status[0]),
                is_written_application_completed=True,
            )
            expected_applications.append(application_with_bu_status)

        if business_unit:
            query_business_unit = BusinessLineFactory(title=business_unit[0])
            application_with_query_bu = UserApplicationFactory(
                status=application_type, business_line=query_business_unit)
            ApplicationHubFactory(user=application_with_query_bu.user,
                                  is_written_application_completed=True)
            expected_applications = [application_with_query_bu]

        listing_view = ApplicationListingView(
            application_type=application_type,
            query=search_query,
            filter_by_business_line=DEFAULT_BUSINESS_LINE_FILTER,
            omni_courses_query_values=omni_status,
            bu_courses_query_values=bu_status,
            business_line_query=business_unit,
            is_user_adg_admin=is_superuser_or_adg_admin(adg_admin))
        assert list(listing_view.get_queryset()) == list(expected_applications)
    def setUp(self):
        """Setup a test user along with its registration and profile"""
        super(LoginTest, self).setUp()  # lint-amnesty, pylint: disable=super-with-arguments
        self.user = self._create_user(self.username, self.user_email)

        RegistrationFactory(user=self.user)
        UserProfileFactory(user=self.user)

        self.client = Client()
        cache.clear()

        self.url = reverse('login_api')
Esempio n. 10
0
    def setUp(self):
        """Setup a test user along with its registration and profile"""
        super().setUp()
        self.user = self._create_user(self.username, self.user_email)

        RegistrationFactory(user=self.user)
        UserProfileFactory(user=self.user)

        self.client = Client()
        cache.clear()

        self.url = reverse('login_api')
Esempio n. 11
0
 def setUp(self):  # pylint: disable=arguments-differ
     super().setUp()
     self.url = reverse("user_api_login_session",
                        kwargs={"api_version": "v1"})
     self.user = UserFactory.create(
         username="******",
         email="*****@*****.**",
         password="******",
     )
     self.user_profile = UserProfileFactory.create(user=self.user,
                                                   name="Test Example")
     self.receiver_called = True
Esempio n. 12
0
def test_get_admin_details(admin_type, adg_admin, bu_admin):
    """
    Test that `get_admin_details` function returns the correct admin details.
    """
    if admin_type == ADG_ADMIN_DISPLAY_STRING:
        admin = adg_admin
        UserProfileFactory(user=admin)
        permission = 'ADG Admin'
    else:
        admin = bu_admin
        UserProfileFactory(user=admin)
        permission = f'BU Admin of {admin.business_unit.title}'

    expected_permission = Text(
        '{name}, {span_start}{permission}{span_end}').format(
            name=admin.profile.name,
            span_start=HTML(SPAN_START),
            permission=permission,
            span_end=HTML(SPAN_END),
        )
    details = get_admin_details(admin)

    assert details['permission'] == expected_permission
Esempio n. 13
0
    def test_listen_for_verified_name_approved(self):
        """
        Test that profile name is updated when a pending name change is approved
        """
        user = UserFactory(email='*****@*****.**', username='******')
        UserProfileFactory(user=user)

        new_name = 'John Doe'
        PendingNameChange.objects.create(user=user, new_name=new_name)
        assert PendingNameChange.objects.count() == 1

        # Send a VERIFIED_NAME_APPROVED signal where the profile name matches the name
        # change request
        VERIFIED_NAME_APPROVED.send(sender=None, user_id=user.id, profile_name=new_name)

        # Assert that the pending name change was deleted and the profile name was updated
        assert PendingNameChange.objects.count() == 0
        profile = UserProfile.objects.get(user=user)
        assert profile.name == new_name