Example #1
0
    def test_course_staff(self):
        """Verify that the wrapper return staff list."""
        staff = PersonFactory()
        staff.profile_image_url = None
        staff.save()

        # another staff with position by default staff has no position associated.
        staff_2 = PersonFactory()
        position = PositionFactory(person=staff_2)

        self.course_run.staff = [staff, staff_2]
        self.course_run.save()

        facebook = PersonSocialNetworkFactory(person=staff_2, type='facebook')
        twitter = PersonSocialNetworkFactory(person=staff_2, type='twitter')

        expected = [{
            'uuid': str(staff.uuid),
            'full_name': staff.full_name,
            'image_url': staff.get_profile_image_url,
            'profile_url': staff.profile_url,
            'social_networks': {},
            'bio': staff.bio,
            'is_new': True,
            'email': staff.email
        }, {
            'uuid': str(staff_2.uuid),
            'full_name': staff_2.full_name,
            'image_url': staff_2.get_profile_image_url,
            'position': position.title,
            'organization': position.organization_name,
            'profile_url': staff.profile_url,
            'is_new': False,
            'social_networks': {
                'facebook': facebook.value,
                'twitter': twitter.value
            },
            'bio': staff_2.bio,
            'email': staff_2.email
        }]

        self.assertEqual(self.wrapped_course_run.course_staff, expected)
Example #2
0
    def test_update(self):
        """Verify that people data can be updated using endpoint."""
        url = reverse('api:v1:person-detail', kwargs={'uuid': self.person.uuid})

        data = self._update_person_data()

        # These are being created so we can verify they are deleted since they are not part of updated_data
        PersonSocialNetworkFactory(person=self.person, type='blog')
        removed_value = PersonAreaOfExpertiseFactory(person=self.person).value

        with mock.patch.object(MarketingSitePeople, 'update_or_publish_person', return_value={}):
            response = self.client.patch(url, data, format='json')
            self.assertEqual(response.status_code, 200)

        updated_person = Person.objects.get(id=self.person.id)

        self.assertEqual(updated_person.given_name, data['given_name'])
        self.assertEqual(updated_person.family_name, data['family_name'])
        self.assertEqual(updated_person.bio, data['bio'])
        self.assertEqual(updated_person.position.title, data['position']['title'])
        self.assertEqual(updated_person.major_works, data['major_works'])
        self.assertListEqual(
            sorted([social_network.url for social_network in updated_person.person_networks.all()]),
            sorted([url_detailed['url'] for url_detailed in data['urls_detailed']])
        )
        self.assertListEqual(
            sorted([social_network.title for social_network in updated_person.person_networks.all()]),
            sorted([url_detailed['title'] for url_detailed in data['urls_detailed']])
        )
        self.assertFalse(updated_person.person_networks.filter(type='blog').exists())

        # Test display_title
        # Test that empty string titles get changed to type when looking at display title for not OTHERS
        self.assertEqual('Facebook', updated_person.person_networks.get(type='facebook', title='').display_title)
        # Test that defined titles are shown
        self.assertEqual(
            'Hopkins new Twitter',
            updated_person.person_networks.get(type='twitter', title='Hopkins new Twitter').display_title
        )
        self.assertEqual(
            'new others', updated_person.person_networks.get(type='others', title='new others').display_title
        )
        self.assertEqual(
            'Create new', updated_person.person_networks.get(type='others', title='Create new').display_title
        )

        self.assertListEqual(
            sorted([area_of_expertise.value for area_of_expertise in updated_person.areas_of_expertise.all()]),
            sorted([area_of_expertise['value'] for area_of_expertise in data['areas_of_expertise']])
        )
        self.assertFalse(updated_person.areas_of_expertise.filter(value=removed_value).exists())
    def test_course_staff(self):
        """Verify that the wrapper return staff list."""
        staff = PersonFactory()
        staff.profile_image_url = None
        staff.save()

        # another staff with position by default staff has no position associated.
        staff_2 = PersonFactory()
        position = PositionFactory(person=staff_2)

        self.course_run.staff = [staff, staff_2]
        self.course_run.save()

        facebook = PersonSocialNetworkFactory(person=staff_2, type='facebook')
        twitter = PersonSocialNetworkFactory(person=staff_2,
                                             type='twitter',
                                             title='@MrTerry')

        area_1 = PersonAreaOfExpertiseFactory(person=staff)
        area_2 = PersonAreaOfExpertiseFactory(person=staff)
        area_3 = PersonAreaOfExpertiseFactory(person=staff_2)

        expected = [{
            'uuid':
            str(staff.uuid),
            'full_name':
            staff.full_name,
            'image_url':
            staff.get_profile_image_url,
            'profile_url':
            staff.profile_url,
            'social_networks': [],
            'major_works':
            staff.major_works,
            'bio':
            staff.bio,
            'areas_of_expertise': [
                {
                    'id': area_1.id,
                    'value': area_1.value
                },
                {
                    'id': area_2.id,
                    'value': area_2.value
                },
            ],
        }, {
            'uuid':
            str(staff_2.uuid),
            'full_name':
            staff_2.full_name,
            'image_url':
            staff_2.get_profile_image_url,
            'position':
            position.title,
            'organization':
            position.organization_name,
            'profile_url':
            staff_2.profile_url,
            'social_networks': [
                {
                    'id': facebook.id,
                    'type': facebook.type,
                    'url': facebook.url,
                    'title': facebook.title,
                },
                {
                    'id': twitter.id,
                    'type': twitter.type,
                    'url': twitter.url,
                    'title': twitter.title,
                },
            ],
            'bio':
            staff_2.bio,
            'major_works':
            staff_2.major_works,
            'areas_of_expertise': [
                {
                    'id': area_3.id,
                    'value': area_3.value
                },
            ],
        }]
        self.assertEqual(self.wrapped_course_run.course_staff, expected)