from django.conf import settings
from django.test import TestCase

from reviewboard.admin import checks


class UpdateTests(TestCase):
    """Tests for update required pages"""

    def tearDown(self):
        # Make sure we don't break further tests by resetting this fully.
        checks.reset_check_cache()

    def testManualUpdatesRequired(self):
        """Testing check_updates_required with valid configuration"""
        # NOTE: This is assuming the install is fine. It should be given
        #       that we set things like the uploaded path correctly to
        #       a known good directory before starting unit tests.
        updates_required = checks.check_updates_required()

        self.assertEqual(len(updates_required), 0)

    def testManualUpdatesRequiredBadUpload(self):
        """Testing check_updates_required with a bad upload directory"""
        old_media_root = settings.MEDIA_ROOT
        settings.MEDIA_ROOT = "/"
        checks.reset_check_cache()

        updates_required = checks.check_updates_required()
        settings.MEDIA_ROOT = old_media_root

        self.assertEqual(len(updates_required), 1)

        url, data = updates_required[0]
        self.assertEqual(url, "admin/manual-updates/media-upload-dir.html")

        response = self.client.get("/")
        self.assertEqual(response.status_code, 200)
        self.assertTemplateUsed(response, "admin/manual_updates_required.html")

from django.conf import settings
from django.test import TestCase

from reviewboard.admin import checks


class UpdateTests(TestCase):
    """Tests for update required pages"""

    def tearDown(self):
        # Make sure we don't break further tests by resetting this fully.
        checks.reset_check_cache()

    def testManualUpdatesRequired(self):
        """Testing check_updates_required with valid configuration"""
        # NOTE: This is assuming the install is fine. It should be given
        #       that we set things like the uploaded path correctly to
        #       a known good directory before starting unit tests.
        updates_required = checks.check_updates_required()

        self.assertEqual(len(updates_required), 0)

    def testManualUpdatesRequiredBadMediaDirs(self):
        """Testing check_updates_required with bad media directories"""
        old_media_root = settings.MEDIA_ROOT
        settings.MEDIA_ROOT = "/"
        checks.reset_check_cache()

        updates_required = checks.check_updates_required()
        settings.MEDIA_ROOT = old_media_root

        # Should complain about ext and upload directories.
        self.assertEqual(len(updates_required), 2)

        url, data = updates_required[0]
        self.assertEqual(url, "admin/manual-updates/media-upload-dir.html")

        url, data = updates_required[1]
        self.assertEqual(url, "admin/manual-updates/ext-dir.html")

        response = self.client.get("/")
        self.assertEqual(response.status_code, 200)
        self.assertTemplateUsed(response, "admin/manual_updates_required.html")

Fix the media manual updates unit test to account for the new ext dir page.
Fix the media manual updates unit test to account for the new ext dir page.

My previous change for the extension directory manual updates page broke
the unit tests. The existing test for the upload directory didn't take
into account that the extension directory would also now be needed. The
test was fixed and renamed to signify that it checks for media dirs now.
