def setUp(self): super(AutoCompletePersonTests, self).setUp() self.user = UserFactory(is_staff=True) self.client.login(username=self.user.username, password=USER_PASSWORD) first_instructor = PersonFactory(given_name="First", family_name="Instructor") second_instructor = PersonFactory(given_name="Second", family_name="Instructor") self.instructors = [first_instructor, second_instructor] self.organizations = OrganizationFactory.create_batch(3) self.organization_extensions = [] for instructor in self.instructors: PositionFactory(organization=self.organizations[0], title="professor", person=instructor) for organization in self.organizations: org_ex = publisher_factories.OrganizationExtensionFactory( organization=organization) self.organization_extensions.append(org_ex) disco_course = CourseFactory( authoring_organizations=[self.organizations[0]]) disco_course2 = CourseFactory( authoring_organizations=[self.organizations[1]]) CourseRunFactory(course=disco_course, staff=[first_instructor]) CourseRunFactory(course=disco_course2, staff=[second_instructor]) self.user.groups.add(self.organization_extensions[0].group)
def setUp(self): super(AutoCompletePersonTests, 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 = OrganizationFactory.create_batch(3) self.organization_extensions = [] for organization in self.organizations: self.organization_extensions.append( factories.OrganizationExtensionFactory( organization=organization)) self.user.groups.add(self.organization_extensions[0].group) first_instructor = PersonFactory(given_name="First", family_name="Instructor") second_instructor = PersonFactory(given_name="Second", family_name="Instructor") self.instructors = [first_instructor, second_instructor] for instructor in self.instructors: PositionFactory(organization=self.organizations[0], title="professor", person=instructor)
def setUpClass(cls): super().setUpClass() cls.user = UserFactory(is_staff=True) first_instructor = PersonFactory(given_name="First", family_name="Instructor") second_instructor = PersonFactory(given_name="Second", family_name="Instructor") cls.instructors = [first_instructor, second_instructor] cls.organizations = OrganizationFactory.create_batch(3) cls.organization_extensions = [] for instructor in cls.instructors: PositionFactory(organization=cls.organizations[0], title="professor", person=instructor) for organization in cls.organizations: cls.organization_extensions.append( OrganizationExtensionFactory(organization=organization)) disco_course = CourseFactory( authoring_organizations=[cls.organizations[0]]) disco_course2 = CourseFactory( authoring_organizations=[cls.organizations[1]]) CourseRunFactory(course=disco_course, staff=[first_instructor]) CourseRunFactory(course=disco_course2, staff=[second_instructor]) cls.user.groups.add(cls.organization_extensions[0].group)
def test_data(self): position = PositionFactory() serializer = PositionSerializer(position) expected = { 'title': str(position.title), 'organization_name': position.organization_name, } self.assertDictEqual(serializer.data, expected)
def setUp(self): super(PersonViewSetTests, self).setUp() self.user = UserFactory(is_staff=True, is_superuser=True) self.user.groups.add(Group.objects.get(name=INTERNAL_USER_GROUP_NAME)) self.client.force_authenticate(self.user) self.person = PersonFactory(partner=self.partner) self.organization = OrganizationFactory(partner=self.partner) PositionFactory(person=self.person, organization=self.organization) toggle_switch('publish_person_to_marketing_site', True) self.expected_node = { 'resource': 'node', '' 'id': '28691', 'uuid': '18d5542f-fa80-418e-b416-455cfdeb4d4e', 'uri': 'https://stage.edx.org/node/28691' }
def test_data(self): position = PositionFactory() person = position.person serializer = PersonSerializer(person) expected = { 'uuid': str(person.uuid), 'given_name': person.given_name, 'family_name': person.family_name, 'bio': person.bio, 'profile_image_url': person.profile_image_url, 'position': PositionSerializer(position).data, 'slug': person.slug, } self.assertDictEqual(serializer.data, expected)
def setUp(self): super(PersonViewSetTests, self).setUp() self.user = UserFactory(is_staff=True, is_superuser=True) self.client.force_authenticate(self.user) self.person = PersonFactory() PositionFactory(person=self.person) self.organization = OrganizationFactory() # DEFAULT_PARTNER_ID is used explicitly here to avoid issues with differences in # auto-incrementing behavior across databases. Otherwise, it's not safe to assume # that the partner created here will always have id=DEFAULT_PARTNER_ID. self.partner = PartnerFactory(id=settings.DEFAULT_PARTNER_ID) toggle_switch('publish_person_to_marketing_site', True) self.expected_node = { 'resource': 'node', '' 'id': '28691', 'uuid': '18d5542f-fa80-418e-b416-455cfdeb4d4e', 'uri': 'https://stage.edx.org/node/28691' }
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)
def setUp(self): super(PersonViewSetTests, self).setUp() self.user = UserFactory() self.target_permissions = Permission.objects.filter( codename__in=['add_person', 'change_person', 'delete_person']) internal_test_group = Group.objects.create(name='internal-test') internal_test_group.permissions.add(*self.target_permissions) self.user.groups.add(internal_test_group) self.client.login(username=self.user.username, password=USER_PASSWORD) self.person = PersonFactory(partner=self.partner) self.organization = OrganizationFactory(partner=self.partner) PositionFactory(person=self.person, organization=self.organization) toggle_switch('publish_person_to_marketing_site', True) self.expected_node = { 'resource': 'node', '' 'id': '28691', 'uuid': '18d5542f-fa80-418e-b416-455cfdeb4d4e', 'uri': 'https://stage.edx.org/node/28691' }
def test_course_staff(self): """Verify that the wrapper return staff list.""" staff = PersonFactory() # another staff with position staff_2 = PersonFactory() position = PositionFactory(person=staff_2) self.course_run.staff = [staff, staff_2] self.course_run.save() expected = [{ 'full_name': staff.full_name, 'image_url': staff.get_profile_image_url, }, { 'full_name': staff_2.full_name, 'image_url': staff_2.get_profile_image_url, 'position': position.title, 'organization': position.organization_name }] self.assertEqual(self.wrapped_course_run.course_staff, expected)
def setUp(self): super().setUp() self.user = UserFactory() self.request.user = self.user self.target_permissions = Permission.objects.filter( codename__in=['add_person', 'change_person', 'delete_person']) self.internal_test_group = Group.objects.create(name='internal-test') self.internal_test_group.permissions.add(*self.target_permissions) self.user.groups.add(self.internal_test_group) self.client.login(username=self.user.username, password=USER_PASSWORD) with override_switch('publish_person_to_marketing_site', False): self.person = PersonFactory(partner=self.partner) self.organization = OrganizationFactory(partner=self.partner) PositionFactory(person=self.person, organization=self.organization) self.expected_node = { 'resource': 'node', 'id': '28691', 'uuid': '18d5542f-fa80-418e-b416-455cfdeb4d4e', 'uri': 'https://stage.edx.org/node/28691' } self.partner.marketing_site_api_username = self._original_partner_marketing_site_api_username self.partner.save()
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)