from __future__ import unicode_literals

from django.utils.six.moves.urllib.request import urlopen


def url_available(url=None, expected_code=200):
    """ Check availability (HTTP response code) of single resource """
    assert urlopen(url).getcode() == expected_code

from __future__ import unicode_literals

from django.utils.six.moves.urllib.request import urlopen
from django.utils.six.moves.urllib.error import HTTPError


def url_available(url=None, expected_code=200):
    """ Check availability (HTTP response code) of single resource """
    try:
        assert urlopen(url).getcode() == expected_code
    except HTTPError as e:
        assert e.code == expected_code

Fix for testing error pages
Fix for testing error pages

calling url_available(url='http://doesnotexist.com', expected_code=404) # raise exception
  from __future__ import unicode_literals
  
  from django.utils.six.moves.urllib.request import urlopen
+ from django.utils.six.moves.urllib.error import HTTPError
  
  
  def url_available(url=None, expected_code=200):
      """ Check availability (HTTP response code) of single resource """
+     try:
-     assert urlopen(url).getcode() == expected_code
+         assert urlopen(url).getcode() == expected_code
+     except HTTPError as e:
+         assert e.code == expected_code
  
Fix for testing error pages
## Code Before:
from __future__ import unicode_literals

from django.utils.six.moves.urllib.request import urlopen


def url_available(url=None, expected_code=200):
    """ Check availability (HTTP response code) of single resource """
    assert urlopen(url).getcode() == expected_code

## Instruction:
Fix for testing error pages
## Code After:
from __future__ import unicode_literals

from django.utils.six.moves.urllib.request import urlopen
from django.utils.six.moves.urllib.error import HTTPError


def url_available(url=None, expected_code=200):
    """ Check availability (HTTP response code) of single resource """
    try:
        assert urlopen(url).getcode() == expected_code
    except HTTPError as e:
        assert e.code == expected_code
