Changeset View
Changeset View
Standalone View
Standalone View
swh/web/tests/browse/views/test_person.py
# Copyright (C) 2017-2018 The Software Heritage developers | # Copyright (C) 2017-2018 The Software Heritage developers | ||||
# See the AUTHORS file at the top-level directory of this distribution | # See the AUTHORS file at the top-level directory of this distribution | ||||
# License: GNU Affero General Public License version 3, or any later version | # License: GNU Affero General Public License version 3, or any later version | ||||
# See top-level LICENSE file for more information | # See top-level LICENSE file for more information | ||||
from unittest.mock import patch | from unittest.mock import patch | ||||
from nose.tools import istest | |||||
from swh.web.common.exc import NotFoundExc | from swh.web.common.exc import NotFoundExc | ||||
from swh.web.common.utils import reverse | from swh.web.common.utils import reverse | ||||
from swh.web.tests.testcase import SWHWebTestCase | from swh.web.tests.testcase import SWHWebTestCase | ||||
class SwhBrowsePersonTest(SWHWebTestCase): | class SwhBrowsePersonTest(SWHWebTestCase): | ||||
@patch('swh.web.browse.views.person.service') | @patch('swh.web.browse.views.person.service') | ||||
@istest | def test_person_browse(self, mock_service): | ||||
def person_browse(self, mock_service): | |||||
test_person_data = \ | test_person_data = \ | ||||
{ | { | ||||
"email": "j.adams440@gmail.com", | "email": "j.adams440@gmail.com", | ||||
"fullname": "oysterCrusher <j.adams440@gmail.com>", | "fullname": "oysterCrusher <j.adams440@gmail.com>", | ||||
"id": 457587, | "id": 457587, | ||||
"name": "oysterCrusher" | "name": "oysterCrusher" | ||||
} | } | ||||
Show All 11 Lines | def test_person_browse(self, mock_service): | ||||
(test_person_data['email'], | (test_person_data['email'], | ||||
test_person_data['email'])) | test_person_data['email'])) | ||||
self.assertContains(resp, '<pre>%s <<a href="mailto:%s">%s</a>></pre>' % # noqa | self.assertContains(resp, '<pre>%s <<a href="mailto:%s">%s</a>></pre>' % # noqa | ||||
(test_person_data['name'], | (test_person_data['name'], | ||||
test_person_data['email'], | test_person_data['email'], | ||||
test_person_data['email'])) | test_person_data['email'])) | ||||
@patch('swh.web.browse.views.person.service') | @patch('swh.web.browse.views.person.service') | ||||
@istest | def test_person_request_error(self, mock_service): | ||||
def person_request_error(self, mock_service): | |||||
mock_service.lookup_person.side_effect = \ | mock_service.lookup_person.side_effect = \ | ||||
NotFoundExc('Person not found') | NotFoundExc('Person not found') | ||||
url = reverse('browse-person', kwargs={'person_id': 457587}) | url = reverse('browse-person', kwargs={'person_id': 457587}) | ||||
resp = self.client.get(url) | resp = self.client.get(url) | ||||
self.assertEquals(resp.status_code, 404) | self.assertEquals(resp.status_code, 404) | ||||
self.assertTemplateUsed('error.html') | self.assertTemplateUsed('error.html') | ||||
self.assertContains(resp, 'Person not found', status_code=404) | self.assertContains(resp, 'Person not found', status_code=404) |