Exemple #1
0
def test_job_template_old_way(get, admin_user, mocker):
    test_org = Organization.objects.create(name='test_org')
    test_jt = JobTemplate.objects.create(name='test_jt ♥', organization=test_org)
    url = reverse('api:job_template_detail', kwargs={'pk': test_jt.pk})

    response = get(url, user=admin_user, expect=200)
    new_url = response.data['related']['named_url']
    old_url = '/'.join([url.rsplit('/', 2)[0], test_jt.name, ''])

    assert URLModificationMiddleware._convert_named_url(new_url) == url
    assert URLModificationMiddleware._convert_named_url(old_url) == url
Exemple #2
0
def setup_module(module):
    # In real-world scenario, named url graph structure is populated by __init__
    # of URLModificationMiddleware. The way Django bootstraps ensures the initialization
    # will happen *once and only once*, while the number of initialization is uncontrollable
    # in unit test environment. So it is wrapped by try-except block to mute any
    # unwanted exceptions.
    try:
        URLModificationMiddleware()
    except ImproperlyConfigured:
        pass