Ejemplo n.º 1
0
def test_badge_add_adds_uri_to_model(models):
    request = Mock(params={'add': 'test_uri'})

    views.badge_add(request)

    models.Blocklist.assert_called_once_with(uri='test_uri')
    request.db.add.assert_called_once_with(models.Blocklist.return_value)
Ejemplo n.º 2
0
    def test_add_flashes_error_if_uri_already_blocked(self, pyramid_request):
        pyramid_request.params = {'add': 'blocked1'}
        pyramid_request.session.flash = mock.Mock()

        views.badge_add(pyramid_request)

        assert pyramid_request.session.flash.call_count == 1
Ejemplo n.º 3
0
    def test_add_flashes_error_if_uri_already_blocked(self, req):
        req.params = {'add': 'blocked1'}
        req.session.flash = mock.Mock()

        views.badge_add(req)

        assert req.session.flash.call_count == 1
Ejemplo n.º 4
0
def test_badge_add_adds_uri_to_model(models):
    request = Mock(params={'add': 'test_uri'})

    views.badge_add(request)

    models.Blocklist.assert_called_once_with(uri='test_uri')
    request.db.add.assert_called_once_with(models.Blocklist.return_value)
Ejemplo n.º 5
0
def test_badge_add_flashes_error_if_uri_already_blocked(models):
    request = Mock(params={'add': 'test_uri'})
    models.Blocklist.side_effect = ValueError("test_error_message")

    views.badge_add(request)

    assert not request.db.add.called
    request.session.flash.assert_called_once_with(
        "test_error_message", "error")
Ejemplo n.º 6
0
def test_badge_add_flashes_error_if_uri_already_blocked(models):
    request = Mock(params={'add': 'test_uri'})
    models.Blocklist.side_effect = ValueError("test_error_message")

    views.badge_add(request)

    assert not request.db.add.called
    request.session.flash.assert_called_once_with("test_error_message",
                                                  "error")
Ejemplo n.º 7
0
    def test_add_redirects_to_index_if_uri_already_blocked(self, pyramid_request):
        pyramid_request.params = {'add': 'blocked1'}

        result = views.badge_add(pyramid_request)

        assert isinstance(result, httpexceptions.HTTPSeeOther)
        assert result.location == '/adm/badge'
Ejemplo n.º 8
0
    def test_add_redirects_to_index_if_uri_already_blocked(self, req):
        req.params = {'add': 'blocked1'}

        result = views.badge_add(req)

        assert isinstance(result, httpexceptions.HTTPSeeOther)
        assert result.location == '/adm/badge'
Ejemplo n.º 9
0
    def test_add_blocks_uri(self, pyramid_request):
        pyramid_request.params = {'add': 'test_uri'}

        views.badge_add(pyramid_request)

        assert models.Blocklist.is_blocked(pyramid_request.db, 'test_uri')
Ejemplo n.º 10
0
def test_badge_add_returns_index_if_uri_already_blocked(models, badge_index):
    request = Mock(params={'add': 'test_uri'})
    models.Blocklist.side_effect = ValueError("test_error_message")

    assert views.badge_add(request) == badge_index.return_value
Ejemplo n.º 11
0
def test_badge_add_returns_index(badge_index):
    request = Mock(params={'add': 'test_uri'})

    assert views.badge_add(request) == badge_index.return_value
Ejemplo n.º 12
0
    def test_add_blocks_uri(self, req):
        req.params = {'add': 'test_uri'}

        views.badge_add(req)

        assert models.Blocklist.is_blocked(req.db, 'test_uri')
Ejemplo n.º 13
0
def test_badge_add_returns_index_if_uri_already_blocked(models, badge_index):
    request = Mock(params={'add': 'test_uri'})
    models.Blocklist.side_effect = ValueError("test_error_message")

    assert views.badge_add(request) == badge_index.return_value
Ejemplo n.º 14
0
def test_badge_add_returns_index(badge_index):
    request = Mock(params={'add': 'test_uri'})

    assert views.badge_add(request) == badge_index.return_value