# vim: tabstop=4 expandtab autoindent shiftwidth=4 fileencoding=utf-8

"""
Assertions that sort of follow Python unittest/Django test cases
"""

from django.test.testcases import TestCase

import re

## Python

from nose import tools
for t in dir(tools):
    if t.startswith('assert_'):
        vars()[t] = getattr(tools, t)

## Django

caps = re.compile('([A-Z])')

def pep8(name):
    return caps.sub(lambda m: '_' + m.groups()[0].lower(), name)


class Dummy(TestCase):
    def nop():
        pass
_t = Dummy('nop')

for at in [ at for at in dir(_t)
            if at.startswith('assert') and not '_' in at ]:
    pepd = pep8(at)
    vars()[pepd] = getattr(_t, at)

del Dummy
del _t
del pep8

## New

def assert_code(response, status_code, msg_prefix=''):
    """Asserts the response was returned with the given status code
    """

    if msg_prefix:
        msg_prefix = '%s: ' % msg_prefix

    assert response.status_code == status_code, \
        'Response code was %d (expected %d)' % \
            (response.status_code, status_code)

def assert_ok(response, msg_prefix=''):
    """Asserts the response was returned with status 200 (OK)
    """

    return assert_code(response, 200, msg_prefix=msg_prefix)

# EOF



# vim: tabstop=4 expandtab autoindent shiftwidth=4 fileencoding=utf-8

"""
Provides Nose and Django test case assert functions
"""

from django.test.testcases import TestCase

import re

## Python

from nose import tools
for t in dir(tools):
    if t.startswith('assert_'):
        vars()[t] = getattr(tools, t)

## Django

caps = re.compile('([A-Z])')

def pep8(name):
    return caps.sub(lambda m: '_' + m.groups()[0].lower(), name)


class Dummy(TestCase):
    def nop():
        pass
_t = Dummy('nop')

for at in [ at for at in dir(_t)
            if at.startswith('assert') and not '_' in at ]:
    pepd = pep8(at)
    vars()[pepd] = getattr(_t, at)

del Dummy
del _t
del pep8

## New

def assert_code(response, status_code, msg_prefix=''):
    """Asserts the response was returned with the given status code
    """

    if msg_prefix:
        msg_prefix = '%s: ' % msg_prefix

    assert response.status_code == status_code, \
        'Response code was %d (expected %d)' % \
            (response.status_code, status_code)

def assert_ok(response, msg_prefix=''):
    """Asserts the response was returned with status 200 (OK)
    """

    return assert_code(response, 200, msg_prefix=msg_prefix)

# EOF



Make the heading doc string a bit more descriptive
Make the heading doc string a bit more descriptive
