-
Notifications
You must be signed in to change notification settings - Fork 15
/
test_switching_logframes.py
44 lines (29 loc) · 1.31 KB
/
test_switching_logframes.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
from django.core.urlresolvers import reverse
from django.http.response import Http404
from django.test.client import RequestFactory
import mock
import pytest
from ..views import SwitchLogframes
@mock.patch('dashboard.views.get_object_or_404', new=mock.Mock(return_value=mock.Mock(slug='test')))
def test_switch_logframes_sets_user_last_viewed_logframe_to_new_logframe():
data = {'logframe': '2'}
request = RequestFactory().post('/', data)
request.user = mock.Mock()
SwitchLogframes.as_view()(request)
assert 'test' == request.user.preferences.last_viewed_logframe.slug
@mock.patch('dashboard.views.get_object_or_404', new=mock.Mock(return_value=mock.Mock(slug='test')))
def test_switch_logframes_containts_instruction_to_redirect_to_dashboard():
data = {'logframe': '2'}
request = RequestFactory().post('/', data)
request.user = mock.Mock()
request.session = {}
response = SwitchLogframes.as_view()(request)
assert reverse('logframe-dashboard', kwargs={'slug': 'test'}) == response['Location']
@pytest.mark.django_db
def test_switch_logframe_with_invalid_id_raises_404():
data = {'logframe': '-1'}
request = RequestFactory().post('/', data)
request.user = mock.Mock()
request.session = {}
with pytest.raises(Http404):
SwitchLogframes.as_view()(request)