Esempio n. 1
0
def test_get_resource_project(rf, default, project0, tp0):
    """Tests that the correct resources are set for the given Project
    contexts.
    """
    store_name = 'store0.po'
    subdir_name = 'subdir0/'

    request = rf.get('/')
    request.user = default

    # Fake decorated function
    func = get_resource(lambda x, y, s, t: (x, y, s, t))

    # Project, no resource
    func(request, project0, '', '')
    assert isinstance(request.resource_obj, Project)

    # Project, cross-language file resource
    func(request, project0, '', store_name)
    assert isinstance(request.resource_obj, ProjectResource)

    # Two languages had this file, but it was marked as obsolete for the Arabic
    # language!
    # Should only contain a single file resource
    assert (
        len(request.resource_obj.resources)
        == len(
            Store.objects.filter(
                translation_project__project__code=project0.code,
                name="store0.po")))
    assert isinstance(request.resource_obj.resources[0], Store)

    # Project, cross-language directory resource
    func(request, project0, subdir_name, '')
    assert isinstance(request.resource_obj, ProjectResource)

    # Two languages have this dir, but it was marked as obsolete for the Arabic
    # language!
    # Should only contain a single dir resource
    assert (
        len(request.resource_obj.resources)
        == len(
            Directory.objects.filter(
                name=subdir_name.rstrip("/"),
                parent__translationproject__project=project0)))
    assert isinstance(request.resource_obj.resources[0], Directory)
Esempio n. 2
0
def test_get_resource_project(rf, default, project0, tp0):
    """Tests that the correct resources are set for the given Project
    contexts.
    """
    store_name = 'store0.po'
    subdir_name = 'subdir0/'

    request = rf.get('/')
    request.user = default

    # Fake decorated function
    func = get_resource(lambda x, y, s, t: (x, y, s, t))

    # Project, no resource
    func(request, project0, '', '')
    assert isinstance(request.resource_obj, Project)

    # Project, cross-language file resource
    func(request, project0, '', store_name)
    assert isinstance(request.resource_obj, ProjectResource)

    # Two languages had this file, but it was marked as obsolete for the Arabic
    # language!
    # Should only contain a single file resource
    assert (
        len(request.resource_obj.resources)
        == len(
            Store.objects.filter(
                translation_project__project__code=project0.code,
                name="store0.po")))
    assert isinstance(request.resource_obj.resources[0], Store)

    # Project, cross-language directory resource
    func(request, project0, subdir_name, '')
    assert isinstance(request.resource_obj, ProjectResource)

    # Two languages have this dir, but it was marked as obsolete for the Arabic
    # language!
    # Should only contain a single dir resource
    assert (
        len(request.resource_obj.resources)
        == len(
            Directory.objects.filter(
                name=subdir_name.rstrip("/"),
                parent__translationproject__project=project0)))
    assert isinstance(request.resource_obj.resources[0], Directory)
Esempio n. 3
0
def test_get_resource_project(rf, default, tutorial, afrikaans_tutorial,
                              arabic_tutorial_obsolete):
    """Tests that the correct resources are set for the given Project
    contexts.
    """
    store_name = 'tutorial.po'
    subdir_name = 'subdir/'

    subdir_name_fake = 'fake_subdir/'
    store_name_fake = 'fake_store.po'

    request = rf.get('/')
    request.user = default

    # Fake decorated function
    func = get_resource(lambda x, y, s, t: (x, y, s, t))

    # Project, no resource
    func(request, tutorial, '', '')
    assert isinstance(request.resource_obj, Project)

    # Project, cross-language file resource
    func(request, tutorial, '', store_name)
    assert isinstance(request.resource_obj, ProjectResource)

    # Two languages had this file, but it was marked as obsolete
    # for the Arabic language!
    # Should only contain a single file resource
    assert len(request.resource_obj.resources) == 1
    assert isinstance(request.resource_obj.resources[0], Store)

    # Project, cross-language directory resource
    func(request, tutorial, subdir_name, '')
    assert isinstance(request.resource_obj, ProjectResource)

    # Two languages have this dir, but it was marked as obsolete for
    # the Arabic language!
    # Should only contain a single dir resource
    assert len(request.resource_obj.resources) == 1
    assert isinstance(request.resource_obj.resources[0], Directory)
Esempio n. 4
0
def test_get_resource_project(rf, default, tutorial, afrikaans_tutorial,
                              arabic_tutorial_obsolete):
    """Tests that the correct resources are set for the given Project
    contexts.
    """
    store_name = 'tutorial.po'
    subdir_name = 'subdir/'

    subdir_name_fake = 'fake_subdir/'
    store_name_fake = 'fake_store.po'

    request = rf.get('/')
    request.user = default

    # Fake decorated function
    func = get_resource(lambda x, y, s, t: (x, y, s, t))

    # Project, no resource
    func(request, tutorial, '', '')
    assert isinstance(request.resource_obj, Project)

    # Project, cross-language file resource
    func(request, tutorial, '', store_name)
    assert isinstance(request.resource_obj, ProjectResource)

    # Two languages had this file, but it was marked as obsolete
    # for the Arabic language!
    # Should only contain a single file resource
    assert len(request.resource_obj.resources) == 1
    assert isinstance(request.resource_obj.resources[0], Store)

    # Project, cross-language directory resource
    func(request, tutorial, subdir_name, '')
    assert isinstance(request.resource_obj, ProjectResource)

    # Two languages have this dir, but it was marked as obsolete for
    # the Arabic language!
    # Should only contain a single dir resource
    assert len(request.resource_obj.resources) == 1
    assert isinstance(request.resource_obj.resources[0], Directory)
Esempio n. 5
0
def test_get_resource_tp(rf, default, tutorial, afrikaans_tutorial):
    """Tests that the correct resources are set for the given TP contexts."""
    store_name = 'tutorial.po'
    subdir_name = 'subdir/'

    subdir_name_fake = 'fake_subdir/'
    store_name_fake = 'fake_store.po'

    request = rf.get('/')
    request.user = default

    # Fake decorated function
    func = get_resource(lambda x, y, s, t: (x, y, s, t))

    # TP, no resource
    func(request, afrikaans_tutorial, '', '')
    assert isinstance(request.resource_obj, TranslationProject)

    # TP, file resource
    func(request, afrikaans_tutorial, '', store_name)
    assert isinstance(request.resource_obj, Store)

    # TP, directory resource
    func(request, afrikaans_tutorial, subdir_name, '')
    assert isinstance(request.resource_obj, Directory)

    # TP, missing file/dir resource, redirects to parent resource
    response = func(request, afrikaans_tutorial, '', store_name_fake)
    assert response.status_code == 302
    assert afrikaans_tutorial.pootle_path in response.get('location')

    response = func(request, afrikaans_tutorial, subdir_name, store_name_fake)
    assert response.status_code == 302
    assert (''.join([afrikaans_tutorial.pootle_path, subdir_name]) in
            response.get('location'))

    response = func(request, afrikaans_tutorial, subdir_name_fake, '')
    assert response.status_code == 302
    assert afrikaans_tutorial.pootle_path in response.get('location')
Esempio n. 6
0
def test_get_resource_tp(rf, default, tutorial, afrikaans_tutorial):
    """Tests that the correct resources are set for the given TP contexts."""
    store_name = 'tutorial.po'
    subdir_name = 'subdir/'

    subdir_name_fake = 'fake_subdir/'
    store_name_fake = 'fake_store.po'

    request = rf.get('/')
    request.user = default

    # Fake decorated function
    func = get_resource(lambda x, y, s, t: (x, y, s, t))

    # TP, no resource
    func(request, afrikaans_tutorial, '', '')
    assert isinstance(request.resource_obj, TranslationProject)

    # TP, file resource
    func(request, afrikaans_tutorial, '', store_name)
    assert isinstance(request.resource_obj, Store)

    # TP, directory resource
    func(request, afrikaans_tutorial, subdir_name, '')
    assert isinstance(request.resource_obj, Directory)

    # TP, missing file/dir resource, redirects to parent resource
    response = func(request, afrikaans_tutorial, '', store_name_fake)
    assert response.status_code == 302
    assert afrikaans_tutorial.pootle_path in response.get('location')

    response = func(request, afrikaans_tutorial, subdir_name, store_name_fake)
    assert response.status_code == 302
    assert (''.join([afrikaans_tutorial.pootle_path, subdir_name])
            in response.get('location'))

    response = func(request, afrikaans_tutorial, subdir_name_fake, '')
    assert response.status_code == 302
    assert afrikaans_tutorial.pootle_path in response.get('location')
Esempio n. 7
0
def test_get_resource_tp(rf, default, tp0):
    """Tests that the correct resources are set for the given TP contexts."""
    store_name = 'store0.po'
    subdir_name = 'subdir0/'

    request = rf.get('/')
    request.user = default

    # Fake decorated function
    func = get_resource(lambda x, y, s, t: (x, y, s, t))

    # TP, no resource
    func(request, tp0, '', '')
    assert isinstance(request.resource_obj, TranslationProject)

    # TP, file resource
    func(request, tp0, '', store_name)
    assert isinstance(request.resource_obj, Store)

    # TP, directory resource
    func(request, tp0, subdir_name, '')
    assert isinstance(request.resource_obj, Directory)