
from __future__ import unicode_literals

from django.core.urlresolvers import reverse
from django.test import TestCase
from urltools import compare


class TestURLs(TestCase):
    """Verify project level URL configuration."""

    def test_cas_enabled(self):
        """Verify that CAS is wired up properly when enabled"""
        with self.settings(
            CAS_ENABLED=True,
            CAS_SERVER_URL='http://example.com/login',
        ):
            # Because this won't actually work, we get in a redirect
            # loop, or at least, best as I can tell.
            response = self.client.get(reverse('cas_login'))
            self.assertTrue(compare(
                'http://example.com/login?'
                'service=http%3A%2F%2Ftestserver%2Fcas%2Flogin%3Fnext%3D%252F',
                response['location']
            ))

    def test_cas_disable(self):
        """Verify that when CAS is disabled, login is default"""
        with self.settings(
            CAS_ENABLED=False
        ):
            response = self.client.get('/login', follow=True)
            self.assertEqual(404, response.status_code)


from __future__ import unicode_literals

from django.core.urlresolvers import reverse
from django.test import TestCase

import ssl

if hasattr(ssl, '_create_unverified_context'):
    ssl._create_default_https_context = ssl._create_unverified_context  # noqa pylint: disable=protected-access

from urltools import compare  # noqa


class TestURLs(TestCase):
    """Verify project level URL configuration."""

    def test_cas_enabled(self):
        """Verify that CAS is wired up properly when enabled"""
        with self.settings(
            CAS_ENABLED=True,
            CAS_SERVER_URL='http://example.com/login',
        ):
            # Because this won't actually work, we get in a redirect
            # loop, or at least, best as I can tell.
            response = self.client.get(reverse('cas_login'))
            self.assertTrue(compare(
                'http://example.com/login?'
                'service=http%3A%2F%2Ftestserver%2Fcas%2Flogin%3Fnext%3D%252F',
                response['location']
            ))

    def test_cas_disable(self):
        """Verify that when CAS is disabled, login is default"""
        with self.settings(
            CAS_ENABLED=False
        ):
            response = self.client.get('/login', follow=True)
            self.assertEqual(404, response.status_code)

Disable SSL validation for a test which uses urltools
Disable SSL validation for a test which uses urltools

This is currently a common problem with python >= 2.7.9:
http://stackoverflow.com/questions/27835619/ssl-certificate-verify-failed-error

  
  from __future__ import unicode_literals
  
  from django.core.urlresolvers import reverse
  from django.test import TestCase
+ 
+ import ssl
+ 
+ if hasattr(ssl, '_create_unverified_context'):
+     ssl._create_default_https_context = ssl._create_unverified_context  # noqa pylint: disable=protected-access
+ 
- from urltools import compare
+ from urltools import compare  # noqa
  
  
  class TestURLs(TestCase):
      """Verify project level URL configuration."""
  
      def test_cas_enabled(self):
          """Verify that CAS is wired up properly when enabled"""
          with self.settings(
              CAS_ENABLED=True,
              CAS_SERVER_URL='http://example.com/login',
          ):
              # Because this won't actually work, we get in a redirect
              # loop, or at least, best as I can tell.
              response = self.client.get(reverse('cas_login'))
              self.assertTrue(compare(
                  'http://example.com/login?'
                  'service=http%3A%2F%2Ftestserver%2Fcas%2Flogin%3Fnext%3D%252F',
                  response['location']
              ))
  
      def test_cas_disable(self):
          """Verify that when CAS is disabled, login is default"""
          with self.settings(
              CAS_ENABLED=False
          ):
              response = self.client.get('/login', follow=True)
              self.assertEqual(404, response.status_code)
  
Disable SSL validation for a test which uses urltools
## Code Before:

from __future__ import unicode_literals

from django.core.urlresolvers import reverse
from django.test import TestCase
from urltools import compare


class TestURLs(TestCase):
    """Verify project level URL configuration."""

    def test_cas_enabled(self):
        """Verify that CAS is wired up properly when enabled"""
        with self.settings(
            CAS_ENABLED=True,
            CAS_SERVER_URL='http://example.com/login',
        ):
            # Because this won't actually work, we get in a redirect
            # loop, or at least, best as I can tell.
            response = self.client.get(reverse('cas_login'))
            self.assertTrue(compare(
                'http://example.com/login?'
                'service=http%3A%2F%2Ftestserver%2Fcas%2Flogin%3Fnext%3D%252F',
                response['location']
            ))

    def test_cas_disable(self):
        """Verify that when CAS is disabled, login is default"""
        with self.settings(
            CAS_ENABLED=False
        ):
            response = self.client.get('/login', follow=True)
            self.assertEqual(404, response.status_code)

## Instruction:
Disable SSL validation for a test which uses urltools
## Code After:

from __future__ import unicode_literals

from django.core.urlresolvers import reverse
from django.test import TestCase

import ssl

if hasattr(ssl, '_create_unverified_context'):
    ssl._create_default_https_context = ssl._create_unverified_context  # noqa pylint: disable=protected-access

from urltools import compare  # noqa


class TestURLs(TestCase):
    """Verify project level URL configuration."""

    def test_cas_enabled(self):
        """Verify that CAS is wired up properly when enabled"""
        with self.settings(
            CAS_ENABLED=True,
            CAS_SERVER_URL='http://example.com/login',
        ):
            # Because this won't actually work, we get in a redirect
            # loop, or at least, best as I can tell.
            response = self.client.get(reverse('cas_login'))
            self.assertTrue(compare(
                'http://example.com/login?'
                'service=http%3A%2F%2Ftestserver%2Fcas%2Flogin%3Fnext%3D%252F',
                response['location']
            ))

    def test_cas_disable(self):
        """Verify that when CAS is disabled, login is default"""
        with self.settings(
            CAS_ENABLED=False
        ):
            response = self.client.get('/login', follow=True)
            self.assertEqual(404, response.status_code)
