def test_list(self):
        """ Verify the endpoint returns a list of all organizations. """

        OrganizationFactory.create_batch(3)

        with self.assertNumQueries(6):
            response = self.client.get(self.list_path)

        self.assertEqual(response.status_code, 200)
        self.assert_response_data_valid(response, Organization.objects.all())
    def test_list_uuid_filter(self):
        """ Verify the endpoint returns a list of organizations filtered by UUID. """

        organizations = OrganizationFactory.create_batch(3)

        # Test with a single UUID
        self.assert_list_uuid_filter([organizations[0]])

        # Test with multiple UUIDs
        self.assert_list_uuid_filter(organizations)
Example #3
0
    def test_data(self):
        authoring_organization, crediting_organization = OrganizationFactory.create_batch(2)
        program = ProgramFactory(authoring_organizations=[authoring_organization],
                                 credit_backing_organizations=[crediting_organization])

        # NOTE: This serializer expects SearchQuerySet results, so we run a search on the newly-created object
        # to generate such a result.
        result = SearchQuerySet().models(Program).filter(uuid=program.uuid)[0]
        serializer = ProgramSearchSerializer(result)

        expected = self._create_expected_data(program)
        self.assertDictEqual(serializer.data, expected)
Example #4
0
    def test_typeahead_authoring_organizations_partial_search(self):
        """ Test typeahead response with partial organization matching. """
        authoring_organizations = OrganizationFactory.create_batch(3)
        course_run = CourseRunFactory(authoring_organizations=authoring_organizations, course__partner=self.partner)
        program = ProgramFactory(authoring_organizations=authoring_organizations, partner=self.partner)
        partial_key = authoring_organizations[0].key[0:5]

        response = self.get_typeahead_response(partial_key)
        self.assertEqual(response.status_code, 200)
        expected = {
            'course_runs': [self.serialize_course_run(course_run)],
            'programs': [self.serialize_program(program)]
        }
        self.assertDictEqual(response.data, expected)
    def test_list_tag_filter(self):
        """ Verify the endpoint returns a list of organizations filtered by tag. """

        tag = 'test-org'
        organizations = OrganizationFactory.create_batch(2)

        # If no organizations have been tagged, the endpoint should not return any data
        self.assert_list_tag_filter([], [tag], expected_query_count=4)

        # Tagged organizations should be returned
        organizations[0].tags.add(tag)
        self.assert_list_tag_filter([organizations[0]], [tag])

        # The endpoint should support filtering by multiple tags. The filter should be an OR filter, meaning the results
        # include any organization containing at least one of the given tags.
        tag2 = 'another-tag'
        organizations[1].tags.add(tag)
        self.assert_list_tag_filter(Organization.objects.all(), [tag, tag2])
Example #6
0
 def test_typeahead_multiple_authoring_organizations(self):
     """ Test typeahead response with multiple authoring organizations. """
     title = "Design"
     authoring_organizations = OrganizationFactory.create_batch(3)
     course_run = CourseRunFactory(
         title=title,
         authoring_organizations=authoring_organizations,
         course__partner=self.partner
     )
     program = ProgramFactory(
         title=title, authoring_organizations=authoring_organizations,
         status=ProgramStatus.Active, partner=self.partner
     )
     response = self.get_typeahead_response(title)
     self.assertEqual(response.status_code, 200)
     response_data = response.json()
     self.assertDictEqual(response_data, {'course_runs': [self.serialize_course_run(course_run)],
                                          'programs': [self.serialize_program(program)]})
Example #7
0
    def create_program(self):
        organizations = OrganizationFactory.create_batch(2)
        person = PersonFactory()

        courses = CourseFactory.create_batch(3)
        for course in courses:
            CourseRunFactory.create_batch(2, course=course, staff=[person], start=datetime.now())

        return ProgramFactory(
            courses=courses,
            authoring_organizations=organizations,
            credit_backing_organizations=organizations,
            corporate_endorsements=CorporateEndorsementFactory.create_batch(1),
            individual_endorsements=EndorsementFactory.create_batch(1),
            expected_learning_items=ExpectedLearningItemFactory.create_batch(1),
            job_outlook_items=JobOutlookItemFactory.create_batch(1),
            banner_image=make_image_file('test_banner.jpg'),
            video=VideoFactory(),
            order_courses_by_start_date=False,
        )
Example #8
0
 def test_data_multiple_authoring_organizations(self):
     authoring_organizations = OrganizationFactory.create_batch(3)
     program = ProgramFactory(authoring_organizations=authoring_organizations)
     serialized_program = self.serialize_program(program)
     expected = [org.key for org in authoring_organizations]
     self.assertEqual(serialized_program.data['orgs'], expected)