Beispiel #1
0
    def assert_program_loaded(self, body):
        """ Assert a Program corresponding to the specified data body was properly loaded into the database. """
        program = Program.objects.get(uuid=AbstractDataLoader.clean_string(body['uuid']), partner=self.partner)

        self.assertEqual(program.title, body['name'])
        for attr in ('subtitle', 'status', 'marketing_slug',):
            self.assertEqual(getattr(program, attr), AbstractDataLoader.clean_string(body[attr]))

        self.assertEqual(program.type, ProgramType.objects.get(name='XSeries'))

        keys = [org['key'] for org in body['organizations']]
        expected_organizations = list(Organization.objects.filter(key__in=keys))
        self.assertEqual(keys, [org.key for org in expected_organizations])
        self.assertListEqual(list(program.authoring_organizations.all()), expected_organizations)

        banner_image_url = body.get('banner_image_urls', {}).get('w1440h480')
        self.assertEqual(program.banner_image_url, banner_image_url)

        course_run_keys = set()
        course_codes = body.get('course_codes', [])
        for course_code in course_codes:
            course_run_keys.update([course_run['course_key'] for course_run in course_code['run_modes']])

        courses = list(Course.objects.filter(course_runs__key__in=course_run_keys).distinct().order_by('key'))
        self.assertEqual(list(program.courses.order_by('key')), courses)

        # Verify the additional course runs added in create_mock_courses_and_runs are excluded.
        self.assertEqual(program.excluded_course_runs.count(), len(course_codes))
Beispiel #2
0
 def assert_organization_loaded(self, body, partner_has_marketing_site=True):
     """ Assert an Organization corresponding to the specified data body was properly loaded into the database. """
     organization = Organization.objects.get(key=AbstractDataLoader.clean_string(body['short_name']))
     if not partner_has_marketing_site:
         self.assertEqual(organization.name, AbstractDataLoader.clean_string(body['name']))
         self.assertEqual(organization.description, AbstractDataLoader.clean_string(body['description']))
         self.assertEqual(organization.logo_image_url, AbstractDataLoader.clean_string(body['logo']))
Beispiel #3
0
    def assert_program_loaded(self, body):
        """ Assert a Program corresponding to the specified data body was properly loaded into the database. """
        program = Program.objects.get(uuid=AbstractDataLoader.clean_string(body['uuid']), partner=self.partner)

        self.assertEqual(program.title, body['name'])
        for attr in ('subtitle', 'status', 'marketing_slug',):
            self.assertEqual(getattr(program, attr), AbstractDataLoader.clean_string(body[attr]))

        self.assertEqual(program.type, ProgramType.objects.get(name='XSeries'))

        keys = [org['key'] for org in body['organizations']]
        expected_organizations = list(Organization.objects.filter(key__in=keys))
        self.assertEqual(keys, [org.key for org in expected_organizations])
        self.assertListEqual(list(program.authoring_organizations.all()), expected_organizations)

        banner_image_url = body.get('banner_image_urls', {}).get('w1440h480')
        self.assertEqual(program.banner_image_url, banner_image_url)

        course_run_keys = set()
        course_codes = body.get('course_codes', [])
        for course_code in course_codes:
            course_run_keys.update([course_run['course_key'] for course_run in course_code['run_modes']])

        courses = list(Course.objects.filter(course_runs__key__in=course_run_keys).distinct().order_by('key'))
        self.assertEqual(list(program.courses.order_by('key')), courses)

        # Verify the additional course runs added in create_mock_courses_and_runs are excluded.
        self.assertEqual(program.excluded_course_runs.count(), len(course_codes))
Beispiel #4
0
 def assert_organization_loaded(self, body, partner_has_marketing_site=True):
     """ Assert an Organization corresponding to the specified data body was properly loaded into the database. """
     organization = Organization.objects.get(key=AbstractDataLoader.clean_string(body['short_name']))
     if not partner_has_marketing_site:
         self.assertEqual(organization.name, AbstractDataLoader.clean_string(body['name']))
         self.assertEqual(organization.description, AbstractDataLoader.clean_string(body['description']))
         self.assertEqual(organization.logo_image_url, AbstractDataLoader.clean_string(body['logo']))
         self.assertEqual(organization.certificate_logo_image_url, AbstractDataLoader.clean_string(body['logo']))
Beispiel #5
0
 def assert_program_banner_image_loaded(self, body):
     """ Assert a program corresponding to the specified data body has banner image loaded into DB """
     program = Program.objects.get(uuid=AbstractDataLoader.clean_string(body['uuid']), partner=self.partner)
     banner_image_url = body.get('banner_image_urls', {}).get('w1440h480')
     if banner_image_url:
         for size_key in program.banner_image.field.variations:
             # Get different sizes specs from the model field
             # Then get the file path from the available files
             sized_image = getattr(program.banner_image, size_key, None)
             self.assertIsNotNone(sized_image)
             if sized_image:
                 path = getattr(program.banner_image, size_key).url
                 self.assertIsNotNone(path)
                 self.assertIsNotNone(program.banner_image.field.variations[size_key]['width'])
                 self.assertIsNotNone(program.banner_image.field.variations[size_key]['height'])
Beispiel #6
0
 def assert_program_banner_image_loaded(self, body):
     """ Assert a program corresponding to the specified data body has banner image loaded into DB """
     program = Program.objects.get(uuid=AbstractDataLoader.clean_string(body['uuid']), partner=self.partner)
     banner_image_url = body.get('banner_image_urls', {}).get('w1440h480')
     if banner_image_url:
         for size_key in program.banner_image.field.variations:
             # Get different sizes specs from the model field
             # Then get the file path from the available files
             sized_image = getattr(program.banner_image, size_key, None)
             self.assertIsNotNone(sized_image)
             if sized_image:
                 path = getattr(program.banner_image, size_key).url
                 self.assertIsNotNone(path)
                 self.assertIsNotNone(program.banner_image.field.variations[size_key]['width'])
                 self.assertIsNotNone(program.banner_image.field.variations[size_key]['height'])
Beispiel #7
0
    def test_clean_string(self):
        """ Verify the method leading and trailing spaces, and returns None for empty strings. """
        # Do nothing for non-string input
        self.assertIsNone(AbstractDataLoader.clean_string(None))
        self.assertEqual(AbstractDataLoader.clean_string(3.14), 3.14)

        # Return None for empty strings
        self.assertIsNone(AbstractDataLoader.clean_string(''))
        self.assertIsNone(AbstractDataLoader.clean_string('    '))
        self.assertIsNone(AbstractDataLoader.clean_string('\t'))

        # Return the stripped value for non-empty strings
        for s in ('\tabc', 'abc', ' abc ', 'abc ', '\tabc\t '):
            self.assertEqual(AbstractDataLoader.clean_string(s), 'abc')
Beispiel #8
0
    def test_clean_string(self):
        """ Verify the method leading and trailing spaces, and returns None for empty strings. """
        # Do nothing for non-string input
        assert AbstractDataLoader.clean_string(None) is None
        assert AbstractDataLoader.clean_string(3.14) == 3.14

        # Return None for empty strings
        assert AbstractDataLoader.clean_string('') is None
        assert AbstractDataLoader.clean_string('    ') is None
        assert AbstractDataLoader.clean_string('\t') is None

        # Return the stripped value for non-empty strings
        for s in ('\tabc', 'abc', ' abc ', 'abc ', '\tabc\t '):
            assert AbstractDataLoader.clean_string(s) == 'abc'
Beispiel #9
0
    def test_clean_string(self):
        """ Verify the method leading and trailing spaces, and returns None for empty strings. """
        # Do nothing for non-string input
        self.assertIsNone(AbstractDataLoader.clean_string(None))
        self.assertEqual(AbstractDataLoader.clean_string(3.14), 3.14)

        # Return None for empty strings
        self.assertIsNone(AbstractDataLoader.clean_string(''))
        self.assertIsNone(AbstractDataLoader.clean_string('    '))
        self.assertIsNone(AbstractDataLoader.clean_string('\t'))

        # Return the stripped value for non-empty strings
        for s in ('\tabc', 'abc', ' abc ', 'abc ', '\tabc\t '):
            self.assertEqual(AbstractDataLoader.clean_string(s), 'abc')