Exemple #1
0
def test_add_translation_to_db():
    """
        This should add a new translation to the database session, which is added only if it does not exit in a db.
        After successfully creating a new translation it should redirect.
    """
    with mock.patch('annotran.languages.models.Language') as language:
        propLang = PropertyMock(return_value=2897)
        type(language).id = propLang
        language.get_by_name = MagicMock(return_value=language)

        with mock.patch('annotran.pages.models.Page') as page:
            propPage = PropertyMock(return_value=2897)
            type(page).id = propPage
            page.get_by_uri = MagicMock(return_value=page)

            with mock.patch('h.groups.models.Group') as group:
                propGroup = PropertyMock(return_value=2897)
                type(group).id = propGroup
                group.get_by_pubid = MagicMock(return_value=group)

                request = _mock_request(
                    matchdict={
                        'public_group_id': '12345',
                        'language': 'test',
                        'page_url': 'http://www.annotran_test.com/'
                    })
                result = views.add_translation(request)
                request.db.add.assert_called_once()
                assert isinstance(result, httpexceptions.HTTPRedirection)
Exemple #2
0
def test_create_redirects_to_translation_read_page(Page, Language, Group,
                                                   Translation):
    """
        After successfully fetching mock objects Page, Language, and Translation it
         should not add that translation into db but it should redirect.
    """
    language = mock.Mock()
    Language.return_value = language

    page = mock.Mock()
    Page.return_value = page

    group = mock.Mock()
    Group.return_value = group

    translation = mock.Mock()
    Translation.return_value = translation

    request = _mock_request(
        matchdict={
            'public_group_id': '12345',
            'language': 'test',
            'page_url': 'http://www.annotran_test.com/'
        })
    result = views.add_translation(request)
    assert not request.db.add.called
    assert isinstance(result, httpexceptions.HTTPRedirection)
Exemple #3
0
def test_add_translation_to_db():
    """
        This should add a new translation to the database session, which is added only if it does not exit in a db.
        After successfully creating a new translation it should redirect.
    """
    with mock.patch('annotran.languages.models.Language') as language:
        propLang = PropertyMock(return_value=2897)
        type(language).id = propLang
        language.get_by_name = MagicMock(return_value=language)

        with mock.patch('annotran.pages.models.Page') as page:
            propPage = PropertyMock(return_value=2897)
            type(page).id = propPage
            page.get_by_uri = MagicMock(return_value=page)

            with mock.patch('h.groups.models.Group') as group:
                propGroup = PropertyMock(return_value=2897)
                type(group).id = propGroup
                group.get_by_pubid = MagicMock(return_value=group)

                request = _mock_request(matchdict={'public_group_id': '12345',
                                                   'language': 'test',
                                                   'page_url': 'http://www.annotran_test.com/'})
                result = views.add_translation(request)
                request.db.add.assert_called_once()
                assert isinstance(result, httpexceptions.HTTPRedirection)
Exemple #4
0
def test_add_translation_to_db_when_page_lang_group_none():
    """
        This should not add a new translation to the database session.
        If page, group or language is None, then it should return immediatelly.
    """
    request = _mock_request(matchdict={'public_group_id': '12345',
                                       'language': 'test',
                                       'page_url': 'http://www.annotran_test.com/'})
    result = views.add_translation(request)
    assert not request.db.add.called
    assert isinstance(result, types.DictType)
Exemple #5
0
def test_add_translation_to_db_when_page_lang_group_none():
    """
        This should not add a new translation to the database session.
        If page, group or language is None, then it should return immediatelly.
    """
    request = _mock_request(
        matchdict={
            'public_group_id': '12345',
            'language': 'test',
            'page_url': 'http://www.annotran_test.com/'
        })
    result = views.add_translation(request)
    assert not request.db.add.called
    assert isinstance(result, types.DictType)
Exemple #6
0
def test_create_redirects_to_translation_read_page(Page, Language, Group, Translation):
    """
        After successfully fetching mock objects Page, Language, and Translation it
         should not add that translation into db but it should redirect.
    """
    language = mock.Mock()
    Language.return_value = language

    page = mock.Mock()
    Page.return_value = page

    group = mock.Mock()
    Group.return_value = group

    translation = mock.Mock()
    Translation.return_value = translation

    request = _mock_request(matchdict={'public_group_id': '12345',
                                       'language': 'test',
                                       'page_url': 'http://www.annotran_test.com/'})
    result = views.add_translation(request)
    assert not request.db.add.called
    assert isinstance(result, httpexceptions.HTTPRedirection)