Python django.db.models.signals.post_save() Examples

The following are 30 code examples of django.db.models.signals.post_save(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module django.db.models.signals , or try the search function .
Example #1
Source File: api_test.py    From micromasters with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
def setUpTestData(cls):
        with mute_signals(post_save):
            profile = ProfileFactory.create()

        cls.program, _ = create_program(past=True)
        cls.user = profile.user
        cls.course_run = cls.program.course_set.first().courserun_set.first()
        with mute_signals(post_save):
            CachedEnrollmentFactory.create(user=cls.user, course_run=cls.course_run)
        cls.exam_run = ExamRunFactory.create(course=cls.course_run.course)
        with mute_signals(post_save):
            cls.final_grade = FinalGradeFactory.create(
                user=cls.user,
                course_run=cls.course_run,
                passed=True,
                course_run_paid_on_edx=False,
            ) 
Example #2
Source File: indexing_api_test.py    From micromasters with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
def test_index_program_enrolled_users_missing_profiles(self, mock_on_commit):
        """
        Test that index_program_enrolled_users doesn't index users missing profiles
        """
        with mute_signals(post_save):
            program_enrollments = [ProgramEnrollmentFactory.build() for _ in range(10)]
        with patch(
            'search.indexing_api._index_chunk', autospec=True, return_value=0
        ) as index_chunk, patch(
            'search.indexing_api.serialize_program_enrolled_user',
            autospec=True,
            side_effect=lambda x: None  # simulate a missing profile
        ) as serialize_mock, patch(
            'search.indexing_api.serialize_public_enrolled_user', autospec=True, side_effect=lambda x: x
        ) as serialize_public_mock:
            index_program_enrolled_users(program_enrollments)
            assert index_chunk.call_count == 0
            assert serialize_public_mock.call_count == 0
            assert serialize_mock.call_count == len(program_enrollments) 
Example #3
Source File: api_test.py    From micromasters with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
def test_populate_query_inactive_memberships(self, is_active, has_profile, mock_on_commit):
        """
        Tests that memberships are handled correctly for users who are inactive or have no profiles
        """
        with mute_signals(post_save):
            query = PercolateQueryFactory.create(source_type=PercolateQuery.DISCUSSION_CHANNEL_TYPE)
            user = UserFactory.create(is_active=is_active)
            if has_profile:
                ProfileFactory.create(user=user, filled_out=True)
            ProgramEnrollmentFactory.create(user=user)

        with patch('search.api.get_conn') as es_mock:
            populate_query_memberships(query.id)
            assert es_mock.return_value.search.call_count == (1 if has_profile and is_active else 0)

        assert PercolateQueryMembership.objects.filter(user=user, query=query).count() == (
            1 if is_active else 0
        ) 
Example #4
Source File: apps.py    From pasportaservo with GNU Affero General Public License v3.0 6 votes vote down vote up
def ready(self):
        # Models that should be watched and cause creation and deletion of the
        # related visibility object. The 2nd element of the tuple specifies the
        # field; the 3rd the specific visibility model.
        assets = [
            ('Profile', 'email', 'PublicEmail'),
            ('Phone', '', 'Phone'),
            ('Place', '', 'Place'),
            ('Place', 'family_members', 'FamilyMembers'),
        ]
        for model, field, asset_type in assets:
            make_visibility_receivers(
                'hosting.' + model,
                field + ('_' if field else '') + 'visibility',
                self.get_model('VisibilitySettingsFor' + asset_type)
            )
        signals.post_save.connect(profile_post_save, sender='hosting.Profile') 
Example #5
Source File: api_test.py    From micromasters with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
def test_populate_query_memberships(self, source_type, is_member, query_matches, mock_on_commit):
        """
        Tests that existing memberships are updated where appropriate
        """
        with mute_signals(post_save):
            query = PercolateQueryFactory.create(source_type=source_type)
            profiles = [ProfileFactory.create(filled_out=True) for _ in range(3)]
            program_enrollments = [ProgramEnrollmentFactory.create(user=profile.user) for profile in profiles]

        with patch(
            'search.api._search_percolate_queries',
            return_value=[query.id] if query_matches else []
        ) as search_percolate_queries_mock:
            populate_query_memberships(query.id)

        assert search_percolate_queries_mock.call_count == len(program_enrollments)
        for program_enrollment in program_enrollments:
            search_percolate_queries_mock.assert_any_call(program_enrollment)

        for profile in profiles:
            membership = PercolateQueryMembership.objects.get(user=profile.user, query=query)
            assert membership.is_member is query_matches
            assert membership.needs_update is True 
Example #6
Source File: api_test.py    From micromasters with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
def test_update_percolate_memberships(self, source_type, is_member, query_matches, mock_on_commit):
        """
        Tests that existing memberships are updated where appropriate
        """
        with mute_signals(post_save):
            query = PercolateQueryFactory.create(source_type=source_type)
            profile = ProfileFactory.create(filled_out=True)
            program_enrollment = ProgramEnrollmentFactory.create(user=profile.user)
        membership = PercolateQueryMembershipFactory.create(
            user=profile.user,
            query=query,
            is_member=is_member,
            needs_update=False
        )

        with patch(
            'search.api._search_percolate_queries',
            return_value=[query.id] if query_matches else []
        ) as search_percolate_queries_mock:
            update_percolate_memberships(profile.user, source_type)

        search_percolate_queries_mock.assert_called_once_with(program_enrollment)

        membership.refresh_from_db()
        assert membership.needs_update is (is_member is not query_matches) 
Example #7
Source File: views_test.py    From micromasters with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
def setUpTestData(cls):
        """
        Create a user
        """
        with mute_signals(post_save):
            cls.user1 = UserFactory.create()
            username = "{}_edx".format(cls.user1.username)
            cls.user1.social_auth.create(
                provider=EdxOrgOAuth2.name,
                uid=username
            )
        cls.url1 = reverse('profile-detail', kwargs={'user': username})

        with mute_signals(post_save):
            cls.user2 = UserFactory.create(username="test.dev.example")
            username = "{}_edx".format(cls.user2.username)
            cls.user2.social_auth.create(
                provider=EdxOrgOAuth2.name,
                uid=username
            )
        cls.url2 = reverse('profile-detail', kwargs={'user': username}) 
Example #8
Source File: api_test.py    From micromasters with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
def setUpTestData(cls):
        with mute_signals(post_save):
            profile = ProfileFactory.create()
        cls.user = profile.user
        cls.program = ProgramFactory.create()
        Role.objects.create(
            user=cls.user,
            program=cls.program,
            role=Staff.ROLE_ID
        )

        with mute_signals(post_save):
            profile = ProfileFactory.create(email_optin=True, filled_out=True)
            profile2 = ProfileFactory.create(email_optin=False, filled_out=True)

        cls.learner = profile.user
        cls.learner2 = profile2.user

        # self.user with role staff on program
        for user in [cls.learner, cls.learner2, cls.user]:
            ProgramEnrollmentFactory(
                user=user,
                program=cls.program,
            ) 
Example #9
Source File: views_test.py    From micromasters with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
def setUpTestData(cls):
        super().setUpTestData()
        with mute_signals(post_save):
            staff_profile = ProfileFactory.create(user__email='sender@example.com')
            recipient_profile = ProfileFactory.create(
                user__email='recipient@example.com',
                email_optin=True,
            )
        cls.staff_user = staff_profile.user
        cls.recipient_user = recipient_profile.user
        cls.program = ProgramFactory.create(financial_aid_availability=False)
        ProgramEnrollmentFactory.create(
            user=cls.recipient_user,
            program=cls.program
        )
        Role.objects.create(
            user=cls.staff_user,
            program=cls.program,
            role=Staff.ROLE_ID
        )
        cls.url_name = 'learner_mail_api'
        cls.request_data = {
            'email_subject': 'email subject',
            'email_body': 'email body'
        } 
Example #10
Source File: views_test.py    From micromasters with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
def setUpTestData(cls):
        super().setUpTestData()
        with mute_signals(post_save):
            staff_profile = ProfileFactory.create()
        cls.staff_user = staff_profile.user
        cls.course = CourseFactory.create(
            contact_email='a@example.com',
            program__financial_aid_availability=False
        )
        course_run = CourseRunFactory.create(course=cls.course)
        ProgramEnrollmentFactory.create(user=cls.staff_user, program=cls.course.program)
        CachedEnrollmentFactory.create(user=cls.staff_user, course_run=course_run)
        cls.url_name = 'course_team_mail_api'
        cls.request_data = {
            'email_subject': 'email subject',
            'email_body': 'email body'
        } 
Example #11
Source File: api_test.py    From micromasters with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
def setUpTestData(cls):
        super().setUpTestData()

        cls.program_enrollment_unsent = ProgramEnrollmentFactory.create()
        cls.program_enrollment_sent = ProgramEnrollmentFactory.create()
        cls.automatic_email = AutomaticEmailFactory.create(enabled=True)
        cls.percolate_query = cls.automatic_email.query
        cls.other_query = PercolateQueryFactory.create(source_type=PercolateQuery.DISCUSSION_CHANNEL_TYPE)
        cls.percolate_queries = [cls.percolate_query, cls.other_query]
        cls.automatic_email_disabled = AutomaticEmailFactory.create(enabled=False)
        cls.percolate_query_disabled = cls.automatic_email_disabled.query
        SentAutomaticEmail.objects.create(
            automatic_email=cls.automatic_email,
            user=cls.program_enrollment_sent.user,
            status=SentAutomaticEmail.SENT,
        )
        # User was sent email connected to a different AutomaticEmail
        SentAutomaticEmail.objects.create(
            user=cls.program_enrollment_unsent.user,
            automatic_email=AutomaticEmailFactory.create(enabled=True),
            status=SentAutomaticEmail.SENT,
        )
        with mute_signals(post_save):
            cls.staff_user = UserFactory.create() 
Example #12
Source File: signals_test.py    From micromasters with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
def setUpTestData(cls):
        with mute_signals(post_save):
            cls.profile = ProfileFactory.create()

        cls.program, _ = create_program(past=True)
        cls.course_run = cls.program.course_set.first().courserun_set.first()
        CachedCurrentGradeFactory.create(
            user=cls.profile.user,
            course_run=cls.course_run,
            data={
                "passed": True,
                "percent": 0.9,
                "course_key": cls.course_run.edx_course_key,
                "username": cls.profile.user.username
            }
        )
        CachedCertificateFactory.create(user=cls.profile.user, course_run=cls.course_run)
        cls.exam_run = ExamRunFactory.create(
            course=cls.course_run.course,
            date_first_schedulable=now_in_utc() - timedelta(days=1),
        ) 
Example #13
Source File: writers_test.py    From micromasters with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
def test_write_ead_file(self):
        """
        Tests that write_ead_file outputs correctly
        """
        kwargs = {
            'id': 143,
            'operation': 'add',
            'exam_run__exam_series_code': 'MM-DEDP',
            'exam_run__date_first_eligible': date(2016, 5, 15),
            'exam_run__date_last_eligible': date(2016, 10, 15),
        }

        with mute_signals(post_save):
            profile = ProfileFactory(id=14879)
            exam_auths = [ExamAuthorizationFactory.create(user=profile.user, **kwargs)]
            exam_auths[0].updated_on = FIXED_DATETIME

        self.ead_writer.write(self.tsv_file, exam_auths)

        assert self.tsv_rows[0] == (
            "add\t143\t"
            "14879\tMM-DEDP\t\t"
            "\t2016/05/15\t2016/10/15\t"  # accommodation blank intentionally
            "2016/05/15 15:02:55"
        ) 
Example #14
Source File: writers_test.py    From micromasters with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
def test_write_cdd_file_with_blank_romanized_name(self):
        """
        Tests cdd_writer against a profile without romanized name fields
        """
        kwargs = {
            'profile__id': 9876,
            'profile__first_name': 'Jane',
            'profile__last_name': 'Smith',
            'profile__romanized_first_name': None,
            'profile__romanized_last_name': None,
            'profile__phone_number': '+1 617 293-3423',
        }

        with mute_signals(post_save):
            exam_profiles = [ExamProfileFactory.create(**kwargs)]
            exam_profiles[0].profile.updated_on = FIXED_DATETIME
        self.cdd_writer.write(self.tsv_file, exam_profiles)

        assert self.tsv_rows[0].startswith("9876\tJane\tSmith\t") 
Example #15
Source File: permissions_test.py    From micromasters with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
def setUpTestData(cls):
        with mute_signals(post_save):
            cls.learner1 = UserFactory.create()
            cls.learner1_username = 'learner1_username'
            cls.learner1.social_auth.create(
                provider=EdxOrgOAuth2.name,
                uid=cls.learner1_username
            )
            cls.learner2 = UserFactory.create()
            cls.learner2_username = 'learner2_username'
            cls.learner2.social_auth.create(
                provider=EdxOrgOAuth2.name,
                uid=cls.learner2_username
            )
            cls.program = ProgramFactory.create()
            cls.staff = UserFactory.create()
            cls.staff_username = 'staff_username'
            for learner in (cls.learner1, cls.learner2):
                ProgramEnrollment.objects.create(
                    program=cls.program,
                    user=learner,
                ) 
Example #16
Source File: serializers_test.py    From micromasters with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
def setUpTestData(cls):
        with mute_signals(post_save):
            cls.profile = profile = ProfileFactory.create()
        cls.user = profile.user
        # Create non-FA program data
        cls.non_fa_program = ProgramFactory.create()
        _, course_runs = cls.generate_course_with_runs(
            cls.non_fa_program,
            course_params=dict(title='Non FA Course 1')
        )
        cls.non_fa_enrollments = [cls.verified_enroll(cls.user, course_runs[0])]
        cls.non_fa_program_enrollment = ProgramEnrollment.objects.create(user=cls.user, program=cls.non_fa_program)
        # Create FA program data
        cls.fa_program = ProgramFactory.create(financial_aid_availability=False)
        _, course_runs = cls.generate_course_with_runs(
            cls.fa_program,
            course_params=dict(title='FA Course 1')
        )
        cls.fa_enrollments = [cls.verified_enroll(cls.user, course_runs[0])]
        cls.fa_program_enrollment = ProgramEnrollment.objects.create(user=cls.user, program=cls.fa_program) 
Example #17
Source File: api_test.py    From micromasters with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def test_percolate_failure(self, mock_on_commit):
        """
        If search_percolate fails we should raise an Exception with some useful information for Sentry
        """
        failures = [
            {
                "shard": 0,
                "index": "index",
                "status": "BAD_REQUEST",
                "reason": {
                    "type": "parse_exception",
                    "reason": "failed to parse request",
                    "caused_by": {
                        "type": "mapper_parsing_exception",
                        "reason": "Cannot generate dynamic mappings of type [_id] for [_id]"
                    }
                }
            }
        ]
        failure_payload = {
            "took": 1,
            "_shards": {
                "total": 5,
                "successful": 0,
                "failed": 5,
                "failures": failures
            },
            "total": 0,
            "matches": []
        }
        with mute_signals(post_save):
            profile = ProfileFactory.create(filled_out=True)
        program_enrollment = ProgramEnrollmentFactory.create(user=profile.user)
        with self.assertRaises(PercolateException) as ex, patch(
            'search.api.get_conn', return_value=Mock(search=Mock(return_value=failure_payload))
        ):
            search_percolate_queries(program_enrollment.id, "doesnt_matter")
        assert ex.exception.args[0] == "Failed to percolate: {}".format(failures) 
Example #18
Source File: views_test.py    From micromasters with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def test_no_program_user_response(self):
        """
        Test that a 403 will be returned when a user with inadequate permissions attempts
        to send an email through the SearchResultMailView
        """
        with mute_signals(post_save):
            no_permissions_profile = ProfileFactory.create()
        self.client.force_login(no_permissions_profile.user)
        resp_post = self.client.post(self.search_result_mail_url, data=self.request_data, format='json')
        assert resp_post.status_code == status.HTTP_403_FORBIDDEN 
Example #19
Source File: signals_test.py    From micromasters with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def test_update_exam_authorization_final_grade(self):
        """
        Verify that update_exam_authorization_final_grade is called when a FinalGrade saves
        """
        create_order(self.profile.user, self.course_run)
        with mute_signals(post_save):
            # muted because enrollment also trigger signal for profile creation. right now we are just
            # looking final grades
            CachedEnrollmentFactory.create(user=self.profile.user, course_run=self.course_run)

        # There is no ExamProfile or ExamAuthorization before creating the FinalGrade.
        assert ExamProfile.objects.filter(profile=self.profile).exists() is False
        assert ExamAuthorization.objects.filter(
            user=self.profile.user,
            course=self.course_run.course
        ).exists() is False

        FinalGradeFactory.create(
            user=self.profile.user,
            course_run=self.course_run,
            passed=True,
        )

        # assert Exam Authorization and profile created.
        assert ExamProfile.objects.filter(profile=self.profile).exists() is True
        assert ExamAuthorization.objects.filter(
            user=self.profile.user,
            course=self.course_run.course
        ).exists() is True 
Example #20
Source File: views_test.py    From micromasters with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def test_learner_view_recipient_opted_out(self):
        """
        Test that an attempt to email a recipient who has opted out of emails will result in an error
        """
        self.client.force_login(self.staff_user)
        with mute_signals(post_save):
            opted_out_profile = ProfileFactory.create(
                user__email='opted_out_recipient@example.com',
                email_optin=False
            )
        url = reverse(self.url_name, kwargs={'student_id': opted_out_profile.student_id})
        resp_post = self.client.post(url, data=self.request_data, format='json')
        assert resp_post.status_code == status.HTTP_403_FORBIDDEN 
Example #21
Source File: writers_test.py    From micromasters with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def test_write_cdd_file(self):
        """
        Tests cdd_writer against a set of profiles
        """
        kwargs = {
            'profile__id': 14879,
            'profile__romanized_first_name': 'Jane',
            'profile__romanized_last_name': 'Smith',
            'profile__user__email': 'jane@example.com',
            'profile__address': '1 Main St, Room B345',
            'profile__city': 'Boston',
            'profile__state_or_territory': 'US-MA',
            'profile__country': 'US',
            'profile__postal_code': '02115',
            'profile__phone_number': '+1 617 293-3423',
        }

        with mute_signals(post_save):
            exam_profiles = [ExamProfileFactory.create(**kwargs)]
            exam_profiles[0].updated_on = FIXED_DATETIME

        self.cdd_writer.write(self.tsv_file, exam_profiles)

        assert self.tsv_rows[0] == (
            "14879\tJane\tSmith\tjane@example.com\t"
            "1 Main St, Room B345\t\t\t"  # triple tab is for blank address2 and address3
            "Boston\tMA\t02115\tUSA\t"
            "6172933423\t1\t2016/05/15 15:02:55"
        ) 
Example #22
Source File: writers_test.py    From micromasters with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def test_profile_phone_number_exceptions(self, bad_number):
        """
        It should raise exceptions for bad data
        """
        with mute_signals(post_save):
            profile = ExamProfileFactory(profile__phone_number=bad_number)
        with self.assertRaises(InvalidProfileDataException):
            CDDWriter.profile_phone_number_to_raw_number(profile)
        with self.assertRaises(InvalidProfileDataException):
            CDDWriter.profile_phone_number_to_country_code(profile) 
Example #23
Source File: writers_test.py    From micromasters with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def test_profile_phone_number_functions(self, input_number, expected_country_code, expected_number):
        """
        A profile with a valid phone number should be parsed correctly
        """
        with mute_signals(post_save):
            profile = ExamProfileFactory(profile__phone_number=input_number)
        assert CDDWriter.profile_phone_number_to_raw_number(profile) == expected_number
        assert CDDWriter.profile_phone_number_to_country_code(profile) == expected_country_code 
Example #24
Source File: writers_test.py    From micromasters with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def test_profile_state(self, country, state, expected):
        """Test that profile_state returns expected values"""
        with mute_signals(post_save):
            profile = ExamProfileFactory(
                profile__country=country,
                profile__state_or_territory=state
            )
        assert CDDWriter.profile_state(profile) == expected 
Example #25
Source File: indexing_api_test.py    From micromasters with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def setUpTestData(cls):
        with mute_signals(post_save):
            cls.profile = ProfileFactory.create()
        EducationFactory.create(profile=cls.profile)
        EmploymentFactory.create(profile=cls.profile)
        EmploymentFactory.create(profile=cls.profile, end_date=None)
        program = ProgramFactory.create()
        course = CourseFactory.create(program=program)
        course_runs = [CourseRunFactory.create(course=course) for _ in range(2)]
        for course_run in course_runs:
            CachedCertificateFactory.create(user=cls.profile.user, course_run=course_run)
            CachedEnrollmentFactory.create(user=cls.profile.user, course_run=course_run)
        cls.program_enrollment = ProgramEnrollment.objects.create(user=cls.profile.user, program=program) 
Example #26
Source File: writers_test.py    From micromasters with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def test_last_name(self, unromanized, romanized, expected):
        """
        Test that the `last_name` method prefers the `romanized_last_name`
        field, and falls back on `last_name` field.
        """
        with mute_signals(post_save):
            profile = ExamProfileFactory(
                profile__last_name=unromanized,
                profile__romanized_last_name=romanized,
            )
        assert CDDWriter.last_name(profile) == expected 
Example #27
Source File: api_test.py    From micromasters with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def test_exam_authorization_for_inactive_user(self):
        """
        test exam_authorization when inactive user passed and paid for course.
        """
        with mute_signals(post_save):
            profile = ProfileFactory.create()

        user = profile.user
        user.is_active = False
        user.save()
        with mute_signals(post_save):
            CachedEnrollmentFactory.create(user=user, course_run=self.course_run)

        with mute_signals(post_save):
            FinalGradeFactory.create(
                user=user,
                course_run=self.course_run,
                passed=True,
                course_run_paid_on_edx=False,
            )
        create_order(user, self.course_run)
        mmtrack = get_mmtrack(user, self.program)
        self.assertTrue(mmtrack.has_paid(self.course_run.edx_course_key))
        self.assertTrue(mmtrack.has_passed_course(self.course_run.edx_course_key))

        # Neither user has exam profile nor authorization.
        assert ExamProfile.objects.filter(profile=mmtrack.user.profile).exists() is False
        assert ExamAuthorization.objects.filter(
            user=mmtrack.user,
            course=self.course_run.course
        ).exists() is False

        with self.assertRaises(ExamAuthorizationException):
            authorize_for_exam_run(self.user, self.course_run, self.exam_run)

        # Assert user doesn't have exam profile and authorization
        assert ExamProfile.objects.filter(profile=mmtrack.user.profile).exists() is False
        assert ExamAuthorization.objects.filter(
            user=mmtrack.user,
            course=self.course_run.course
        ).exists() is False 
Example #28
Source File: writers_test.py    From micromasters with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def test_first_name(self, unromanized, romanized, expected):
        """
        Test that the `first_name` method prefers the `romanized_first_name`
        field, and falls back on `first_name` field.
        """
        with mute_signals(post_save):
            profile = ExamProfileFactory(
                profile__first_name=unromanized,
                profile__romanized_first_name=romanized,
            )
        assert CDDWriter.first_name(profile) == expected 
Example #29
Source File: utils_test.py    From micromasters with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def setUpTestData(cls):
        """
        Create a profile
        """
        super().setUpTestData()
        with mute_signals(post_save):
            cls.profile = ProfileFactory.create() 
Example #30
Source File: signals_test.py    From micromasters with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def test_update_exam_authorization_final_grade_when_user_not_paid(self):
        """
        Verify that update_exam_authorization_final_grade is called and log exception when
        FinalGrade saves user dont match exam authorization criteria
        """
        with mute_signals(post_save):
            # muting signal for CachedEnrollment. Because CachedEnrollment and FinalGrade both omits
            # signal, we want to see behaviour of FinalGrade here
            CachedEnrollmentFactory.create(user=self.profile.user, course_run=self.course_run)

        assert ExamProfile.objects.filter(profile=self.profile).exists() is False
        assert ExamAuthorization.objects.filter(
            user=self.profile.user,
            course=self.course_run.course
        ).exists() is False

        FinalGradeFactory.create(
            user=self.profile.user,
            course_run=self.course_run,
            passed=True,
            course_run_paid_on_edx=False,
        )

        # assert Exam Authorization and profile not created.
        assert ExamProfile.objects.filter(profile=self.profile).exists() is False
        assert ExamAuthorization.objects.filter(
            user=self.profile.user,
            course=self.course_run.course
        ).exists() is False