示例#1
0
 def test_specific_paths_take_priority_in_database_config(self):
     self.course1.url_redirects.create(course=self.course1,
                                       partner=self.partner,
                                       value='/courses/course1/better')
     config = RemoveRedirectsConfig.get_solo()
     config.url_paths = '/courses/course1'
     config.remove_all = True
     config.save()
     call_command('remove_redirects_from_courses', '--args-from-database')
     self.assertEqual(self.course1.url_redirects.count(), 1)
示例#2
0
    def test_remove_multiple_specific_different_courses(self):
        active_url_slug = self.course1.active_url_slug
        config = RemoveRedirectsConfig.get_solo()
        config.url_paths = '/courses/course2 /courses/course1 course/older_course1_slug'
        config.save()
        call_command('remove_redirects_from_courses', '--args-from-database')

        self.assertEqual(self.course1.active_url_slug, active_url_slug)
        self.assertEqual(self.course1.url_slug_history.count(), 1)
        self.assertEqual(self.course1.url_redirects.count(), 0)
        self.assertEqual(self.course2.url_redirects.count(), 0)
示例#3
0
    def test_remove_multiple_specific_same_course(self):
        active_url_slug = self.course1.active_url_slug
        self.course1.url_redirects.create(course=self.course1,
                                          partner=self.partner,
                                          value='/courses/course1/better')
        config = RemoveRedirectsConfig.get_solo()
        config.url_paths = '/courses/course1/better /courses/course1 course/older_course1_slug'
        config.save()
        call_command('remove_redirects_from_courses', '--args-from-database')

        self.assertEqual(self.course1.active_url_slug, active_url_slug)
        self.assertEqual(self.course1.url_slug_history.count(), 1)
        self.assertEqual(self.course1.url_redirects.count(), 0)
示例#4
0
    def test_remove_all(self, argument_source, argument):
        course1_active_url_slug = self.course1.active_url_slug
        course2_active_url_slug = self.course2.active_url_slug

        if argument_source == 'database':
            config = RemoveRedirectsConfig.get_solo()
            config.remove_all = True
            config.save()
        call_command('remove_redirects_from_courses', argument)

        # make sure active url_slugs remain
        self.assertEqual(self.course1.active_url_slug, course1_active_url_slug)
        self.assertEqual(self.course1.url_slug_history.count(), 1)
        self.assertEqual(self.course1.url_redirects.count(), 0)

        self.assertEqual(self.course2.active_url_slug, course2_active_url_slug)
        self.assertEqual(self.course2.url_redirects.count(), 0)
    def test_remove_specific_path(self, argument_source, path, is_removed):
        self.course1.url_redirects.create(course=self.course1,
                                          partner=self.partner,
                                          value='/courses/course1/better')
        if argument_source == 'database':
            config = RemoveRedirectsConfig.get_solo()
            config.url_paths = path
            config.save()
            call_command('remove_redirects_from_courses',
                         '--args-from-database')
        else:
            call_command('remove_redirects_from_courses', '-url_paths', path)

        course1_url_paths = list(
            map(lambda x: x.value, self.course1.url_redirects.all()))

        # check we removed the relevant path
        assert ('/courses/course1' not in course1_url_paths) == is_removed

        # check we didn't remove anything else
        assert '/courses/course1/better' in course1_url_paths
示例#6
0
    def test_remove_specific_slug(self, argument_source, path):
        course1_active_url_slug = self.course1.active_url_slug
        self.course1.url_slug_history.create(course=self.course1,
                                             url_slug='ancient_course1_slug',
                                             partner=self.partner)
        if argument_source == 'database':
            config = RemoveRedirectsConfig.get_solo()
            config.url_paths = path
            config.save()
            call_command('remove_redirects_from_courses',
                         '--args-from-database')
        else:
            call_command('remove_redirects_from_courses', '-url_paths', path)

        course1_url_slugs = list(
            map(lambda x: x.url_slug, self.course1.url_slug_history.all()))

        # check we removed the relevant slug
        self.assertNotIn('ancient_course1_slug', course1_url_slugs)

        # check we didn't remove anything else
        self.assertIn(course1_active_url_slug, course1_url_slugs)
        self.assertIn('older_course1_slug', course1_url_slugs)
 def get_args_from_database(self):
     config = RemoveRedirectsConfig.get_solo()
     return {
         "remove_all": config.remove_all,
         "url_paths": config.url_paths.split()
     }