예제 #1
0
 def setUp(self):
     super().setUp()
     # Disable marketing site password just to save us from having to mock the responses
     self.partner = factories.PartnerFactory(
         marketing_site_api_password=None)
     self.person = factories.PersonFactory(partner=self.partner,
                                           given_name='Person')
     self.target = factories.PersonFactory(partner=self.partner,
                                           given_name='Target')
     self.instructor1 = factories.PersonFactory(partner=self.partner,
                                                given_name='Instructor1')
     self.instructor2 = factories.PersonFactory(partner=self.partner,
                                                given_name='Instructor2')
     self.instructor3 = factories.PersonFactory(partner=self.partner,
                                                given_name='Instructor3')
     self.position = factories.PositionFactory(person=self.person)
     self.social1 = factories.PersonSocialNetworkFactory(person=self.person)
     self.social2 = factories.PersonSocialNetworkFactory(person=self.person)
     self.endorsement = factories.EndorsementFactory(endorser=self.person)
     self.course = factories.CourseFactory(partner=self.partner)
     self.courserun1 = factories.CourseRunFactory(course=self.course,
                                                  staff=[
                                                      self.instructor1,
                                                      self.person,
                                                      self.instructor2,
                                                      self.instructor3,
                                                  ])
     self.courserun2 = factories.CourseRunFactory(course=self.course,
                                                  staff=[
                                                      self.instructor1,
                                                      self.instructor2,
                                                      self.person,
                                                      self.instructor3,
                                                  ])
     self.program = factories.ProgramFactory(courses=[self.course],
                                             instructor_ordering=[
                                                 self.person,
                                                 self.instructor1,
                                                 self.instructor2,
                                                 self.instructor3,
                                             ])
     self.publisher_course = publisher_factories.CourseFactory()
     self.publisher_courserun1 = publisher_factories.CourseRunFactory(
         course=self.publisher_course,
         staff=[
             self.person,
             self.instructor1,
             self.instructor2,
             self.instructor3,
         ])
     self.publisher_courserun2 = publisher_factories.CourseRunFactory(
         course=self.publisher_course,
         staff=[
             self.instructor1,
             self.instructor2,
             self.instructor3,
             self.person,
         ])
예제 #2
0
 def setUp(self):
     super(AutocompleteTests, self).setUp()
     self.user = UserFactory(is_staff=True)
     self.client.login(username=self.user.username, password=USER_PASSWORD)
     self.courses = factories.CourseFactory.create_batch(3, title='Some random course title')
     for course in self.courses:
         factories.CourseRunFactory(course=course)
     self.organizations = factories.OrganizationFactory.create_batch(3)
     first_instructor = factories.PersonFactory(given_name="First Instructor")
     second_instructor = factories.PersonFactory(given_name="Second Instructor")
     self.instructors = [first_instructor, second_instructor]
예제 #3
0
    def test_get_profile_image_url(self):
        """
        Verify that property returns profile_image_url if profile_image_url
        exists other wise it returns uploaded image url.
        """
        self.assertEqual(self.person.get_profile_image_url,
                         self.person.profile_image_url)

        # create another person with out profile_image_url
        person = factories.PersonFactory(profile_image_url=None)
        self.assertEqual(person.get_profile_image_url,
                         person.profile_image.url)

        # create another person with out profile_image_url and profile_image
        person = factories.PersonFactory(profile_image_url=None,
                                         profile_image=None)
        self.assertFalse(person.get_profile_image_url)
예제 #4
0
    def test_connection_error(self):
        image_url = 'https://example.com/image.jpg'
        person = factories.PersonFactory(profile_image_url=image_url)
        self._configutation([str(person.uuid)])

        with mock.patch(self.LOGGER_PATH) as mock_logger:
            call_command('download_drupal_instructor_image')
            mock_logger.exception.assert_called_with(
                'Connection failure downloading image for {instructor}, [{uuid}], from {url}'
                .format(instructor=person.full_name,
                        uuid=person.uuid,
                        url=person.profile_image_url))

            person.refresh_from_db()
            # Image would not be saved because the new image failed to download
            assert person.profile_image.url != person.profile_image_url  # pylint: disable=no-member
예제 #5
0
    def test_unknown_content_type(self):
        image_url, _ = self._mock_image_response(content_type='unknown')
        person = factories.PersonFactory(profile_image_url=image_url)
        self._configutation([str(person.uuid)])

        with mock.patch(self.LOGGER_PATH) as mock_logger:
            call_command('download_drupal_instructor_image')
            mock_logger.error.assert_called_with(
                'Unknown content type for instructor [{instructor}], [{uuid}], and url [{url}]'
                .format(instructor=person.full_name,
                        uuid=person.uuid,
                        url=person.profile_image_url))
            assert len(responses.calls) == 1

            person.refresh_from_db()
            # Image would not be saved because the new image failed to download
            assert person.profile_image.url != person.profile_image_url  # pylint: disable=no-member
예제 #6
0
    def test_image_not_found(self):
        image_url, _ = self._mock_image_response(status=404)
        person = factories.PersonFactory(profile_image_url=image_url)
        self._configutation([str(person.uuid)])

        with mock.patch(self.LOGGER_PATH) as mock_logger:
            call_command('download_drupal_instructor_image')
            mock_logger.error.assert_called_with(
                'Failed to retrieve Image for {name}, [{uuid}], at {url} with status code [{status_code}]'
                .format(name=person.full_name,
                        uuid=person.uuid,
                        url=person.profile_image_url,
                        status_code=404))
            assert len(responses.calls) == 1

            person.refresh_from_db()
            # Image would not be saved because the new image failed to download
            assert person.profile_image.url != person.profile_image_url  # pylint: disable=no-member
예제 #7
0
    def test_image_already_downloaded(self):
        _, image_content = self._mock_image_response()
        person = factories.PersonFactory(
            profile_image=ContentFile(image_content, name='tmp.png'))
        self._configutation([str(person.uuid)])

        # In the application code when a user uploads an image in Publisher UI
        # the profile_image_url will be set to the profile_image.url.
        person.profile_image_url = person.profile_image.url  # pylint: disable=no-member
        person.save()
        person.refresh_from_db()

        call_command('download_drupal_instructor_image')

        # API should not be called
        assert len(responses.calls) == 0

        person.refresh_from_db()
        assert person.profile_image.url == person.profile_image_url  # pylint: disable=no-member
예제 #8
0
 def setUp(self):
     super(EndorsementTests, self).setUp()
     self.person = factories.PersonFactory()
     self.endorsement = Endorsement.objects.create(endorser=self.person,
                                                   quote='test quote')
예제 #9
0
 def setUp(self):
     super(PersonSocialNetworkTests, self).setUp()
     self.network = factories.PersonSocialNetworkFactory()
     self.person = factories.PersonFactory()
예제 #10
0
 def setUp(self):
     super(PersonTests, self).setUp()
     self.person = factories.PersonFactory()
예제 #11
0
 def _setup_person_with_image(self):
     image_url, _ = self._mock_image_response()
     person = factories.PersonFactory(profile_image_url=image_url)
     return person