diff --git a/swh/web/tests/admin/test_origin_save.py b/swh/web/tests/admin/test_origin_save.py --- a/swh/web/tests/admin/test_origin_save.py +++ b/swh/web/tests/admin/test_origin_save.py @@ -7,7 +7,6 @@ from django.contrib.auth import get_user_model -from nose.tools import istest, nottest from unittest.mock import patch from swh.web.common.models import ( @@ -32,22 +31,20 @@ class OriginSaveAdminTestCase(SWHWebTestCase): @classmethod - def setUpTestData(cls): - User = get_user_model() + def setUpTestData(cls): # noqa: N802 + User = get_user_model() # noqa: N806 user = User.objects.create_user(_user_name, _user_mail, _user_password) user.is_staff = True user.save() SaveAuthorizedOrigin.objects.create(url=_authorized_origin_url) SaveUnauthorizedOrigin.objects.create(url=_unauthorized_origin_url) - @nottest def check_not_login(self, url): login_url = reverse('login', query_params={'next': url}) response = self.client.post(url) self.assertEquals(response.status_code, 302) self.assertEquals(unquote(response.url), login_url) - @istest def test_add_authorized_origin_url(self): authorized_url = 'https://scm.adullact.net/anonscm/' self.assertEquals(can_save_origin(authorized_url), @@ -67,7 +64,6 @@ self.assertEquals(can_save_origin(authorized_url), SAVE_REQUEST_ACCEPTED) - @istest def test_remove_authorized_origin_url(self): self.assertEquals(can_save_origin(_authorized_origin_url), SAVE_REQUEST_ACCEPTED) @@ -86,7 +82,6 @@ self.assertEquals(can_save_origin(_authorized_origin_url), SAVE_REQUEST_PENDING) - @istest def test_add_unauthorized_origin_url(self): unauthorized_url = 'https://www.yahoo./' self.assertEquals(can_save_origin(unauthorized_url), @@ -106,7 +101,6 @@ self.assertEquals(can_save_origin(unauthorized_url), SAVE_REQUEST_REJECTED) - @istest def test_remove_unauthorized_origin_url(self): self.assertEquals(can_save_origin(_unauthorized_origin_url), SAVE_REQUEST_REJECTED) @@ -125,7 +119,6 @@ self.assertEquals(can_save_origin(_unauthorized_origin_url), SAVE_REQUEST_PENDING) - @istest @patch('swh.web.common.origin_save.scheduler') def test_accept_pending_save_request(self, mock_scheduler): origin_type = 'git' @@ -175,7 +168,6 @@ self.assertEquals(response.data[0]['save_task_status'], SAVE_TASK_NOT_YET_SCHEDULED) - @istest def test_reject_pending_save_request(self): origin_type = 'git' origin_url = 'https://wikipedia.com' diff --git a/swh/web/tests/api/test_api_lookup.py b/swh/web/tests/api/test_api_lookup.py --- a/swh/web/tests/api/test_api_lookup.py +++ b/swh/web/tests/api/test_api_lookup.py @@ -3,9 +3,6 @@ # License: GNU Affero General Public License version 3, or any later version # See top-level LICENSE file for more information - -from nose.tools import istest - from swh.web.common.exc import NotFoundExc from swh.web.api.views import utils from swh.web.tests.testcase import SWHWebTestCase @@ -13,8 +10,7 @@ class ApiLookupTestCase(SWHWebTestCase): - @istest - def genericapi_lookup_nothing_is_found(self): + def test_genericapi_lookup_nothing_is_found(self): # given def test_generic_lookup_fn(sha1, another_unused_arg): assert another_unused_arg == 'unused_arg' @@ -30,8 +26,7 @@ self.assertIn('This will be raised because None is returned.', cm.exception.args[0]) - @istest - def generic_api_map_are_enriched_and_transformed_to_list(self): + def test_generic_api_map_are_enriched_and_transformed_to_list(self): # given def test_generic_lookup_fn_1(criteria0, param0, param1): assert criteria0 == 'something' @@ -47,8 +42,7 @@ self.assertEqual(actual_result, [4, 6, 8]) - @istest - def generic_api_list_are_enriched_too(self): + def test_generic_api_list_are_enriched_too(self): # given def test_generic_lookup_fn_2(crit): assert crit == 'something' @@ -63,8 +57,7 @@ self.assertEqual(actual_result, ['=a=', '=b=', '=c=']) - @istest - def generic_api_generator_are_enriched_and_returned_as_list(self): + def test_generic_api_generator_are_enriched_and_returned_as_list(self): # given def test_generic_lookup_fn_3(crit): assert crit == 'crit' @@ -78,8 +71,7 @@ self.assertEqual(actual_result, [3, 4, 5]) - @istest - def generic_api_simple_data_are_enriched_and_returned_too(self): + def test_generic_api_simple_data_are_enriched_and_returned_too(self): # given def test_generic_lookup_fn_4(crit): assert crit == '123' @@ -97,8 +89,7 @@ self.assertEqual(actual_result, {'a': 100}) - @istest - def api_lookup_not_found(self): + def test_api_lookup_not_found(self): # when with self.assertRaises(NotFoundExc) as e: utils.api_lookup( @@ -108,8 +99,7 @@ self.assertEqual(e.exception.args[0], 'this is the error message raised as it is None') - @istest - def api_lookup_with_result(self): + def test_api_lookup_with_result(self): # when actual_result = utils.api_lookup( lambda x: x + '!', 'something', @@ -117,8 +107,7 @@ self.assertEqual(actual_result, 'something!') - @istest - def api_lookup_with_result_as_map(self): + def test_api_lookup_with_result_as_map(self): # when actual_result = utils.api_lookup( lambda x: map(lambda y: y+1, x), [1, 2, 3], diff --git a/swh/web/tests/api/test_apidoc.py b/swh/web/tests/api/test_apidoc.py --- a/swh/web/tests/api/test_apidoc.py +++ b/swh/web/tests/api/test_apidoc.py @@ -3,7 +3,6 @@ # License: GNU Affero General Public License version 3, or any later version # See top-level LICENSE file for more information -from nose.tools import istest, nottest from rest_framework.test import APITestCase from rest_framework.response import Response @@ -63,8 +62,7 @@ class APIDocTestCase(SWHWebTestCase, APITestCase): - @istest - def apidoc_nodoc_failure(self): + def test_apidoc_nodoc_failure(self): with self.assertRaises(Exception): @api_doc('/my/nodoc/url/') def apidoc_nodoc_tester(request, arga=0, argb=0): @@ -74,15 +72,13 @@ @api_route(r'/some/(?P[0-9]+)/(?P[0-9]+)/', 'some-doc-route') @api_doc('/some/doc/route/') - @nottest - def apidoc_route_tester(request, myarg, myotherarg, akw=0): + def apidoc_route(request, myarg, myotherarg, akw=0): """ Sample doc """ return {'result': int(myarg) + int(myotherarg) + akw} - @istest - def apidoc_route_doc(self): + def test_apidoc_route_doc(self): # when rv = self.client.get('/api/1/some/doc/route/') @@ -90,8 +86,7 @@ self.assertEqual(rv.status_code, 200) self.assertTemplateUsed('api/apidoc.html') - @istest - def apidoc_route_fn(self): + def test_apidoc_route_fn(self): # when rv = self.client.get('/api/1/some/1/1/') @@ -103,15 +98,13 @@ @api_route(r'/some/full/(?P[0-9]+)/(?P[0-9]+)/', 'some-complete-doc-route') @api_doc('/some/complete/doc/route/') - @nottest - def apidoc_full_stack_tester(request, myarg, myotherarg, akw=0): + def apidoc_full_stack(request, myarg, myotherarg, akw=0): """ Sample doc """ return {'result': int(myarg) + int(myotherarg) + akw} - @istest - def apidoc_full_stack_doc(self): + def test_apidoc_full_stack_doc(self): # when rv = self.client.get('/api/1/some/complete/doc/route/') @@ -119,15 +112,13 @@ self.assertEqual(rv.status_code, 200) self.assertTemplateUsed('api/apidoc.html') - @istest - def apidoc_full_stack_fn(self): + def test_apidoc_full_stack_fn(self): # when rv = self.client.get('/api/1/some/full/1/1/') # then self.assertEqual(rv.status_code, 200) - @istest def test_api_doc_parse_httpdomain(self): doc_data = { 'description': '', diff --git a/swh/web/tests/api/test_apiresponse.py b/swh/web/tests/api/test_apiresponse.py --- a/swh/web/tests/api/test_apiresponse.py +++ b/swh/web/tests/api/test_apiresponse.py @@ -7,7 +7,6 @@ from rest_framework.test import APIRequestFactory -from nose.tools import istest from unittest.mock import patch from swh.web.api.apiresponse import ( @@ -20,8 +19,7 @@ class SWHComputeLinkHeaderTest(SWHWebTestCase): - @istest - def compute_link_header(self): + def test_compute_link_header(self): rv = { 'headers': {'link-next': 'foo', 'link-prev': 'bar'}, 'results': [1, 2, 3] @@ -36,8 +34,7 @@ 'Link': '; rel="next",; rel="previous"', }) - @istest - def compute_link_header_nothing_changed(self): + def test_compute_link_header_nothing_changed(self): rv = {} options = {} @@ -47,8 +44,7 @@ self.assertEquals(headers, {}) - @istest - def compute_link_header_nothing_changed_2(self): + def test_compute_link_header_nothing_changed_2(self): rv = {'headers': {}} options = {} @@ -60,28 +56,24 @@ class SWHTransformProcessorTest(SWHWebTestCase): - @istest - def transform_only_return_results_1(self): + def test_transform_only_return_results_1(self): rv = {'results': {'some-key': 'some-value'}} self.assertEquals(transform(rv), {'some-key': 'some-value'}) - @istest - def transform_only_return_results_2(self): + def test_transform_only_return_results_2(self): rv = {'headers': {'something': 'do changes'}, 'results': {'some-key': 'some-value'}} self.assertEquals(transform(rv), {'some-key': 'some-value'}) - @istest - def transform_do_remove_headers(self): + def test_transform_do_remove_headers(self): rv = {'headers': {'something': 'do changes'}, 'some-key': 'some-value'} self.assertEquals(transform(rv), {'some-key': 'some-value'}) - @istest - def transform_do_nothing(self): + def test_transform_do_nothing(self): rv = {'some-key': 'some-value'} self.assertEquals(transform(rv), {'some-key': 'some-value'}) @@ -92,9 +84,8 @@ @patch('swh.web.api.apiresponse.json') @patch('swh.web.api.apiresponse.filter_by_fields') @patch('swh.web.api.apiresponse.shorten_path') - @istest - def swh_multi_response_mimetype(self, mock_shorten_path, - mock_filter, mock_json): + def test_swh_multi_response_mimetype(self, mock_shorten_path, + mock_filter, mock_json): # given data = { 'data': [12, 34], @@ -144,8 +135,7 @@ if mime_type == 'text/html': self.assertEqual(rv.template_name, 'api/apidoc.html') - @istest - def swh_filter_renderer_do_nothing(self): + def test_swh_filter_renderer_do_nothing(self): # given input_data = {'a': 'some-data'} @@ -159,8 +149,7 @@ self.assertEquals(actual_data, input_data) @patch('swh.web.api.apiresponse.utils.filter_field_keys') - @istest - def swh_filter_renderer_do_filter(self, mock_ffk): + def test_swh_filter_renderer_do_filter(self, mock_ffk): # given mock_ffk.return_value = {'a': 'some-data'} diff --git a/swh/web/tests/api/test_utils.py b/swh/web/tests/api/test_utils.py --- a/swh/web/tests/api/test_utils.py +++ b/swh/web/tests/api/test_utils.py @@ -4,7 +4,6 @@ # See top-level LICENSE file for more information from unittest.mock import patch, call -from nose.tools import istest, nottest from swh.web.api import utils from swh.web.tests.testcase import SWHWebTestCase @@ -37,8 +36,7 @@ 'd78a4a71ba1ad064770f0c9') } - @istest - def filter_field_keys_dict_unknown_keys(self): + def test_filter_field_keys_dict_unknown_keys(self): # when actual_res = utils.filter_field_keys( {'directory': 1, 'file': 2, 'link': 3}, @@ -47,8 +45,7 @@ # then self.assertEqual(actual_res, {}) - @istest - def filter_field_keys_dict(self): + def test_filter_field_keys_dict(self): # when actual_res = utils.filter_field_keys( {'directory': 1, 'file': 2, 'link': 3}, @@ -57,8 +54,7 @@ # then self.assertEqual(actual_res, {'directory': 1, 'link': 3}) - @istest - def filter_field_keys_list_unknown_keys(self): + def test_filter_field_keys_list_unknown_keys(self): # when actual_res = utils.filter_field_keys( [{'directory': 1, 'file': 2, 'link': 3}, @@ -68,8 +64,7 @@ # then self.assertEqual(actual_res, [{}, {}]) - @istest - def filter_field_keys_map(self): + def test_filter_field_keys_map(self): # when actual_res = utils.filter_field_keys( map(lambda x: {'i': x['i']+1, 'j': x['j']}, @@ -81,8 +76,7 @@ # then self.assertEqual(list(actual_res), [{'i': 2}, {'i': 3}, {'i': 4}]) - @istest - def filter_field_keys_list(self): + def test_filter_field_keys_list(self): # when actual_res = utils.filter_field_keys( [{'directory': 1, 'file': 2, 'link': 3}, @@ -92,8 +86,7 @@ # then self.assertEqual(actual_res, [{'directory': 1}, {'dir': 1}]) - @istest - def filter_field_keys_other(self): + def test_filter_field_keys_other(self): # given input_set = {1, 2} @@ -103,14 +96,12 @@ # then self.assertEqual(actual_res, input_set) - @istest - def person_to_string(self): + def test_person_to_string(self): self.assertEqual(utils.person_to_string(dict(name='raboof', email='foo@bar')), 'raboof ') - @istest - def enrich_release_0(self): + def test_enrich_release_0(self): # when actual_release = utils.enrich_release({}) @@ -118,8 +109,7 @@ self.assertEqual(actual_release, {}) @patch('swh.web.api.utils.reverse') - @istest - def enrich_release_1(self, mock_django_reverse): + def test_enrich_release_1(self, mock_django_reverse): # given def reverse_test_context(view_name, kwargs): @@ -165,8 +155,7 @@ ]) @patch('swh.web.api.utils.reverse') - @istest - def enrich_release_2(self, mock_django_reverse): + def test_enrich_release_2(self, mock_django_reverse): # given mock_django_reverse.return_value = '/api/1/dir/23/' @@ -185,8 +174,7 @@ kwargs={'sha1_git': '23'}) @patch('swh.web.api.utils.reverse') - @istest - def enrich_release_3(self, mock_django_reverse): + def test_enrich_release_3(self, mock_django_reverse): # given mock_django_reverse.return_value = '/api/1/rev/3/' @@ -205,8 +193,7 @@ kwargs={'sha1_git': '3'}) @patch('swh.web.api.utils.reverse') - @istest - def enrich_release_4(self, mock_django_reverse): + def test_enrich_release_4(self, mock_django_reverse): # given mock_django_reverse.return_value = '/api/1/rev/4/' @@ -225,8 +212,7 @@ kwargs={'sha1_git': '4'}) @patch('swh.web.api.utils.reverse') - @istest - def enrich_directory_no_type(self, mock_django_reverse): + def test_enrich_directory_no_type(self, mock_django_reverse): # when/then self.assertEqual(utils.enrich_directory({'id': 'dir-id'}), {'id': 'dir-id'}) @@ -253,8 +239,9 @@ 'content', kwargs={'q': 'sha1_git:123'}) @patch('swh.web.api.utils.reverse') - @istest - def enrich_directory_with_context_and_type_file(self, mock_django_reverse): + def test_enrich_directory_with_context_and_type_file( + self, mock_django_reverse, + ): # given mock_django_reverse.return_value = '/api/content/sha1_git:123/' @@ -281,8 +268,9 @@ 'content', kwargs={'q': 'sha1_git:789'}) @patch('swh.web.api.utils.reverse') - @istest - def enrich_directory_with_context_and_type_dir(self, mock_django_reverse): + def test_enrich_directory_with_context_and_type_dir( + self, mock_django_reverse, + ): # given mock_django_reverse.return_value = '/api/directory/456/' @@ -310,15 +298,13 @@ mock_django_reverse.assert_called_once_with('directory', kwargs={'sha1_git': '456'}) - @istest - def enrich_content_without_hashes(self): + def test_enrich_content_without_hashes(self): # when/then self.assertEqual(utils.enrich_content({'id': '123'}), {'id': '123'}) @patch('swh.web.api.utils.reverse') - @istest - def enrich_content_with_hashes(self, mock_django_reverse): + def test_enrich_content_with_hashes(self, mock_django_reverse): for algo, hash in self.sample_content_hashes.items(): @@ -362,9 +348,8 @@ mock_django_reverse.reset() @patch('swh.web.api.utils.reverse') - @istest - def enrich_content_with_hashes_and_top_level_url(self, - mock_django_reverse): + def test_enrich_content_with_hashes_and_top_level_url(self, + mock_django_reverse): for algo, hash in self.sample_content_hashes.items(): @@ -411,15 +396,13 @@ mock_django_reverse.reset() - @istest - def enrich_entity_identity(self): + def test_enrich_entity_identity(self): # when/then self.assertEqual(utils.enrich_content({'id': '123'}), {'id': '123'}) @patch('swh.web.api.utils.reverse') - @istest - def enrich_entity_with_sha1(self, mock_django_reverse): + def test_enrich_entity_with_sha1(self, mock_django_reverse): # given def reverse_test(view_name, kwargs): return '/api/entity/' + kwargs['uuid'] + '/' @@ -446,7 +429,6 @@ [call('entity', kwargs={'uuid': 'uuid-1'}), call('entity', kwargs={'uuid': 'uuid-parent'})]) - @nottest def _reverse_context_test(self, view_name, kwargs): if view_name == 'revision': return '/api/revision/%s/' % kwargs['sha1_git'] @@ -459,8 +441,9 @@ return '/api/revision/%s/log/' % kwargs['sha1_git'] @patch('swh.web.api.utils.reverse') - @istest - def enrich_revision_without_children_or_parent(self, mock_django_reverse): + def test_enrich_revision_without_children_or_parent( + self, mock_django_reverse, + ): # given def reverse_test(view_name, kwargs): if view_name == 'revision': @@ -505,9 +488,9 @@ call('directory', kwargs={'sha1_git': '123'})]) @patch('swh.web.api.utils.reverse') - @istest - def enrich_revision_with_children_and_parent_no_dir(self, - mock_django_reverse): + def test_enrich_revision_with_children_and_parent_no_dir( + self, mock_django_reverse, + ): # given mock_django_reverse.side_effect = self._reverse_context_test @@ -542,8 +525,7 @@ call('revision', kwargs={'sha1_git': '456'})]) @patch('swh.web.api.utils.reverse') - @istest - def enrich_revision_no_context(self, mock_django_reverse): + def test_enrich_revision_no_context(self, mock_django_reverse): # given mock_django_reverse.side_effect = self._reverse_context_test @@ -573,8 +555,9 @@ call('revision', kwargs={'sha1_git': '456'})]) @patch('swh.web.api.utils.reverse') - @istest - def enrich_revision_context_empty_prev_list(self, mock_django_reverse): + def test_enrich_revision_context_empty_prev_list( + self, mock_django_reverse, + ): # given mock_django_reverse.side_effect = self._reverse_context_test @@ -609,8 +592,7 @@ call('revision', kwargs={'sha1_git': '456'})]) @patch('swh.web.api.utils.reverse') - @istest - def enrich_revision_context_some_prev_list(self, mock_django_reverse): + def test_enrich_revision_context_some_prev_list(self, mock_django_reverse): # given mock_django_reverse.side_effect = self._reverse_context_test @@ -644,7 +626,6 @@ call('revision', kwargs={'sha1_git': '123'}), call('revision', kwargs={'sha1_git': '456'})]) - @nottest def _reverse_rev_message_test(self, view_name, kwargs): if view_name == 'revision': return '/api/revision/%s/' % kwargs['sha1_git'] @@ -659,8 +640,7 @@ return '/api/revision/%s/prev/%s/' % (kwargs['sha1_git'], kwargs['context']) # noqa @patch('swh.web.api.utils.reverse') - @istest - def enrich_revision_with_no_message(self, mock_django_reverse): + def test_enrich_revision_with_no_message(self, mock_django_reverse): # given mock_django_reverse.side_effect = self._reverse_rev_message_test @@ -699,8 +679,7 @@ ) @patch('swh.web.api.utils.reverse') - @istest - def enrich_revision_with_invalid_message(self, mock_django_reverse): + def test_enrich_revision_with_invalid_message(self, mock_django_reverse): # given mock_django_reverse.side_effect = self._reverse_rev_message_test diff --git a/swh/web/tests/api/views/test_content.py b/swh/web/tests/api/views/test_content.py --- a/swh/web/tests/api/views/test_content.py +++ b/swh/web/tests/api/views/test_content.py @@ -3,7 +3,6 @@ # License: GNU Affero General Public License version 3, or any later version # See top-level LICENSE file for more information -from nose.tools import istest from rest_framework.test import APITestCase from unittest.mock import patch, MagicMock @@ -12,8 +11,7 @@ class ContentApiTestCase(SWHWebTestCase, APITestCase): @patch('swh.web.api.views.content.service') - @istest - def api_content_filetype(self, mock_service): + def test_api_content_filetype(self, mock_service): stub_filetype = { 'accepted_media_type': 'application/xml', 'encoding': 'ascii', @@ -41,8 +39,7 @@ 'sha1_git:b04caf10e9535160d90e874b45aa426de762f19f') @patch('swh.web.api.views.content.service') - @istest - def api_content_filetype_sha_not_found(self, mock_service): + def test_api_content_filetype_sha_not_found(self, mock_service): # given mock_service.lookup_content_filetype.return_value = None @@ -64,8 +61,7 @@ 'sha1:40e71b8614fcd89ccd17ca2b1d9e66c5b00a6d03') @patch('swh.web.api.views.content.service') - @istest - def api_content_language(self, mock_service): + def test_api_content_language(self, mock_service): stub_language = { 'lang': 'lisp', 'id': '34571b8614fcd89ccd17ca2b1d9e66c5b00a6d03', @@ -91,8 +87,7 @@ 'sha1_git:b04caf10e9535160d90e874b45aa426de762f19f') @patch('swh.web.api.views.content.service') - @istest - def api_content_language_sha_not_found(self, mock_service): + def test_api_content_language_sha_not_found(self, mock_service): # given mock_service.lookup_content_language.return_value = None @@ -114,8 +109,7 @@ 'sha1:40e71b8614fcd89ccd17ca2b1d9e66c5b00a6d03') @patch('swh.web.api.views.content.service') - @istest - def api_content_symbol(self, mock_service): + def test_api_content_symbol(self, mock_service): stub_ctag = [{ 'sha1': '34571b8614fcd89ccd17ca2b1d9e66c5b00a6d03', 'name': 'foobar', @@ -152,8 +146,7 @@ 'foo', 'sha1', 10) @patch('swh.web.api.views.content.service') - @istest - def api_content_symbol_2(self, mock_service): + def test_api_content_symbol_2(self, mock_service): stub_ctag = [{ 'sha1': '12371b8614fcd89ccd17ca2b1d9e66c5b00a6456', 'name': 'foobar', @@ -183,8 +176,7 @@ 'foo', 'prev-sha1', 2) @patch('swh.web.api.views.content.service') - # @istest - def api_content_symbol_3(self, mock_service): + def test_api_content_symbol_3(self, mock_service): stub_ctag = [{ 'sha1': '67891b8614fcd89ccd17ca2b1d9e66c5b00a6d03', 'name': 'foo', @@ -220,8 +212,7 @@ mock_service.lookup_expression.assert_called_once_with('foo', None, 10) @patch('swh.web.api.views.content.service') - @istest - def api_content_symbol_not_found(self, mock_service): + def test_api_content_symbol_not_found(self, mock_service): # given mock_service.lookup_expression.return_value = [] @@ -241,8 +232,7 @@ 'bar', 'hash', 10) @patch('swh.web.api.views.content.service') - @istest - def api_content_ctags(self, mock_service): + def test_api_content_ctags(self, mock_service): stub_ctags = { 'id': '34571b8614fcd89ccd17ca2b1d9e66c5b00a6d03', 'ctags': [] @@ -268,8 +258,7 @@ 'sha1_git:b04caf10e9535160d90e874b45aa426de762f19f') @patch('swh.web.api.views.content.service') - @istest - def api_content_license(self, mock_service): + def test_api_content_license(self, mock_service): stub_license = { 'licenses': ['No_license_found', 'Apache-2.0'], 'id': '34571b8614fcd89ccd17ca2b1d9e66c5b00a6d03', @@ -297,8 +286,7 @@ 'sha1_git:b04caf10e9535160d90e874b45aa426de762f19f') @patch('swh.web.api.views.content.service') - @istest - def api_content_license_sha_not_found(self, mock_service): + def test_api_content_license_sha_not_found(self, mock_service): # given mock_service.lookup_content_license.return_value = None @@ -320,8 +308,7 @@ 'sha1:40e71b8614fcd89ccd17ca2b1d9e66c5b00a6d03') @patch('swh.web.api.views.content.service') - @istest - def api_content_provenance(self, mock_service): + def test_api_content_provenance(self, mock_service): stub_provenances = [{ 'origin': 1, 'visit': 2, @@ -358,8 +345,7 @@ 'sha1_git:34571b8614fcd89ccd17ca2b1d9e66c5b00a6d03') @patch('swh.web.api.views.content.service') - @istest - def api_content_provenance_sha_not_found(self, mock_service): + def test_api_content_provenance_sha_not_found(self, mock_service): # given mock_service.lookup_content_provenance.return_value = None @@ -381,8 +367,7 @@ 'sha1:40e71b8614fcd89ccd17ca2b1d9e66c5b00a6d03') @patch('swh.web.api.views.content.service') - @istest - def api_content_metadata(self, mock_service): + def test_api_content_metadata(self, mock_service): # given mock_service.lookup_content.return_value = { 'checksums': { @@ -428,8 +413,7 @@ 'sha1:40e71b8614fcd89ccd17ca2b1d9e66c5b00a6d03') @patch('swh.web.api.views.content.service') - @istest - def api_content_not_found_as_json(self, mock_service): + def test_api_content_not_found_as_json(self, mock_service): # given mock_service.lookup_content.return_value = None mock_service.lookup_content_provenance = MagicMock() @@ -453,8 +437,7 @@ mock_service.lookup_content_provenance.called = False @patch('swh.web.api.views.content.service') - @istest - def api_content_not_found_as_yaml(self, mock_service): + def test_api_content_not_found_as_yaml(self, mock_service): # given mock_service.lookup_content.return_value = None mock_service.lookup_content_provenance = MagicMock() @@ -480,8 +463,7 @@ mock_service.lookup_content_provenance.called = False @patch('swh.web.api.views.content.service') - @istest - def api_content_raw_ko_not_found(self, mock_service): + def test_api_content_raw_ko_not_found(self, mock_service): # given mock_service.lookup_content_raw.return_value = None @@ -502,8 +484,7 @@ 'sha1:40e71b8614fcd89ccd17ca2b1d9e66c5b00a6d03') @patch('swh.web.api.views.content.service') - @istest - def api_content_raw_text(self, mock_service): + def test_api_content_raw_text(self, mock_service): # given stub_content = {'data': b'some content data'} mock_service.lookup_content_raw.return_value = stub_content @@ -532,8 +513,7 @@ 'sha1:40e71b8614fcd89ccd17ca2b1d9e66c5b00a6d03') @patch('swh.web.api.views.content.service') - @istest - def api_content_raw_text_with_filename(self, mock_service): + def test_api_content_raw_text_with_filename(self, mock_service): # given stub_content = {'data': b'some content data'} mock_service.lookup_content_raw.return_value = stub_content @@ -561,8 +541,7 @@ 'sha1:40e71b8614fcd89ccd17ca2b1d9e66c5b00a6d03') @patch('swh.web.api.views.content.service') - @istest - def api_content_raw_no_accepted_media_type_text_is_not_available_for_download( # noqa + def test_api_content_raw_no_accepted_media_type_text_is_not_available_for_download( # noqa self, mock_service): # given stub_content = {'data': b'some content data'} @@ -590,8 +569,7 @@ 'sha1:40e71b8614fcd89ccd17ca2b1d9e66c5b00a6d03') @patch('swh.web.api.views.content.service') - @istest - def api_content_raw_no_accepted_media_type_found_so_not_available_for_download( # noqa + def test_api_content_raw_no_accepted_media_type_found_so_not_available_for_download( # noqa self, mock_service): # given stub_content = {'data': b'some content data'} @@ -617,8 +595,7 @@ 'sha1:40e71b8614fcd89ccd17ca2b1d9e66c5b00a6d03') @patch('swh.web.api.views.content.service') - @istest - def api_check_content_known(self, mock_service): + def test_api_check_content_known(self, mock_service): # given mock_service.lookup_multiple_hashes.return_value = [ {'found': True, @@ -642,8 +619,7 @@ [{'filename': None, 'sha1': 'sha1:blah'}]) @patch('swh.web.api.views.content.service') - @istest - def api_check_content_known_as_yaml(self, mock_service): + def test_api_check_content_known_as_yaml(self, mock_service): # given mock_service.lookup_multiple_hashes.return_value = [ {'found': True, @@ -675,8 +651,7 @@ {'filename': None, 'sha1': 'sha1_git:hello'}]) @patch('swh.web.api.views.content.service') - @istest - def api_check_content_known_post_as_yaml(self, mock_service): + def test_api_check_content_known_post_as_yaml(self, mock_service): # given stub_result = [{'sha1': '7e62b1fe10c88a3eddbba930b156bee2956b2435', 'found': True}, @@ -708,8 +683,7 @@ self.assertEquals(rv.data, expected_result) @patch('swh.web.api.views.content.service') - @istest - def api_check_content_known_not_found(self, mock_service): + def test_api_check_content_known_not_found(self, mock_service): # given stub_result = [{'sha1': 'sha1:halb', 'found': False}] diff --git a/swh/web/tests/api/views/test_directory.py b/swh/web/tests/api/views/test_directory.py --- a/swh/web/tests/api/views/test_directory.py +++ b/swh/web/tests/api/views/test_directory.py @@ -3,7 +3,6 @@ # License: GNU Affero General Public License version 3, or any later version # See top-level LICENSE file for more information -from nose.tools import istest from rest_framework.test import APITestCase from unittest.mock import patch @@ -13,8 +12,7 @@ class DirectoryApiTestCase(SWHWebTestCase, APITestCase): @patch('swh.web.api.views.directory.service') - @istest - def api_directory(self, mock_service): + def test_api_directory(self, mock_service): # given stub_directories = [ { @@ -59,8 +57,7 @@ '18d8be353ed3480476f032475e7c233eff7371d5') @patch('swh.web.api.views.directory.service') - @istest - def api_directory_not_found(self, mock_service): + def test_api_directory_not_found(self, mock_service): # given mock_service.lookup_directory.return_value = [] @@ -77,8 +74,7 @@ '66618d8be353ed3480476f032475e7c233eff737 not found.'}) @patch('swh.web.api.views.directory.service') - @istest - def api_directory_with_path_found(self, mock_service): + def test_api_directory_with_path_found(self, mock_service): # given expected_dir = { 'sha1_git': '18d8be353ed3480476f032475e7c233eff7371d5', @@ -104,8 +100,7 @@ '18d8be353ed3480476f032475e7c233eff7371d5', 'bla') @patch('swh.web.api.views.directory.service') - @istest - def api_directory_with_path_not_found(self, mock_service): + def test_api_directory_with_path_not_found(self, mock_service): # given mock_service.lookup_directory_with_path.return_value = None path = 'some/path/to/dir/' diff --git a/swh/web/tests/api/views/test_entity.py b/swh/web/tests/api/views/test_entity.py --- a/swh/web/tests/api/views/test_entity.py +++ b/swh/web/tests/api/views/test_entity.py @@ -3,7 +3,6 @@ # License: GNU Affero General Public License version 3, or any later version # See top-level LICENSE file for more information -from nose.tools import istest from rest_framework.test import APITestCase from unittest.mock import patch @@ -15,8 +14,7 @@ class EntityApiTestCase(SWHWebTestCase, APITestCase): @patch('swh.web.api.views.entity.service') - @istest - def api_lookup_entity_by_uuid_not_found(self, mock_service): + def test_api_lookup_entity_by_uuid_not_found(self, mock_service): # when mock_service.lookup_entity_by_uuid.return_value = [] @@ -36,8 +34,7 @@ '5f4d4c51-498a-4e28-88b3-b3e4e8396cba') @patch('swh.web.api.views.entity.service') - @istest - def api_lookup_entity_by_uuid_bad_request(self, mock_service): + def test_api_lookup_entity_by_uuid_bad_request(self, mock_service): # when mock_service.lookup_entity_by_uuid.side_effect = BadInputExc( 'bad input: uuid malformed!') @@ -54,8 +51,7 @@ 'uuid malformed') @patch('swh.web.api.views.entity.service') - @istest - def api_lookup_entity_by_uuid(self, mock_service): + def test_api_lookup_entity_by_uuid(self, mock_service): # when stub_entities = [ { diff --git a/swh/web/tests/api/views/test_identifiers.py b/swh/web/tests/api/views/test_identifiers.py --- a/swh/web/tests/api/views/test_identifiers.py +++ b/swh/web/tests/api/views/test_identifiers.py @@ -3,7 +3,6 @@ # License: GNU Affero General Public License version 3, or any later version # See top-level LICENSE file for more information -from nose.tools import istest from rest_framework.test import APITestCase from unittest.mock import patch @@ -16,9 +15,8 @@ class SwhIdsApiTestCase(SWHWebTestCase, APITestCase): - @istest @patch('swh.web.api.views.identifiers.service') - def swh_id_resolve_success(self, mock_service): + def test_swh_id_resolve_success(self, mock_service): rev_id = '96db9023b881d7cd9f379b0c154650d6c108e9a3' origin = 'https://github.com/openssl/openssl' swh_id = 'swh:1:rev:%s;origin=%s' % (rev_id, origin) @@ -44,8 +42,7 @@ self.assertEquals(resp.status_code, 200) self.assertEquals(resp.data, expected_result) - @istest - def swh_id_resolve_invalid(self): + def test_swh_id_resolve_invalid(self): rev_id_invalid = '96db9023b8_foo_50d6c108e9a3' swh_id = 'swh:1:rev:%s' % rev_id_invalid url = reverse('resolve-swh-pid', kwargs={'swh_id': swh_id}) @@ -54,9 +51,8 @@ self.assertEquals(resp.status_code, 400) - @istest @patch('swh.web.api.views.identifiers.service') - def swh_id_resolve_not_found(self, mock_service): + def test_swh_id_resolve_not_found(self, mock_service): rev_id_not_found = '56db90232881d7cd9e379b0c154650d6c108e9a1' swh_id = 'swh:1:rev:%s' % rev_id_not_found diff --git a/swh/web/tests/api/views/test_origin.py b/swh/web/tests/api/views/test_origin.py --- a/swh/web/tests/api/views/test_origin.py +++ b/swh/web/tests/api/views/test_origin.py @@ -3,7 +3,6 @@ # License: GNU Affero General Public License version 3, or any later version # See top-level LICENSE file for more information -from nose.tools import istest from rest_framework.test import APITestCase from unittest.mock import patch @@ -30,8 +29,9 @@ } @patch('swh.web.api.views.origin.get_origin_visits') - @istest - def api_1_lookup_origin_visits_raise_error(self, mock_get_origin_visits): + def test_api_1_lookup_origin_visits_raise_error( + self, mock_get_origin_visits, + ): # given mock_get_origin_visits.side_effect = ValueError( 'voluntary error to check the bad request middleware.') @@ -45,8 +45,7 @@ 'reason': 'voluntary error to check the bad request middleware.'}) @patch('swh.web.common.utils.service') - @istest - def api_1_lookup_origin_visits_raise_swh_storage_error_db( + def test_api_1_lookup_origin_visits_raise_swh_storage_error_db( self, mock_service): # given mock_service.lookup_origin_visits.side_effect = StorageDBError( @@ -63,8 +62,7 @@ 'SWH Storage exploded! Will be back online shortly!'}) @patch('swh.web.common.utils.service') - @istest - def api_1_lookup_origin_visits_raise_swh_storage_error_api( + def test_api_1_lookup_origin_visits_raise_swh_storage_error_api( self, mock_service): # given mock_service.lookup_origin_visits.side_effect = StorageAPIError( @@ -83,8 +81,7 @@ }) @patch('swh.web.api.views.origin.get_origin_visits') - @istest - def api_1_lookup_origin_visits(self, mock_get_origin_visits): + def test_api_1_lookup_origin_visits(self, mock_get_origin_visits): # given stub_visits = [ { @@ -141,8 +138,7 @@ ]) @patch('swh.web.api.views.origin.service') - @istest - def api_1_lookup_origin_visit(self, mock_service): + def test_api_1_lookup_origin_visit(self, mock_service): # given origin_visit = self.origin_visit1.copy() origin_visit.update({ @@ -168,8 +164,7 @@ mock_service.lookup_origin_visit.assert_called_once_with('10', '100') @patch('swh.web.api.views.origin.service') - @istest - def api_1_lookup_origin_visit_not_found(self, mock_service): + def test_api_1_lookup_origin_visit_not_found(self, mock_service): # given mock_service.lookup_origin_visit.return_value = None @@ -186,8 +181,7 @@ mock_service.lookup_origin_visit.assert_called_once_with('1', '1000') @patch('swh.web.api.views.origin.service') - @istest - def api_origin_by_id(self, mock_service): + def test_api_origin_by_id(self, mock_service): # given mock_service.lookup_origin.return_value = self.origin1 @@ -207,8 +201,7 @@ mock_service.lookup_origin.assert_called_with({'id': '1234'}) @patch('swh.web.api.views.origin.service') - @istest - def api_origin_by_type_url(self, mock_service): + def test_api_origin_by_type_url(self, mock_service): # given stub_origin = self.origin1.copy() stub_origin.update({ @@ -235,8 +228,7 @@ 'type': 'ftp'}) @patch('swh.web.api.views.origin.service') - @istest - def api_origin_not_found(self, mock_service): + def test_api_origin_not_found(self, mock_service): # given mock_service.lookup_origin.return_value = None diff --git a/swh/web/tests/api/views/test_origin_save.py b/swh/web/tests/api/views/test_origin_save.py --- a/swh/web/tests/api/views/test_origin_save.py +++ b/swh/web/tests/api/views/test_origin_save.py @@ -5,7 +5,6 @@ from datetime import datetime, timedelta -from nose.tools import istest, nottest from rest_framework.test import APITestCase from unittest.mock import patch @@ -25,14 +24,13 @@ class SaveApiTestCase(SWHWebTestCase, APITestCase): @classmethod - def setUpTestData(cls): + def setUpTestData(cls): # noqa: N802 SaveUnauthorizedOrigin.objects.create( url='https://github.com/user/illegal_repo') SaveUnauthorizedOrigin.objects.create( url='https://gitlab.com/user_to_exclude') - @istest - def invalid_origin_type(self): + def test_invalid_origin_type(self): url = reverse('save-origin', kwargs={'origin_type': 'foo', 'origin_url': 'https://github.com/torvalds/linux'}) # noqa @@ -40,8 +38,7 @@ response = self.client.post(url) self.assertEquals(response.status_code, 400) - @istest - def invalid_origin_url(self): + def test_invalid_origin_url(self): url = reverse('save-origin', kwargs={'origin_type': 'git', 'origin_url': 'bar'}) @@ -49,7 +46,6 @@ response = self.client.post(url) self.assertEquals(response.status_code, 400) - @nottest def check_created_save_request_status(self, mock_scheduler, origin_url, scheduler_task_status, expected_request_status, @@ -107,7 +103,6 @@ else: self.assertEqual(response.status_code, 403) - @nottest def check_save_request_status(self, mock_scheduler, origin_url, expected_request_status, expected_task_status, @@ -153,9 +148,8 @@ self.assertEqual(save_request_data['save_task_status'], expected_task_status) - @istest @patch('swh.web.common.origin_save.scheduler') - def save_request_rejected(self, mock_scheduler): + def test_save_request_rejected(self, mock_scheduler): origin_url = 'https://github.com/user/illegal_repo' self.check_created_save_request_status(mock_scheduler, origin_url, None, SAVE_REQUEST_REJECTED) @@ -163,9 +157,8 @@ SAVE_REQUEST_REJECTED, SAVE_TASK_NOT_CREATED) - @istest @patch('swh.web.common.origin_save.scheduler') - def save_request_pending(self, mock_scheduler): + def test_save_request_pending(self, mock_scheduler): origin_url = 'https://unkwownforge.com/user/repo' self.check_created_save_request_status(mock_scheduler, origin_url, None, SAVE_REQUEST_PENDING, @@ -174,9 +167,8 @@ SAVE_REQUEST_PENDING, SAVE_TASK_NOT_CREATED) - @istest @patch('swh.web.common.origin_save.scheduler') - def save_request_succeed(self, mock_scheduler): + def test_save_request_succeed(self, mock_scheduler): origin_url = 'https://github.com/Kitware/CMake' self.check_created_save_request_status(mock_scheduler, origin_url, None, SAVE_REQUEST_ACCEPTED, @@ -197,9 +189,8 @@ scheduler_task_status='completed', visit_date=visit_date) # noqa - @istest @patch('swh.web.common.origin_save.scheduler') - def save_request_failed(self, mock_scheduler): + def test_save_request_failed(self, mock_scheduler): origin_url = 'https://gitlab.com/inkscape/inkscape' self.check_created_save_request_status(mock_scheduler, origin_url, None, SAVE_REQUEST_ACCEPTED, @@ -213,9 +204,8 @@ SAVE_TASK_FAILED, scheduler_task_status='disabled') # noqa - @istest @patch('swh.web.common.origin_save.scheduler') - def create_save_request_only_when_needed(self, mock_scheduler): + def test_create_save_request_only_when_needed(self, mock_scheduler): origin_url = 'https://gitlab.com/webpack/webpack' SaveOriginRequest.objects.create(origin_type='git', origin_url=origin_url, diff --git a/swh/web/tests/api/views/test_person.py b/swh/web/tests/api/views/test_person.py --- a/swh/web/tests/api/views/test_person.py +++ b/swh/web/tests/api/views/test_person.py @@ -3,7 +3,6 @@ # License: GNU Affero General Public License version 3, or any later version # See top-level LICENSE file for more information -from nose.tools import istest from rest_framework.test import APITestCase from unittest.mock import patch @@ -13,8 +12,7 @@ class PersonApiTestCase(SWHWebTestCase, APITestCase): @patch('swh.web.api.views.person.service') - @istest - def api_person(self, mock_service): + def test_api_person(self, mock_service): # given stub_person = { 'id': '198003', @@ -32,8 +30,7 @@ self.assertEquals(rv.data, stub_person) @patch('swh.web.api.views.person.service') - @istest - def api_person_not_found(self, mock_service): + def test_api_person_not_found(self, mock_service): # given mock_service.lookup_person.return_value = None diff --git a/swh/web/tests/api/views/test_release.py b/swh/web/tests/api/views/test_release.py --- a/swh/web/tests/api/views/test_release.py +++ b/swh/web/tests/api/views/test_release.py @@ -3,7 +3,6 @@ # License: GNU Affero General Public License version 3, or any later version # See top-level LICENSE file for more information -from nose.tools import istest from rest_framework.test import APITestCase from unittest.mock import patch @@ -13,8 +12,7 @@ class ReleaseApiTestCase(SWHWebTestCase, APITestCase): @patch('swh.web.api.views.release.service') - @istest - def api_release(self, mock_service): + def test_api_release(self, mock_service): release_id = '7045404f3d1c54e6473' target_id = '6072557b6c10cd9a211' # given @@ -59,8 +57,7 @@ mock_service.lookup_release.assert_called_once_with(release_id) @patch('swh.web.api.views.release.service') - @istest - def api_release_target_type_not_a_revision(self, mock_service): + def test_api_release_target_type_not_a_revision(self, mock_service): release = '8d56a78' target = '9a5c3f' # given @@ -104,8 +101,7 @@ mock_service.lookup_release.assert_called_once_with(release) @patch('swh.web.api.views.release.service') - @istest - def api_release_not_found(self, mock_service): + def test_api_release_not_found(self, mock_service): # given mock_service.lookup_release.return_value = None diff --git a/swh/web/tests/api/views/test_revision.py b/swh/web/tests/api/views/test_revision.py --- a/swh/web/tests/api/views/test_revision.py +++ b/swh/web/tests/api/views/test_revision.py @@ -3,7 +3,6 @@ # License: GNU Affero General Public License version 3, or any later version # See top-level LICENSE file for more information -from nose.tools import istest from rest_framework.test import APITestCase from unittest.mock import patch @@ -18,8 +17,7 @@ class ReleaseApiTestCase(SWHWebTestCase, APITestCase): @patch('swh.web.api.views.revision.service') - @istest - def api_revision(self, mock_service): + def test_api_revision(self, mock_service): # given stub_revision = { 'id': '18d8be353ed3480476f032475e7c233eff7371d5', @@ -93,8 +91,7 @@ '18d8be353ed3480476f032475e7c233eff7371d5') @patch('swh.web.api.views.revision.service') - @istest - def api_revision_not_found(self, mock_service): + def test_api_revision_not_found(self, mock_service): # given mock_service.lookup_revision.return_value = None @@ -109,8 +106,7 @@ 'reason': 'Revision with sha1_git 12345 not found.'}) @patch('swh.web.api.views.revision.service') - @istest - def api_revision_raw_ok(self, mock_service): + def test_api_revision_raw_ok(self, mock_service): # given stub_revision = {'message': 'synthetic revision message'} @@ -128,8 +124,7 @@ '18d8be353ed3480476f032475e7c233eff7371d5') @patch('swh.web.api.views.revision.service') - @istest - def api_revision_raw_ok_no_msg(self, mock_service): + def test_api_revision_raw_ok_no_msg(self, mock_service): # given mock_service.lookup_revision_message.side_effect = NotFoundExc( 'No message for revision') @@ -150,8 +145,7 @@ '18d8be353ed3480476f032475e7c233eff7371d5') @patch('swh.web.api.views.revision.service') - @istest - def api_revision_raw_ko_no_rev(self, mock_service): + def test_api_revision_raw_ko_no_rev(self, mock_service): # given mock_service.lookup_revision_message.side_effect = NotFoundExc( 'No revision found') @@ -171,8 +165,7 @@ '18d8be353ed3480476f032475e7c233eff7371d5') @patch('swh.web.api.views.revision.service') - @istest - def api_revision_with_origin_not_found(self, mock_service): + def test_api_revision_with_origin_not_found(self, mock_service): mock_service.lookup_revision_by.return_value = None rv = self.client.get('/api/1/revision/origin/123/') @@ -190,8 +183,7 @@ None) @patch('swh.web.api.views.revision.service') - @istest - def api_revision_with_origin(self, mock_service): + def test_api_revision_with_origin(self, mock_service): mock_revision = { 'id': '32', 'directory': '21', @@ -222,8 +214,7 @@ None) @patch('swh.web.api.views.revision.service') - @istest - def api_revision_with_origin_and_branch_name(self, mock_service): + def test_api_revision_with_origin_and_branch_name(self, mock_service): mock_revision = { 'id': '12', 'directory': '23', @@ -258,8 +249,7 @@ @patch('swh.web.api.views.revision.parse_timestamp') @patch('swh.web.api.views.revision.service') @patch('swh.web.api.views.revision.utils') - @istest - def api_revision_with_origin_and_branch_name_and_timestamp(self, + def test_api_revision_with_origin_and_branch_name_and_timestamp(self, mock_utils, mock_service, mock_parse_timestamp): # noqa @@ -305,8 +295,7 @@ @patch('swh.web.api.views.revision.parse_timestamp') @patch('swh.web.api.views.revision.service') @patch('swh.web.api.views.revision.utils') - @istest - def api_revision_with_origin_and_branch_name_and_timestamp_with_escapes( + def test_api_revision_with_origin_and_branch_name_and_timestamp_escapes( self, mock_utils, mock_service, @@ -346,8 +335,7 @@ mock_revision) @patch('swh.web.api.views.revision.service') - @istest - def revision_directory_by_ko_raise(self, mock_service): + def test_revision_directory_by_ko_raise(self, mock_service): # given mock_service.lookup_directory_through_revision.side_effect = NotFoundExc('not') # noqa @@ -364,8 +352,7 @@ None, limit=100, with_data=False) @patch('swh.web.api.views.revision.service') - @istest - def revision_directory_by_type_dir(self, mock_service): + def test_revision_directory_by_type_dir(self, mock_service): # given mock_service.lookup_directory_through_revision.return_value = ( 'rev-id', @@ -393,8 +380,7 @@ 'some/path', limit=100, with_data=False) @patch('swh.web.api.views.revision.service') - @istest - def revision_directory_by_type_file(self, mock_service): + def test_revision_directory_by_type_file(self, mock_service): # given mock_service.lookup_directory_through_revision.return_value = ( 'rev-id', @@ -426,8 +412,7 @@ @patch('swh.web.api.views.revision.parse_timestamp') @patch('swh.web.api.views.revision._revision_directory_by') @patch('swh.web.api.views.revision.utils') - @istest - def api_directory_through_revision_origin_ko_not_found(self, + def test_api_directory_through_revision_origin_ko_not_found(self, mock_utils, mock_rev_dir, mock_parse_timestamp): # noqa @@ -459,9 +444,8 @@ with_data=False) @patch('swh.web.api.views.revision._revision_directory_by') - @istest - def api_directory_through_revision_origin(self, - mock_revision_dir): + def test_api_directory_through_revision_origin(self, + mock_revision_dir): expected_res = [{ 'id': '123' }] @@ -481,8 +465,7 @@ with_data=False) @patch('swh.web.api.views.revision.service') - @istest - def api_revision_log(self, mock_service): + def test_api_revision_log(self, mock_service): # given stub_revisions = [{ 'id': '18d8be353ed3480476f032475e7c233eff7371d5', @@ -538,8 +521,7 @@ '8834ef7e7c357ce2af928115c6c6a42b7e2a44e6', 11) @patch('swh.web.api.views.revision.service') - @istest - def api_revision_log_with_next(self, mock_service): + def test_api_revision_log_with_next(self, mock_service): # given stub_revisions = [] for i in range(27): @@ -567,8 +549,7 @@ '8834ef7e7c357ce2af928115c6c6a42b7e2a44e6', 26) @patch('swh.web.api.views.revision.service') - @istest - def api_revision_log_not_found(self, mock_service): + def test_api_revision_log_not_found(self, mock_service): # given mock_service.lookup_revision_log.return_value = None @@ -589,8 +570,7 @@ '8834ef7e7c357ce2af928115c6c6a42b7e2a44e6', 11) @patch('swh.web.api.views.revision.service') - @istest - def api_revision_log_context(self, mock_service): + def test_api_revision_log_context(self, mock_service): # given stub_revisions = [{ 'id': '18d8be353ed3480476f032475e7c233eff7371d5', @@ -688,8 +668,7 @@ ['21145781e26ad1f978e']) @patch('swh.web.api.views.revision.service') - @istest - def api_revision_log_by(self, mock_service): + def test_api_revision_log_by(self, mock_service): # given stub_revisions = [{ 'id': '18d8be353ed3480476f032475e7c233eff7371d5', @@ -743,8 +722,7 @@ '1', 'refs/heads/master', None, 11) @patch('swh.web.api.views.revision.service') - @istest - def api_revision_log_by_with_next(self, mock_service): + def test_api_revision_log_by_with_next(self, mock_service): # given stub_revisions = [] for i in range(27): @@ -770,8 +748,7 @@ '1', 'refs/heads/master', None, 26) @patch('swh.web.api.views.revision.service') - @istest - def api_revision_log_by_norev(self, mock_service): + def test_api_revision_log_by_norev(self, mock_service): # given mock_service.lookup_revision_log_by.side_effect = NotFoundExc( 'No revision') @@ -790,8 +767,7 @@ '1', 'refs/heads/master', None, 11) @patch('swh.web.api.views.revision.service') - @istest - def api_revision_history(self, mock_service): + def test_api_revision_history(self, mock_service): # for readability purposes, we use: # - sha1 as 3 letters (url are way too long otherwise to respect pep8) # - only keys with modification steps (all other keys are kept as is) @@ -827,8 +803,7 @@ mock_service.lookup_revision.assert_called_once_with('883') @patch('swh.web.api.views.revision._revision_directory_by') - @istest - def api_revision_directory_ko_not_found(self, mock_rev_dir): + def test_api_revision_directory_ko_not_found(self, mock_rev_dir): # given mock_rev_dir.side_effect = NotFoundExc('Not found') @@ -848,8 +823,7 @@ with_data=False) @patch('swh.web.api.views.revision._revision_directory_by') - @istest - def api_revision_directory_ok_returns_dir_entries(self, mock_rev_dir): + def test_api_revision_directory_ok_returns_dir_entries(self, mock_rev_dir): stub_dir = { 'type': 'dir', 'revision': '999', @@ -891,8 +865,7 @@ with_data=False) @patch('swh.web.api.views.revision._revision_directory_by') - @istest - def api_revision_directory_ok_returns_content(self, mock_rev_dir): + def test_api_revision_directory_ok_returns_content(self, mock_rev_dir): stub_content = { 'type': 'file', 'revision': '999', diff --git a/swh/web/tests/api/views/test_stat.py b/swh/web/tests/api/views/test_stat.py --- a/swh/web/tests/api/views/test_stat.py +++ b/swh/web/tests/api/views/test_stat.py @@ -3,7 +3,6 @@ # License: GNU Affero General Public License version 3, or any later version # See top-level LICENSE file for more information -from nose.tools import istest from rest_framework.test import APITestCase from unittest.mock import patch @@ -14,8 +13,7 @@ class StatApiTestCase(SWHWebTestCase, APITestCase): @patch('swh.web.api.views.stat.service') - @istest - def api_1_stat_counters_raise_error(self, mock_service): + def test_api_1_stat_counters_raise_error(self, mock_service): # given mock_service.stat_counters.side_effect = ValueError( 'voluntary error to check the bad request middleware.') @@ -29,8 +27,7 @@ 'reason': 'voluntary error to check the bad request middleware.'}) @patch('swh.web.api.views.stat.service') - @istest - def api_1_stat_counters_raise_swh_storage_error_db(self, mock_service): + def test_api_1_stat_counters_raise_from_db(self, mock_service): # given mock_service.stat_counters.side_effect = StorageDBError( 'SWH Storage exploded! Will be back online shortly!') @@ -46,8 +43,7 @@ 'SWH Storage exploded! Will be back online shortly!'}) @patch('swh.web.api.views.stat.service') - @istest - def api_1_stat_counters_raise_swh_storage_error_api(self, mock_service): + def test_api_1_stat_counters_raise_from_api(self, mock_service): # given mock_service.stat_counters.side_effect = StorageAPIError( 'SWH Storage API dropped dead! Will resurrect from its ashes asap!' @@ -65,8 +61,7 @@ }) @patch('swh.web.api.views.stat.service') - @istest - def api_1_stat_counters(self, mock_service): + def test_api_1_stat_counters(self, mock_service): # given stub_stats = { "content": 1770830, diff --git a/swh/web/tests/api/views/test_vault.py b/swh/web/tests/api/views/test_vault.py --- a/swh/web/tests/api/views/test_vault.py +++ b/swh/web/tests/api/views/test_vault.py @@ -3,7 +3,6 @@ # License: GNU Affero General Public License version 3, or any later version # See top-level LICENSE file for more information -from nose.tools import istest from rest_framework.test import APITestCase from unittest.mock import patch @@ -19,8 +18,7 @@ class VaultApiTestCase(SWHWebTestCase, APITestCase): @patch('swh.web.api.views.vault.service') - @istest - def api_vault_cook(self, mock_service): + def test_api_vault_cook(self, mock_service): stub_cook = { 'fetch_url': ('http://127.0.0.1:5004/api/1/vault/directory/{}/raw/' .format(TEST_OBJ_ID)), @@ -59,8 +57,7 @@ obj_type, hashutil.hash_to_bytes(TEST_OBJ_ID)) @patch('swh.web.api.views.vault.service') - @istest - def api_vault_cook_notfound(self, mock_service): + def test_api_vault_cook_notfound(self, mock_service): mock_service.vault_cook.return_value = None mock_service.vault_fetch.return_value = None diff --git a/swh/web/tests/browse/test_utils.py b/swh/web/tests/browse/test_utils.py --- a/swh/web/tests/browse/test_utils.py +++ b/swh/web/tests/browse/test_utils.py @@ -6,7 +6,6 @@ # flake8: noqa from unittest.mock import patch -from nose.tools import istest from swh.web.browse import utils from swh.web.common.exc import NotFoundExc @@ -18,15 +17,13 @@ class SwhBrowseUtilsTestCase(SWHWebTestCase): - @istest - def get_mimetype_and_encoding_for_content(self): + def test_get_mimetype_and_encoding_for_content(self): text = b'Hello world!' self.assertEqual(utils.get_mimetype_and_encoding_for_content(text), ('text/plain', 'us-ascii')) @patch('swh.web.browse.utils.get_origin_visits') - @istest - def get_origin_visit(self, mock_origin_visits): + def test_get_origin_visit(self, mock_origin_visits): origin_info = { 'id': 2, 'type': 'git', @@ -102,8 +99,7 @@ @patch('swh.web.browse.utils.service') @patch('swh.web.browse.utils.get_origin_visit') - @istest - def get_origin_visit_snapshot(self, mock_get_origin_visit, + def test_get_origin_visit_snapshot(self, mock_get_origin_visit, mock_service): mock_get_origin_visit.return_value = \ @@ -223,13 +219,11 @@ self.assertEqual(origin_visit_branches, expected_result) - @istest - def gen_link(self): + def test_gen_link(self): self.assertEqual(utils.gen_link('https://www.softwareheritage.org/', 'SWH'), 'SWH') - @istest - def gen_person_link(self): + def test_gen_person_link(self): person_id = 8221896 person_name = 'Antoine Lambert' person_url = reverse('browse-person', kwargs={'person_id': person_id}) @@ -237,8 +231,7 @@ self.assertEqual(utils.gen_person_link(person_id, person_name), '%s' % (person_url, person_name)) - @istest - def gen_revision_link(self): + def test_gen_revision_link(self): revision_id = '28a0bc4120d38a394499382ba21d6965a67a3703' revision_url = reverse('browse-revision', kwargs={'sha1_git': revision_id}) @@ -248,8 +241,7 @@ self.assertEqual(utils.gen_revision_link(revision_id, shorten_id=True), '%s' % (revision_url, revision_id[:7])) - @istest - def prepare_revision_log_for_display_no_contex(self): + def test_prepare_revision_log_for_display_no_contex(self): per_page = 10 first_page_logs_data = revision_history_log_test[:per_page+1] second_page_logs_data = revision_history_log_test[per_page:2*per_page+1] @@ -331,8 +323,7 @@ self.assertEqual(revision_log_display_data['next_revs_breadcrumb'], '/'.join(old_prev_revs_bc.split('/')[:-1])) - @istest - def prepare_revision_log_for_display_snapshot_context(self): + def test_prepare_revision_log_for_display_snapshot_context(self): per_page = 10 first_page_logs_data = revision_history_log_test[:per_page+1] second_page_logs_data = revision_history_log_test[per_page:2*per_page+1] diff --git a/swh/web/tests/browse/views/test_content.py b/swh/web/tests/browse/views/test_content.py --- a/swh/web/tests/browse/views/test_content.py +++ b/swh/web/tests/browse/views/test_content.py @@ -6,7 +6,6 @@ import base64 from unittest.mock import patch -from nose.tools import istest from django.utils.html import escape from django.utils.encoding import DjangoUnicodeDecodeError @@ -33,8 +32,7 @@ class SwhBrowseContentTest(SWHWebTestCase): @patch('swh.web.browse.views.content.request_content') - @istest - def content_view_text(self, mock_request_content): + def test_content_view_text(self, mock_request_content): mock_request_content.return_value = stub_content_text_data sha1_git = stub_content_text_data['checksums']['sha1_git'] @@ -61,8 +59,7 @@ self.assertContains(resp, swh_cnt_id_url) @patch('swh.web.browse.views.content.request_content') - @istest - def content_view_text_no_highlight(self, mock_request_content): + def test_content_view_text_no_highlight(self, mock_request_content): mock_request_content.return_value = stub_content_text_no_highlight_data sha1_git = stub_content_text_no_highlight_data['checksums']['sha1_git'] @@ -90,8 +87,7 @@ self.assertContains(resp, swh_cnt_id_url) @patch('swh.web.browse.utils.service') - @istest - def content_view_no_utf8_text(self, mock_service): + def test_content_view_no_utf8_text(self, mock_service): mock_service.lookup_content.return_value = \ non_utf8_encoded_content_data @@ -120,8 +116,7 @@ self.fail('Textual content is not encoded in utf-8') @patch('swh.web.browse.views.content.request_content') - @istest - def content_view_image(self, mock_request_content): + def test_content_view_image(self, mock_request_content): mime_type = 'image/png' mock_request_content.return_value = stub_content_bin_data @@ -137,16 +132,15 @@ self.assertEquals(resp.status_code, 200) self.assertTemplateUsed('browse/content.html') - pngEncoded = base64.b64encode(stub_content_bin_data['raw_data']) \ - .decode('utf-8') + png_encoded = base64.b64encode(stub_content_bin_data['raw_data']) \ + .decode('utf-8') self.assertContains(resp, '' - % (mime_type, pngEncoded)) + % (mime_type, png_encoded)) self.assertContains(resp, url_raw) @patch('swh.web.browse.views.content.request_content') - @istest - def content_view_with_path(self, mock_request_content): + def test_content_view_with_path(self, mock_request_content): mock_request_content.return_value = stub_content_text_data url = reverse('browse-content', @@ -194,8 +188,7 @@ self.assertContains(resp, url_raw) @patch('swh.web.browse.views.content.request_content') - @istest - def content_raw_text(self, mock_request_content): + def test_content_raw_text(self, mock_request_content): mock_request_content.return_value = stub_content_text_data url = reverse('browse-content-raw', @@ -224,7 +217,6 @@ self.assertEqual(resp.content, stub_content_text_data['raw_data']) @patch('swh.web.browse.utils.service') - @istest def test_content_raw_no_utf8_text(self, mock_service): mock_service.lookup_content.return_value = \ non_utf8_encoded_content_data @@ -245,8 +237,7 @@ self.assertEqual(encoding, non_utf8_encoding) @patch('swh.web.browse.views.content.request_content') - @istest - def content_raw_bin(self, mock_request_content): + def test_content_raw_bin(self, mock_request_content): mock_request_content.return_value = stub_content_bin_data url = reverse('browse-content-raw', @@ -274,8 +265,7 @@ self.assertEqual(resp.content, stub_content_bin_data['raw_data']) @patch('swh.web.browse.views.content.request_content') - @istest - def content_request_errors(self, mock_request_content): + def test_content_request_errors(self, mock_request_content): url = reverse('browse-content', kwargs={'query_string': '123456'}) resp = self.client.get(url) @@ -291,8 +281,7 @@ self.assertTemplateUsed('error.html') @patch('swh.web.browse.utils.service') - @istest - def content_bytes_missing(self, mock_service): + def test_content_bytes_missing(self, mock_service): content_data = dict(stub_content_text_data) content_data['raw_data'] = None @@ -308,8 +297,7 @@ self.assertTemplateUsed('browse/content.html') @patch('swh.web.browse.views.content.request_content') - @istest - def content_too_large(self, mock_request_content): + def test_content_too_large(self, mock_request_content): mock_request_content.return_value = stub_content_too_large_data url = reverse('browse-content', diff --git a/swh/web/tests/browse/views/test_directory.py b/swh/web/tests/browse/views/test_directory.py --- a/swh/web/tests/browse/views/test_directory.py +++ b/swh/web/tests/browse/views/test_directory.py @@ -4,7 +4,6 @@ # See top-level LICENSE file for more information from unittest.mock import patch -from nose.tools import istest, nottest from swh.web.common.exc import BadInputExc, NotFoundExc from swh.web.common.utils import reverse, get_swh_persistent_id @@ -19,7 +18,6 @@ class SwhBrowseDirectoryTest(SWHWebTestCase): - @nottest def directory_view(self, root_directory_sha1, directory_entries, path=None): dirs = [e for e in directory_entries if e['type'] in ('dir', 'rev')] @@ -92,8 +90,7 @@ self.assertContains(resp, swh_dir_id_url) @patch('swh.web.browse.utils.service') - @istest - def root_directory_view(self, mock_service): + def test_root_directory_view(self, mock_service): mock_service.lookup_directory.return_value = \ stub_root_directory_data @@ -101,8 +98,8 @@ @patch('swh.web.browse.utils.service') @patch('swh.web.browse.views.directory.service') - @istest - def sub_directory_view(self, mock_directory_service, mock_utils_service): + def test_sub_directory_view(self, mock_directory_service, + mock_utils_service): mock_utils_service.lookup_directory.return_value = \ stub_sub_directory_data mock_directory_service.lookup_directory_with_path.return_value = \ @@ -114,9 +111,8 @@ @patch('swh.web.browse.utils.service') @patch('swh.web.browse.views.directory.service') - @istest - def directory_request_errors(self, mock_directory_service, - mock_utils_service): + def test_directory_request_errors(self, mock_directory_service, + mock_utils_service): mock_utils_service.lookup_directory.side_effect = \ BadInputExc('directory not found') diff --git a/swh/web/tests/browse/views/test_identifiers.py b/swh/web/tests/browse/views/test_identifiers.py --- a/swh/web/tests/browse/views/test_identifiers.py +++ b/swh/web/tests/browse/views/test_identifiers.py @@ -6,7 +6,6 @@ # flake8: noqa from unittest.mock import patch -from nose.tools import istest from swh.web.common.exc import BadInputExc from swh.web.common.utils import reverse @@ -25,8 +24,7 @@ class SwhBrowseIdTest(SWHWebTestCase): - @istest - def content_id_browse(self): + def test_content_id_browse(self): cnt_sha1_git = stub_content_text_data['checksums']['sha1_git'] swh_id = swh_id_prefix + 'cnt:' + cnt_sha1_git url = reverse('browse-swh-id', @@ -41,8 +39,7 @@ self.assertEquals(resp.status_code, 302) self.assertEqual(resp['location'], content_browse_url) - @istest - def directory_id_browse(self): + def test_directory_id_browse(self): swh_id = swh_id_prefix + 'dir:' + stub_root_directory_sha1 url = reverse('browse-swh-id', kwargs={'swh_id': swh_id}) @@ -55,8 +52,7 @@ self.assertEquals(resp.status_code, 302) self.assertEqual(resp['location'], directory_browse_url) - @istest - def revision_id_browse(self): + def test_revision_id_browse(self): swh_id = swh_id_prefix + 'rev:' + revision_id_test url = reverse('browse-swh-id', kwargs={'swh_id': swh_id}) @@ -84,8 +80,7 @@ self.assertEquals(resp.status_code, 302) self.assertEqual(resp['location'], revision_browse_url) - @istest - def release_id_browse(self): + def test_release_id_browse(self): swh_id = swh_id_prefix + 'rel:' + stub_release['id'] url = reverse('browse-swh-id', kwargs={'swh_id': swh_id}) @@ -113,8 +108,7 @@ self.assertEquals(resp.status_code, 302) self.assertEqual(resp['location'], release_browse_url) - @istest - def bad_id_browse(self): + def test_bad_id_browse(self): swh_id = swh_id_prefix + 'foo:' + stub_release['id'] url = reverse('browse-swh-id', kwargs={'swh_id': swh_id}) @@ -122,8 +116,7 @@ resp = self.client.get(url) self.assertEquals(resp.status_code, 400) - @istest - def content_id_optional_parts_browse(self): + def test_content_id_optional_parts_browse(self): cnt_sha1_git = stub_content_text_data['checksums']['sha1_git'] optional_parts = ';lines=4-20;origin=https://github.com/user/repo' swh_id = swh_id_prefix + 'cnt:' + cnt_sha1_git + optional_parts diff --git a/swh/web/tests/browse/views/test_origin.py b/swh/web/tests/browse/views/test_origin.py --- a/swh/web/tests/browse/views/test_origin.py +++ b/swh/web/tests/browse/views/test_origin.py @@ -6,7 +6,6 @@ # flake8: noqa from unittest.mock import patch -from nose.tools import istest, nottest from django.utils.html import escape @@ -45,8 +44,7 @@ @patch('swh.web.browse.views.origin.get_origin_info') @patch('swh.web.browse.views.origin.get_origin_visits') @patch('swh.web.browse.views.origin.service') - @istest - def origin_visits_browse(self, mock_service, mock_get_origin_visits, + def test_origin_visits_browse(self, mock_service, mock_get_origin_visits, mock_get_origin_info): mock_service.lookup_origin.return_value = origin_info_test_data mock_get_origin_info.return_value = origin_info_test_data @@ -67,14 +65,13 @@ self.assertEquals(resp.status_code, 200) self.assertTemplateUsed('origin-visits.html') - @nottest - def origin_content_view_test(self, origin_info, origin_visits, - origin_branches, origin_releases, - origin_branch, - root_dir_sha1, content_sha1, content_sha1_git, - content_path, content_data, - content_language, - visit_id=None, timestamp=None): + def origin_content_view_helper(self, origin_info, origin_visits, + origin_branches, origin_releases, + origin_branch, + root_dir_sha1, content_sha1, content_sha1_git, + content_path, content_data, + content_language, + visit_id=None, timestamp=None): url_args = {'origin_type': origin_info['type'], 'origin_url': origin_info['url'], @@ -210,8 +207,7 @@ @patch('swh.web.browse.views.utils.snapshot_context.service') @patch('swh.web.browse.utils.service') @patch('swh.web.browse.views.utils.snapshot_context.request_content') - @istest - def origin_content_view(self, mock_request_content, mock_utils_service, + def test_origin_content_view(self, mock_request_content, mock_utils_service, mock_service, mock_get_origin_visit_snapshot, mock_get_origin_visits): @@ -224,62 +220,61 @@ mock_request_content.return_value = stub_content_text_data mock_utils_service.lookup_origin.return_value = stub_content_origin_info - self.origin_content_view_test(stub_content_origin_info, - stub_content_origin_visits, - stub_content_origin_snapshot[0], - stub_content_origin_snapshot[1], - stub_content_origin_branch, - stub_content_root_dir, - stub_content_text_sha1, - stub_content_text_sha1_git, - stub_content_text_path, - stub_content_text_data['raw_data'], - 'cpp') - - self.origin_content_view_test(stub_content_origin_info, - stub_content_origin_visits, - stub_content_origin_snapshot[0], - stub_content_origin_snapshot[1], - stub_content_origin_branch, - stub_content_root_dir, - stub_content_text_sha1, - stub_content_text_sha1_git, - stub_content_text_path, - stub_content_text_data['raw_data'], - 'cpp', - visit_id=stub_content_origin_visit_id) - - self.origin_content_view_test(stub_content_origin_info, - stub_content_origin_visits, - stub_content_origin_snapshot[0], - stub_content_origin_snapshot[1], - stub_content_origin_branch, - stub_content_root_dir, - stub_content_text_sha1, - stub_content_text_sha1_git, - stub_content_text_path, - stub_content_text_data['raw_data'], - 'cpp', - timestamp=stub_content_origin_visit_unix_ts) - - self.origin_content_view_test(stub_content_origin_info, - stub_content_origin_visits, - stub_content_origin_snapshot[0], - stub_content_origin_snapshot[1], - stub_content_origin_branch, - stub_content_root_dir, - stub_content_text_sha1, - stub_content_text_sha1_git, - stub_content_text_path, - stub_content_text_data['raw_data'], - 'cpp', - timestamp=stub_content_origin_visit_iso_date) - - @nottest - def origin_directory_view(self, origin_info, origin_visits, - origin_branches, origin_releases, origin_branch, - root_directory_sha1, directory_entries, - visit_id=None, timestamp=None, path=None): + self.origin_content_view_helper(stub_content_origin_info, + stub_content_origin_visits, + stub_content_origin_snapshot[0], + stub_content_origin_snapshot[1], + stub_content_origin_branch, + stub_content_root_dir, + stub_content_text_sha1, + stub_content_text_sha1_git, + stub_content_text_path, + stub_content_text_data['raw_data'], + 'cpp') + + self.origin_content_view_helper(stub_content_origin_info, + stub_content_origin_visits, + stub_content_origin_snapshot[0], + stub_content_origin_snapshot[1], + stub_content_origin_branch, + stub_content_root_dir, + stub_content_text_sha1, + stub_content_text_sha1_git, + stub_content_text_path, + stub_content_text_data['raw_data'], + 'cpp', + visit_id=stub_content_origin_visit_id) + + self.origin_content_view_helper(stub_content_origin_info, + stub_content_origin_visits, + stub_content_origin_snapshot[0], + stub_content_origin_snapshot[1], + stub_content_origin_branch, + stub_content_root_dir, + stub_content_text_sha1, + stub_content_text_sha1_git, + stub_content_text_path, + stub_content_text_data['raw_data'], + 'cpp', + timestamp=stub_content_origin_visit_unix_ts) + + self.origin_content_view_helper(stub_content_origin_info, + stub_content_origin_visits, + stub_content_origin_snapshot[0], + stub_content_origin_snapshot[1], + stub_content_origin_branch, + stub_content_root_dir, + stub_content_text_sha1, + stub_content_text_sha1_git, + stub_content_text_path, + stub_content_text_data['raw_data'], + 'cpp', + timestamp=stub_content_origin_visit_iso_date) + + def origin_directory_view_helper(self, origin_info, origin_visits, + origin_branches, origin_releases, origin_branch, + root_directory_sha1, directory_entries, + visit_id=None, timestamp=None, path=None): dirs = [e for e in directory_entries if e['type'] in ('dir', 'rev')] @@ -425,8 +420,7 @@ @patch('swh.web.browse.utils.get_origin_visit_snapshot') @patch('swh.web.browse.utils.service') @patch('swh.web.browse.views.origin.service') - @istest - def origin_root_directory_view(self, mock_origin_service, + def test_origin_root_directory_view(self, mock_origin_service, mock_utils_service, mock_get_origin_visit_snapshot, mock_get_origin_visits): @@ -437,74 +431,73 @@ stub_origin_root_directory_entries mock_utils_service.lookup_origin.return_value = stub_origin_info - self.origin_directory_view(stub_origin_info, stub_origin_visits, - stub_origin_snapshot[0], - stub_origin_snapshot[1], - stub_origin_master_branch, - stub_origin_root_directory_sha1, - stub_origin_root_directory_entries) - - self.origin_directory_view(stub_origin_info, stub_origin_visits, - stub_origin_snapshot[0], - stub_origin_snapshot[1], - stub_origin_master_branch, - stub_origin_root_directory_sha1, - stub_origin_root_directory_entries, - visit_id=stub_visit_id) - - self.origin_directory_view(stub_origin_info, stub_origin_visits, - stub_origin_snapshot[0], - stub_origin_snapshot[1], - stub_origin_master_branch, - stub_origin_root_directory_sha1, - stub_origin_root_directory_entries, - timestamp=stub_visit_unix_ts) - - self.origin_directory_view(stub_origin_info, stub_origin_visits, - stub_origin_snapshot[0], - stub_origin_snapshot[1], - stub_origin_master_branch, - stub_origin_root_directory_sha1, - stub_origin_root_directory_entries, - timestamp=stub_visit_iso_date) - - self.origin_directory_view(stub_origin_info_no_type, stub_origin_visits, - stub_origin_snapshot[0], - stub_origin_snapshot[1], - stub_origin_master_branch, - stub_origin_root_directory_sha1, - stub_origin_root_directory_entries) - - self.origin_directory_view(stub_origin_info_no_type, stub_origin_visits, - stub_origin_snapshot[0], - stub_origin_snapshot[1], - stub_origin_master_branch, - stub_origin_root_directory_sha1, - stub_origin_root_directory_entries, - visit_id=stub_visit_id) - - self.origin_directory_view(stub_origin_info_no_type, stub_origin_visits, - stub_origin_snapshot[0], - stub_origin_snapshot[1], - stub_origin_master_branch, - stub_origin_root_directory_sha1, - stub_origin_root_directory_entries, - timestamp=stub_visit_unix_ts) - - self.origin_directory_view(stub_origin_info_no_type, stub_origin_visits, - stub_origin_snapshot[0], - stub_origin_snapshot[1], - stub_origin_master_branch, - stub_origin_root_directory_sha1, - stub_origin_root_directory_entries, - timestamp=stub_visit_iso_date) + self.origin_directory_view_helper(stub_origin_info, stub_origin_visits, + stub_origin_snapshot[0], + stub_origin_snapshot[1], + stub_origin_master_branch, + stub_origin_root_directory_sha1, + stub_origin_root_directory_entries) + + self.origin_directory_view_helper(stub_origin_info, stub_origin_visits, + stub_origin_snapshot[0], + stub_origin_snapshot[1], + stub_origin_master_branch, + stub_origin_root_directory_sha1, + stub_origin_root_directory_entries, + visit_id=stub_visit_id) + + self.origin_directory_view_helper(stub_origin_info, stub_origin_visits, + stub_origin_snapshot[0], + stub_origin_snapshot[1], + stub_origin_master_branch, + stub_origin_root_directory_sha1, + stub_origin_root_directory_entries, + timestamp=stub_visit_unix_ts) + + self.origin_directory_view_helper(stub_origin_info, stub_origin_visits, + stub_origin_snapshot[0], + stub_origin_snapshot[1], + stub_origin_master_branch, + stub_origin_root_directory_sha1, + stub_origin_root_directory_entries, + timestamp=stub_visit_iso_date) + + self.origin_directory_view_helper(stub_origin_info_no_type, stub_origin_visits, + stub_origin_snapshot[0], + stub_origin_snapshot[1], + stub_origin_master_branch, + stub_origin_root_directory_sha1, + stub_origin_root_directory_entries) + + self.origin_directory_view_helper(stub_origin_info_no_type, stub_origin_visits, + stub_origin_snapshot[0], + stub_origin_snapshot[1], + stub_origin_master_branch, + stub_origin_root_directory_sha1, + stub_origin_root_directory_entries, + visit_id=stub_visit_id) + + self.origin_directory_view_helper(stub_origin_info_no_type, stub_origin_visits, + stub_origin_snapshot[0], + stub_origin_snapshot[1], + stub_origin_master_branch, + stub_origin_root_directory_sha1, + stub_origin_root_directory_entries, + timestamp=stub_visit_unix_ts) + + self.origin_directory_view_helper(stub_origin_info_no_type, stub_origin_visits, + stub_origin_snapshot[0], + stub_origin_snapshot[1], + stub_origin_master_branch, + stub_origin_root_directory_sha1, + stub_origin_root_directory_entries, + timestamp=stub_visit_iso_date) @patch('swh.web.browse.utils.get_origin_visits') @patch('swh.web.browse.utils.get_origin_visit_snapshot') @patch('swh.web.browse.utils.service') @patch('swh.web.browse.views.utils.snapshot_context.service') - @istest - def origin_sub_directory_view(self, mock_origin_service, + def test_origin_sub_directory_view(self, mock_origin_service, mock_utils_service, mock_get_origin_visit_snapshot, mock_get_origin_visits): @@ -518,75 +511,75 @@ 'type' : 'dir'} mock_utils_service.lookup_origin.return_value = stub_origin_info - self.origin_directory_view(stub_origin_info, stub_origin_visits, - stub_origin_snapshot[0], - stub_origin_snapshot[1], - stub_origin_master_branch, - stub_origin_root_directory_sha1, - stub_origin_sub_directory_entries, - path=stub_origin_sub_directory_path) - - self.origin_directory_view(stub_origin_info, stub_origin_visits, - stub_origin_snapshot[0], - stub_origin_snapshot[1], - stub_origin_master_branch, - stub_origin_root_directory_sha1, - stub_origin_sub_directory_entries, - visit_id=stub_visit_id, - path=stub_origin_sub_directory_path) - - self.origin_directory_view(stub_origin_info, stub_origin_visits, - stub_origin_snapshot[0], - stub_origin_snapshot[1], - stub_origin_master_branch, - stub_origin_root_directory_sha1, - stub_origin_sub_directory_entries, - timestamp=stub_visit_unix_ts, - path=stub_origin_sub_directory_path) - - self.origin_directory_view(stub_origin_info, stub_origin_visits, - stub_origin_snapshot[0], - stub_origin_snapshot[1], - stub_origin_master_branch, - stub_origin_root_directory_sha1, - stub_origin_sub_directory_entries, - timestamp=stub_visit_iso_date, - path=stub_origin_sub_directory_path) - - self.origin_directory_view(stub_origin_info_no_type, stub_origin_visits, - stub_origin_snapshot[0], - stub_origin_snapshot[1], - stub_origin_master_branch, - stub_origin_root_directory_sha1, - stub_origin_sub_directory_entries, - path=stub_origin_sub_directory_path) - - self.origin_directory_view(stub_origin_info_no_type, stub_origin_visits, - stub_origin_snapshot[0], - stub_origin_snapshot[1], - stub_origin_master_branch, - stub_origin_root_directory_sha1, - stub_origin_sub_directory_entries, - visit_id=stub_visit_id, - path=stub_origin_sub_directory_path) - - self.origin_directory_view(stub_origin_info_no_type, stub_origin_visits, - stub_origin_snapshot[0], - stub_origin_snapshot[1], - stub_origin_master_branch, - stub_origin_root_directory_sha1, - stub_origin_sub_directory_entries, - timestamp=stub_visit_unix_ts, - path=stub_origin_sub_directory_path) - - self.origin_directory_view(stub_origin_info_no_type, stub_origin_visits, - stub_origin_snapshot[0], - stub_origin_snapshot[1], - stub_origin_master_branch, - stub_origin_root_directory_sha1, - stub_origin_sub_directory_entries, - timestamp=stub_visit_iso_date, - path=stub_origin_sub_directory_path) + self.origin_directory_view_helper(stub_origin_info, stub_origin_visits, + stub_origin_snapshot[0], + stub_origin_snapshot[1], + stub_origin_master_branch, + stub_origin_root_directory_sha1, + stub_origin_sub_directory_entries, + path=stub_origin_sub_directory_path) + + self.origin_directory_view_helper(stub_origin_info, stub_origin_visits, + stub_origin_snapshot[0], + stub_origin_snapshot[1], + stub_origin_master_branch, + stub_origin_root_directory_sha1, + stub_origin_sub_directory_entries, + visit_id=stub_visit_id, + path=stub_origin_sub_directory_path) + + self.origin_directory_view_helper(stub_origin_info, stub_origin_visits, + stub_origin_snapshot[0], + stub_origin_snapshot[1], + stub_origin_master_branch, + stub_origin_root_directory_sha1, + stub_origin_sub_directory_entries, + timestamp=stub_visit_unix_ts, + path=stub_origin_sub_directory_path) + + self.origin_directory_view_helper(stub_origin_info, stub_origin_visits, + stub_origin_snapshot[0], + stub_origin_snapshot[1], + stub_origin_master_branch, + stub_origin_root_directory_sha1, + stub_origin_sub_directory_entries, + timestamp=stub_visit_iso_date, + path=stub_origin_sub_directory_path) + + self.origin_directory_view_helper(stub_origin_info_no_type, stub_origin_visits, + stub_origin_snapshot[0], + stub_origin_snapshot[1], + stub_origin_master_branch, + stub_origin_root_directory_sha1, + stub_origin_sub_directory_entries, + path=stub_origin_sub_directory_path) + + self.origin_directory_view_helper(stub_origin_info_no_type, stub_origin_visits, + stub_origin_snapshot[0], + stub_origin_snapshot[1], + stub_origin_master_branch, + stub_origin_root_directory_sha1, + stub_origin_sub_directory_entries, + visit_id=stub_visit_id, + path=stub_origin_sub_directory_path) + + self.origin_directory_view_helper(stub_origin_info_no_type, stub_origin_visits, + stub_origin_snapshot[0], + stub_origin_snapshot[1], + stub_origin_master_branch, + stub_origin_root_directory_sha1, + stub_origin_sub_directory_entries, + timestamp=stub_visit_unix_ts, + path=stub_origin_sub_directory_path) + + self.origin_directory_view_helper(stub_origin_info_no_type, stub_origin_visits, + stub_origin_snapshot[0], + stub_origin_snapshot[1], + stub_origin_master_branch, + stub_origin_root_directory_sha1, + stub_origin_sub_directory_entries, + timestamp=stub_visit_iso_date, + path=stub_origin_sub_directory_path) @patch('swh.web.browse.views.utils.snapshot_context.request_content') @patch('swh.web.browse.utils.get_origin_visits') @@ -595,8 +588,7 @@ @patch('swh.web.browse.views.origin.service') @patch('swh.web.browse.views.utils.snapshot_context.service') @patch('swh.web.browse.views.origin.get_origin_info') - @istest - def origin_request_errors(self, mock_get_origin_info, + def test_origin_request_errors(self, mock_get_origin_info, mock_snapshot_service, mock_origin_service, mock_utils_service, @@ -713,8 +705,7 @@ self.assertContains(resp, 'Content not found', status_code=404) - @nottest - def origin_branches_test(self, origin_info, origin_snapshot): + def origin_branches_helper(self, origin_info, origin_snapshot): url_args = {'origin_type': origin_info['type'], 'origin_url': origin_info['url']} @@ -764,8 +755,7 @@ @patch('swh.web.browse.utils.get_origin_visit_snapshot') @patch('swh.web.browse.utils.service') @patch('swh.web.browse.views.origin.service') - @istest - def origin_branches(self, mock_origin_service, + def test_origin_branches(self, mock_origin_service, mock_utils_service, mock_get_origin_visit_snapshot, mock_get_origin_visits): @@ -773,13 +763,12 @@ mock_get_origin_visit_snapshot.return_value = stub_origin_snapshot mock_utils_service.lookup_origin.return_value = stub_origin_info - self.origin_branches_test(stub_origin_info, stub_origin_snapshot) + self.origin_branches_helper(stub_origin_info, stub_origin_snapshot) - self.origin_branches_test(stub_origin_info_no_type, stub_origin_snapshot) + self.origin_branches_helper(stub_origin_info_no_type, stub_origin_snapshot) - @nottest - def origin_releases_test(self, origin_info, origin_snapshot): + def origin_releases_helper(self, origin_info, origin_snapshot): url_args = {'origin_type': origin_info['type'], 'origin_url': origin_info['url']} @@ -822,8 +811,7 @@ @patch('swh.web.browse.utils.get_origin_visit_snapshot') @patch('swh.web.browse.utils.service') @patch('swh.web.browse.views.origin.service') - @istest - def origin_releases(self, mock_origin_service, + def test_origin_releases(self, mock_origin_service, mock_utils_service, mock_get_origin_visit_snapshot, mock_get_origin_visits): @@ -831,6 +819,6 @@ mock_get_origin_visit_snapshot.return_value = stub_origin_snapshot mock_utils_service.lookup_origin.return_value = stub_origin_info - self.origin_releases_test(stub_origin_info, stub_origin_snapshot) - self.origin_releases_test(stub_origin_info_no_type, stub_origin_snapshot) + self.origin_releases_helper(stub_origin_info, stub_origin_snapshot) + self.origin_releases_helper(stub_origin_info_no_type, stub_origin_snapshot) diff --git a/swh/web/tests/browse/views/test_person.py b/swh/web/tests/browse/views/test_person.py --- a/swh/web/tests/browse/views/test_person.py +++ b/swh/web/tests/browse/views/test_person.py @@ -4,7 +4,6 @@ # See top-level LICENSE file for more information from unittest.mock import patch -from nose.tools import istest from swh.web.common.exc import NotFoundExc from swh.web.common.utils import reverse @@ -14,8 +13,7 @@ class SwhBrowsePersonTest(SWHWebTestCase): @patch('swh.web.browse.views.person.service') - @istest - def person_browse(self, mock_service): + def test_person_browse(self, mock_service): test_person_data = \ { "email": "j.adams440@gmail.com", @@ -43,8 +41,7 @@ test_person_data['email'])) @patch('swh.web.browse.views.person.service') - @istest - def person_request_error(self, mock_service): + def test_person_request_error(self, mock_service): mock_service.lookup_person.side_effect = \ NotFoundExc('Person not found') diff --git a/swh/web/tests/browse/views/test_release.py b/swh/web/tests/browse/views/test_release.py --- a/swh/web/tests/browse/views/test_release.py +++ b/swh/web/tests/browse/views/test_release.py @@ -6,7 +6,6 @@ # flake8: noqa from unittest.mock import patch -from nose.tools import istest from swh.web.common.exc import NotFoundExc from swh.web.common.utils import ( @@ -26,8 +25,7 @@ @patch('swh.web.browse.views.release.service') @patch('swh.web.browse.utils.service') @patch('swh.web.common.utils.service') - @istest - def release_browse(self, mock_service_common, mock_service_utils, + def test_release_browse(self, mock_service_common, mock_service_utils, mock_service): mock_service.lookup_release.return_value = stub_release diff --git a/swh/web/tests/browse/views/test_revision.py b/swh/web/tests/browse/views/test_revision.py --- a/swh/web/tests/browse/views/test_revision.py +++ b/swh/web/tests/browse/views/test_revision.py @@ -6,7 +6,6 @@ # flake8: noqa from unittest.mock import patch -from nose.tools import istest from django.utils.html import escape from swh.web.common.exc import NotFoundExc @@ -28,8 +27,7 @@ @patch('swh.web.browse.views.revision.service') @patch('swh.web.browse.utils.service') @patch('swh.web.common.utils.service') - @istest - def revision_browse(self, mock_service_common, mock_service_utils, + def test_revision_browse(self, mock_service_common, mock_service_utils, mock_service): mock_service.lookup_revision.return_value = revision_metadata_test @@ -135,8 +133,7 @@ self.assertContains(resp, swh_dir_id_url) @patch('swh.web.browse.views.revision.service') - @istest - def revision_log_browse(self, mock_service): + def test_revision_log_browse(self, mock_service): per_page = 10 mock_service.lookup_revision_log.return_value = \ @@ -242,8 +239,7 @@ @patch('swh.web.browse.utils.service') @patch('swh.web.browse.views.revision.service') - @istest - def revision_request_errors(self, mock_service, mock_utils_service): + def test_revision_request_errors(self, mock_service, mock_utils_service): mock_service.lookup_revision.side_effect = \ NotFoundExc('Revision not found') url = reverse('browse-revision', diff --git a/swh/web/tests/common/test_converters.py b/swh/web/tests/common/test_converters.py --- a/swh/web/tests/common/test_converters.py +++ b/swh/web/tests/common/test_converters.py @@ -5,7 +5,6 @@ import datetime -from nose.tools import istest from swh.model import hashutil @@ -15,8 +14,7 @@ class ConvertersTestCase(SWHWebTestCase): - @istest - def fmap(self): + def test_fmap(self): self.assertEquals([2, 3, None, 4], converters.fmap(lambda x: x+1, [1, 2, None, 3])) self.assertEquals([11, 12, 13], @@ -31,8 +29,7 @@ self.assertIsNone(converters.fmap(lambda x: x, None)) - @istest - def from_swh(self): + def test_from_swh(self): some_input = { 'a': 'something', 'b': 'someone', @@ -115,8 +112,7 @@ self.assertEquals(expected_output, actual_output) - @istest - def from_swh_edge_cases_do_no_conversion_if_none_or_not_bytes(self): + def test_from_swh_edge_cases_do_no_conversion_if_none_or_not_bytes(self): some_input = { 'a': 'something', 'b': None, @@ -140,8 +136,7 @@ self.assertEquals(expected_output, actual_output) - @istest - def from_swh_edge_cases_convert_invalid_utf8_bytes(self): + def test_from_swh_edge_cases_convert_invalid_utf8_bytes(self): some_input = { 'a': 'something', 'b': 'someone', @@ -167,18 +162,15 @@ for v in expected_output['decoding_failures']: self.assertTrue(v in actual_output['decoding_failures']) - @istest - def from_swh_empty(self): + def test_from_swh_empty(self): # when self.assertEquals({}, converters.from_swh({})) - @istest - def from_swh_none(self): + def test_from_swh_none(self): # when self.assertIsNone(converters.from_swh(None)) - @istest - def from_provenance(self): + def test_from_provenance(self): # given input_provenance = { 'origin': 10, @@ -204,8 +196,7 @@ # then self.assertEqual(actual_provenance, expected_provenance) - @istest - def from_origin(self): + def test_from_origin(self): # given origin_input = { 'id': 9, @@ -225,8 +216,7 @@ # then self.assertEqual(actual_origin, expected_origin) - @istest - def from_origin_visit(self): + def test_from_origin_visit(self): snap_hash = 'b5f0b7f716735ebffe38505c60145c4fd9da6ca3' for snap in [snap_hash, None]: @@ -261,8 +251,7 @@ # then self.assertEqual(actual_visit, expected_visit) - @istest - def from_release(self): + def test_from_release(self): release_input = { 'id': hashutil.hash_to_bytes( 'aad23fa492a0c5fed0708a6703be875448c86884'), @@ -308,8 +297,7 @@ # then self.assertEqual(actual_release, expected_release) - @istest - def from_release_no_revision(self): + def test_from_release_no_revision(self): release_input = { 'id': hashutil.hash_to_bytes( 'b2171ee2bdf119cd99a7ec7eff32fa8013ef9a4e'), @@ -352,8 +340,7 @@ # then self.assertEqual(actual_release, expected_release) - @istest - def from_revision(self): + def test_from_revision(self): revision_input = { 'id': hashutil.hash_to_bytes( '18d8be353ed3480476f032475e7c233eff7371d5'), @@ -455,8 +442,7 @@ # then self.assertEqual(actual_revision, expected_revision) - @istest - def from_revision_nomerge(self): + def test_from_revision_nomerge(self): revision_input = { 'id': hashutil.hash_to_bytes( '18d8be353ed3480476f032475e7c233eff7371d5'), @@ -480,8 +466,7 @@ # then self.assertEqual(actual_revision, expected_revision) - @istest - def from_revision_noparents(self): + def test_from_revision_noparents(self): revision_input = { 'id': hashutil.hash_to_bytes( '18d8be353ed3480476f032475e7c233eff7371d5'), @@ -570,8 +555,7 @@ # then self.assertEqual(actual_revision, expected_revision) - @istest - def from_revision_invalid(self): + def test_from_revision_invalid(self): revision_input = { 'id': hashutil.hash_to_bytes( '18d8be353ed3480476f032475e7c233eff7371d5'), @@ -672,12 +656,10 @@ # then self.assertEqual(actual_revision, expected_revision) - @istest - def from_content_none(self): + def test_from_content_none(self): self.assertIsNone(converters.from_content(None)) - @istest - def from_content(self): + def test_from_content(self): content_input = { 'sha1': hashutil.hash_to_bytes( '5c6f0e2750f48fa0bd0c4cf5976ba0b9e02ebda5'), @@ -716,8 +698,7 @@ # then self.assertEqual(actual_content, expected_content) - @istest - def from_person(self): + def test_from_person(self): person_input = { 'id': 10, 'anything': 'else', @@ -740,8 +721,7 @@ # then self.assertEqual(actual_person, expected_person) - @istest - def from_directory_entries(self): + def test_from_directory_entries(self): dir_entries_input = { 'sha1': hashutil.hash_to_bytes( '5c6f0e2750f48fa0bd0c4cf5976ba0b9e02ebda5'), @@ -784,8 +764,7 @@ # then self.assertEqual(actual_dir_entries, expected_dir_entries) - @istest - def from_filetype(self): + def test_from_filetype(self): content_filetype = { 'id': hashutil.hash_to_bytes( '5c6f0e2750f48fa0bd0c4cf5976ba0b9e02ebda5'), diff --git a/swh/web/tests/common/test_highlightjs.py b/swh/web/tests/common/test_highlightjs.py --- a/swh/web/tests/common/test_highlightjs.py +++ b/swh/web/tests/common/test_highlightjs.py @@ -3,7 +3,6 @@ # License: GNU Affero General Public License version 3, or any later version # See top-level LICENSE file for more information -from nose.tools import istest from swh.web.common import highlightjs from swh.web.tests.testcase import SWHWebTestCase @@ -11,8 +10,7 @@ class HighlightJsTestCase(SWHWebTestCase): - @istest - def get_hljs_language_from_mime_type(self): + def test_get_hljs_language_from_mime_type(self): lang = highlightjs.get_hljs_language_from_mime_type('text/plain') self.assertEquals(lang, None) @@ -50,8 +48,7 @@ lang = highlightjs.get_hljs_language_from_mime_type('image/png') self.assertEquals(lang, None) - @istest - def get_hljs_language_from_filename(self): + def test_get_hljs_language_from_filename(self): lang = highlightjs.get_hljs_language_from_filename('foo') self.assertEquals(lang, None) diff --git a/swh/web/tests/common/test_query.py b/swh/web/tests/common/test_query.py --- a/swh/web/tests/common/test_query.py +++ b/swh/web/tests/common/test_query.py @@ -4,7 +4,6 @@ # See top-level LICENSE file for more information from unittest.mock import patch -from nose.tools import istest from swh.model import hashutil @@ -14,70 +13,58 @@ class QueryTestCase(SWHWebTestCase): - @istest - def parse_hash_malformed_query_with_more_than_2_parts(self): + def test_parse_hash_malformed_query_with_more_than_2_parts(self): with self.assertRaises(BadInputExc): query.parse_hash('sha1:1234567890987654:other-stuff') - @istest - def parse_hash_guess_sha1(self): + def test_parse_hash_guess_sha1(self): h = 'f1d2d2f924e986ac86fdf7b36c94bcdf32beec15' r = query.parse_hash(h) self.assertEquals(r, ('sha1', hashutil.hash_to_bytes(h))) - @istest - def parse_hash_guess_sha256(self): + def test_parse_hash_guess_sha256(self): h = '084C799CD551DD1D8D5C5F9A5D593B2' \ 'E931F5E36122ee5c793c1d08a19839cc0' r = query.parse_hash(h) self.assertEquals(r, ('sha256', hashutil.hash_to_bytes(h))) - @istest - def parse_hash_guess_algo_malformed_hash(self): + def test_parse_hash_guess_algo_malformed_hash(self): with self.assertRaises(BadInputExc): query.parse_hash('1234567890987654') - @istest - def parse_hash_check_sha1(self): + def test_parse_hash_check_sha1(self): h = 'f1d2d2f924e986ac86fdf7b36c94bcdf32beec15' r = query.parse_hash('sha1:' + h) self.assertEquals(r, ('sha1', hashutil.hash_to_bytes(h))) - @istest - def parse_hash_check_sha1_git(self): + def test_parse_hash_check_sha1_git(self): h = 'e1d2d2f924e986ac86fdf7b36c94bcdf32beec15' r = query.parse_hash('sha1_git:' + h) self.assertEquals(r, ('sha1_git', hashutil.hash_to_bytes(h))) - @istest - def parse_hash_check_sha256(self): + def test_parse_hash_check_sha256(self): h = '084C799CD551DD1D8D5C5F9A5D593B2E931F5E36122ee5c793c1d08a19839cc0' r = query.parse_hash('sha256:' + h) self.assertEquals(r, ('sha256', hashutil.hash_to_bytes(h))) - @istest - def parse_hash_check_algo_malformed_sha1_hash(self): + def test_parse_hash_check_algo_malformed_sha1_hash(self): with self.assertRaises(BadInputExc): query.parse_hash('sha1:1234567890987654') - @istest - def parse_hash_check_algo_malformed_sha1_git_hash(self): + def test_parse_hash_check_algo_malformed_sha1_git_hash(self): with self.assertRaises(BadInputExc): query.parse_hash('sha1_git:1234567890987654') - @istest - def parse_hash_check_algo_malformed_sha256_hash(self): + def test_parse_hash_check_algo_malformed_sha256_hash(self): with self.assertRaises(BadInputExc): query.parse_hash('sha256:1234567890987654') - @istest - def parse_hash_check_algo_unknown_one(self): + def test_parse_hash_check_algo_unknown_one(self): with self.assertRaises(BadInputExc): query.parse_hash('sha2:1234567890987654') @patch('swh.web.common.query.parse_hash') - @istest - def parse_hash_with_algorithms_or_throws_bad_query(self, mock_hash): + def test_parse_hash_with_algorithms_or_throws_bad_query(self, mock_hash): # given mock_hash.side_effect = BadInputExc('Error input') @@ -92,8 +79,7 @@ mock_hash.assert_called_once_with('sha1:blah') @patch('swh.web.common.query.parse_hash') - @istest - def parse_hash_with_algorithms_or_throws_bad_algo(self, mock_hash): + def test_parse_hash_with_algorithms_or_throws_bad_algo(self, mock_hash): # given mock_hash.return_value = 'sha1', '123' @@ -108,8 +94,7 @@ mock_hash.assert_called_once_with('sha1:431') @patch('swh.web.common.query.parse_hash') - @istest - def parse_hash_with_algorithms(self, mock_hash): + def test_parse_hash_with_algorithms(self, mock_hash): # given mock_hash.return_value = ('sha256', b'123') @@ -124,16 +109,14 @@ mock_hash.assert_called_once_with('sha256:123') - @istest - def parse_uuid4(self): + def test_parse_uuid4(self): # when actual_uuid = query.parse_uuid4('7c33636b-8f11-4bda-89d9-ba8b76a42cec') # then self.assertEquals(actual_uuid, '7c33636b-8f11-4bda-89d9-ba8b76a42cec') - @istest - def parse_uuid4_ko(self): + def test_parse_uuid4_ko(self): # when with self.assertRaises(BadInputExc) as cm: query.parse_uuid4('7c33636b-8f11-4bda-89d9-ba8b76a42') diff --git a/swh/web/tests/common/test_service.py b/swh/web/tests/common/test_service.py --- a/swh/web/tests/common/test_service.py +++ b/swh/web/tests/common/test_service.py @@ -5,7 +5,6 @@ import datetime -from nose.tools import istest from unittest.mock import MagicMock, patch, call from swh.model.hashutil import hash_to_bytes, hash_to_hex @@ -116,8 +115,7 @@ } @patch('swh.web.common.service.storage') - @istest - def lookup_multiple_hashes_ball_missing(self, mock_storage): + def test_lookup_multiple_hashes_ball_missing(self, mock_storage): # given mock_storage.content_missing_per_sha1 = MagicMock(return_value=[]) @@ -139,8 +137,7 @@ ]) @patch('swh.web.common.service.storage') - @istest - def lookup_multiple_hashes_some_missing(self, mock_storage): + def test_lookup_multiple_hashes_some_missing(self, mock_storage): # given mock_storage.content_missing_per_sha1 = MagicMock(return_value=[ hash_to_bytes('456caf10e9535160d90e874b45aa426de762f19f') @@ -164,8 +161,7 @@ ]) @patch('swh.web.common.service.storage') - @istest - def lookup_hash_does_not_exist(self, mock_storage): + def test_lookup_hash_does_not_exist(self, mock_storage): # given mock_storage.content_find = MagicMock(return_value=None) @@ -183,8 +179,7 @@ hash_to_bytes('123caf10e9535160d90e874b45aa426de762f19f')}) @patch('swh.web.common.service.storage') - @istest - def lookup_hash_exist(self, mock_storage): + def test_lookup_hash_exist(self, mock_storage): # given stub_content = { 'sha1': hash_to_bytes( @@ -206,8 +201,7 @@ ) @patch('swh.web.common.service.storage') - @istest - def search_hash_does_not_exist(self, mock_storage): + def test_search_hash_does_not_exist(self, mock_storage): # given mock_storage.content_find = MagicMock(return_value=None) @@ -224,8 +218,7 @@ hash_to_bytes('123caf10e9535160d90e874b45aa426de762f19f')}) @patch('swh.web.common.service.storage') - @istest - def search_hash_exist(self, mock_storage): + def test_search_hash_exist(self, mock_storage): # given stub_content = { 'sha1': hash_to_bytes( @@ -246,8 +239,7 @@ ) @patch('swh.web.common.service.idx_storage') - @istest - def lookup_content_ctags(self, mock_idx_storage): + def test_lookup_content_ctags(self, mock_idx_storage): # given mock_idx_storage.content_ctags_get = MagicMock( return_value=[{ @@ -279,8 +271,7 @@ [hash_to_bytes('123caf10e9535160d90e874b45aa426de762f19f')]) @patch('swh.web.common.service.idx_storage') - @istest - def lookup_content_ctags_no_hash(self, mock_idx_storage): + def test_lookup_content_ctags_no_hash(self, mock_idx_storage): # given mock_idx_storage.content_ctags_get = MagicMock(return_value=[]) @@ -292,8 +283,7 @@ self.assertEqual(actual_ctags, []) @patch('swh.web.common.service.idx_storage') - @istest - def lookup_content_filetype(self, mock_idx_storage): + def test_lookup_content_filetype(self, mock_idx_storage): # given mock_idx_storage.content_mimetype_get = MagicMock( return_value=[{ @@ -320,8 +310,7 @@ @patch('swh.web.common.service.idx_storage') @patch('swh.web.common.service.storage') - @istest - def lookup_content_filetype_2(self, mock_storage, mock_idx_storage): + def test_lookup_content_filetype_2(self, mock_storage, mock_idx_storage): # given mock_storage.content_find = MagicMock( return_value={ @@ -358,8 +347,7 @@ [hash_to_bytes('123caf10e9535160d90e874b45aa426de762f19f')]) @patch('swh.web.common.service.idx_storage') - @istest - def lookup_content_language(self, mock_idx_storage): + def test_lookup_content_language(self, mock_idx_storage): # given mock_idx_storage.content_language_get = MagicMock( return_value=[{ @@ -384,8 +372,7 @@ @patch('swh.web.common.service.idx_storage') @patch('swh.web.common.service.storage') - @istest - def lookup_content_language_2(self, mock_storage, mock_idx_storage): + def test_lookup_content_language_2(self, mock_storage, mock_idx_storage): # given mock_storage.content_find = MagicMock( return_value={ @@ -420,8 +407,7 @@ [hash_to_bytes('123caf10e9535160d90e874b45aa426de762f19f')]) @patch('swh.web.common.service.idx_storage') - @istest - def lookup_expression(self, mock_idx_storage): + def test_lookup_expression(self, mock_idx_storage): # given mock_idx_storage.content_ctags_search = MagicMock( return_value=[{ @@ -451,8 +437,7 @@ 'foobar', last_sha1='hash', limit=10) @patch('swh.web.common.service.idx_storage') - @istest - def lookup_expression_no_result(self, mock_idx_storage): + def test_lookup_expression_no_result(self, mock_idx_storage): # given mock_idx_storage.content_ctags_search = MagicMock( return_value=[]) @@ -469,8 +454,7 @@ 'barfoo', last_sha1='hash', limit=10) @patch('swh.web.common.service.idx_storage') - @istest - def lookup_content_license(self, mock_idx_storage): + def test_lookup_content_license(self, mock_idx_storage): # given mock_idx_storage.content_fossology_license_get = MagicMock( return_value=[{ @@ -499,8 +483,7 @@ @patch('swh.web.common.service.idx_storage') @patch('swh.web.common.service.storage') - @istest - def lookup_content_license_2(self, mock_storage, mock_idx_storage): + def test_lookup_content_license_2(self, mock_storage, mock_idx_storage): # given mock_storage.content_find = MagicMock( return_value={ @@ -540,8 +523,7 @@ [hash_to_bytes('123caf10e9535160d90e874b45aa426de762f19f')]) @patch('swh.web.common.service.storage') - @istest - def lookup_content_provenance(self, mock_storage): + def test_lookup_content_provenance(self, mock_storage): # given mock_storage.content_find_provenance = MagicMock( return_value=(p for p in [{ @@ -573,8 +555,7 @@ hash_to_bytes('123caf10e9535160d90e874b45aa426de762f19f')}) @patch('swh.web.common.service.storage') - @istest - def lookup_content_provenance_not_found(self, mock_storage): + def test_lookup_content_provenance_not_found(self, mock_storage): # given mock_storage.content_find_provenance = MagicMock(return_value=None) @@ -590,8 +571,7 @@ hash_to_bytes('456caf10e9535160d90e874b45aa426de762f19f')}) @patch('swh.web.common.service.storage') - @istest - def stat_counters(self, mock_storage): + def test_stat_counters(self, mock_storage): # given input_stats = { "content": 1770830, @@ -620,8 +600,7 @@ mock_storage.stat_counters.assert_called_with() @patch('swh.web.common.service._lookup_origin_visits') - @istest - def lookup_origin_visits(self, mock_lookup_visits): + def test_lookup_origin_visits(self, mock_lookup_visits): # given date_origin_visit2 = datetime.datetime( 2013, 7, 1, 20, 0, 0, @@ -674,8 +653,7 @@ 6, last_visit=None, limit=10) @patch('swh.web.common.service.storage') - @istest - def lookup_origin_visit(self, mock_storage): + def test_lookup_origin_visit(self, mock_storage): # given stub_result = self.origin_visit1 mock_storage.origin_visit_get_by.return_value = stub_result @@ -695,8 +673,7 @@ mock_storage.origin_visit_get_by.assert_called_once_with(1, 1) @patch('swh.web.common.service.storage') - @istest - def lookup_origin(self, mock_storage): + def test_lookup_origin(self, mock_storage): # given mock_storage.origin_get = MagicMock(return_value={ 'id': 'origin-id', @@ -714,9 +691,7 @@ mock_storage.origin_get.assert_called_with({'id': 'origin-id'}) @patch('swh.web.common.service.storage') - @istest - def lookup_release_ko_id_checksum_not_ok_because_not_a_sha1(self, - mock_storage): + def test_lookup_release_ko_id_checksum_not_a_sha1(self, mock_storage): # given mock_storage.release_get = MagicMock() @@ -728,8 +703,7 @@ mock_storage.release_get.called = False @patch('swh.web.common.service.storage') - @istest - def lookup_release_ko_id_checksum_ok_but_not_a_sha1(self, mock_storage): + def test_lookup_release_ko_id_checksum_too_long(self, mock_storage): # given mock_storage.release_get = MagicMock() @@ -743,8 +717,7 @@ mock_storage.release_get.called = False @patch('swh.web.common.service.storage') - @istest - def lookup_directory_with_path_not_found(self, mock_storage): + def test_lookup_directory_with_path_not_found(self, mock_storage): # given mock_storage.lookup_directory_with_path = MagicMock(return_value=None) @@ -757,8 +730,7 @@ self.assertIsNone(actual_directory) @patch('swh.web.common.service.storage') - @istest - def lookup_directory_with_path_found(self, mock_storage): + def test_lookup_directory_with_path_found(self, mock_storage): # given sha1_git = '65a55bbdf3629f916219feb3dcc7393ded1bc8db' entry = {'id': 'dir-id', @@ -774,8 +746,7 @@ self.assertEqual(entry, actual_directory) @patch('swh.web.common.service.storage') - @istest - def lookup_release(self, mock_storage): + def test_lookup_release(self, mock_storage): # given mock_storage.release_get = MagicMock(return_value=[{ 'id': hash_to_bytes('65a55bbdf3629f916219feb3dcc7393ded1bc8db'), @@ -809,8 +780,7 @@ mock_storage.release_get.assert_called_with( [hash_to_bytes('65a55bbdf3629f916219feb3dcc7393ded1bc8db')]) - @istest - def lookup_revision_with_context_ko_not_a_sha1_1(self): + def test_lookup_revision_with_context_ko_not_a_sha1_1(self): # given sha1_git = '13c1d34d138ec13b5ebad226dc2528dc7506c956e4646f62d4' \ 'daf51aea892abe' @@ -821,8 +791,7 @@ service.lookup_revision_with_context(sha1_git_root, sha1_git) self.assertIn('Only sha1_git is supported', cm.exception.args[0]) - @istest - def lookup_revision_with_context_ko_not_a_sha1_2(self): + def test_lookup_revision_with_context_ko_not_a_sha1_2(self): # given sha1_git_root = '65a55bbdf3629f916219feb3dcc7393ded1bc8db' sha1_git = '13c1d34d138ec13b5ebad226dc2528dc7506c956e4646f6' \ @@ -834,8 +803,7 @@ self.assertIn('Only sha1_git is supported', cm.exception.args[0]) @patch('swh.web.common.service.storage') - @istest - def lookup_revision_with_context_ko_sha1_git_does_not_exist( + def test_lookup_revision_with_context_ko_sha1_git_does_not_exist( self, mock_storage): # given @@ -856,8 +824,7 @@ [sha1_git_bin]) @patch('swh.web.common.service.storage') - @istest - def lookup_revision_with_context_ko_root_sha1_git_does_not_exist( + def test_lookup_revision_with_context_ko_root_sha1_git_does_not_exist( self, mock_storage): # given @@ -880,8 +847,7 @@ @patch('swh.web.common.service.storage') @patch('swh.web.common.service.query') - @istest - def lookup_revision_with_context(self, mock_query, mock_storage): + def test_lookup_revision_with_context(self, mock_query, mock_storage): # given sha1_git_root = '666' sha1_git = '883' @@ -959,8 +925,7 @@ @patch('swh.web.common.service.storage') @patch('swh.web.common.service.query') - @istest - def lookup_revision_with_context_sha1_git_root_already_retrieved_as_dict( + def test_lookup_revision_with_context_retrieved_as_dict( self, mock_query, mock_storage): # given sha1_git = '883' @@ -1033,10 +998,9 @@ @patch('swh.web.common.service.storage') @patch('swh.web.common.service.query') - @istest - def lookup_directory_with_revision_ko_revision_not_found(self, - mock_query, - mock_storage): + def test_lookup_directory_with_revision_not_found(self, + mock_query, + mock_storage): # given mock_query.parse_hash_with_algorithms_or_throws.return_value = ('sha1', b'123') @@ -1053,8 +1017,7 @@ @patch('swh.web.common.service.storage') @patch('swh.web.common.service.query') - @istest - def lookup_directory_with_revision_ko_revision_with_path_to_nowhere( + def test_lookup_directory_with_revision_ko_revision_with_path_to_nowhere( self, mock_query, mock_storage): @@ -1088,8 +1051,7 @@ @patch('swh.web.common.service.storage') @patch('swh.web.common.service.query') - @istest - def lookup_directory_with_revision_ko_type_not_implemented( + def test_lookup_directory_with_revision_ko_type_not_implemented( self, mock_query, mock_storage): @@ -1133,10 +1095,9 @@ @patch('swh.web.common.service.storage') @patch('swh.web.common.service.query') - @istest - def lookup_directory_with_revision_revision_without_path(self, - mock_query, - mock_storage): + def test_lookup_directory_with_revision_revision_without_path( + self, mock_query, mock_storage, + ): # given mock_query.parse_hash_with_algorithms_or_throws.return_value = ('sha1', b'123') @@ -1171,10 +1132,9 @@ @patch('swh.web.common.service.storage') @patch('swh.web.common.service.query') - @istest - def lookup_directory_with_revision_revision_with_path_to_dir(self, - mock_query, - mock_storage): + def test_lookup_directory_with_revision_with_path_to_dir(self, + mock_query, + mock_storage): # given mock_query.parse_hash_with_algorithms_or_throws.return_value = ('sha1', b'123') @@ -1220,8 +1180,7 @@ @patch('swh.web.common.service.storage') @patch('swh.web.common.service.query') - @istest - def lookup_directory_with_revision_revision_with_path_to_file_without_data( + def test_lookup_directory_with_revision_with_path_to_file_wo_data( self, mock_query, mock_storage): @@ -1267,8 +1226,7 @@ @patch('swh.web.common.service.storage') @patch('swh.web.common.service.query') - @istest - def lookup_directory_with_revision_revision_with_path_to_file_with_data( + def test_lookup_directory_with_revision_with_path_to_file_w_data( self, mock_query, mock_storage): @@ -1328,8 +1286,7 @@ mock_storage.content_get.assert_called_once_with([b'content-sha1']) @patch('swh.web.common.service.storage') - @istest - def lookup_revision(self, mock_storage): + def test_lookup_revision(self, mock_storage): # given mock_storage.revision_get = MagicMock( return_value=[self.SAMPLE_REVISION_RAW]) @@ -1345,8 +1302,7 @@ [self.SHA1_SAMPLE_BIN]) @patch('swh.web.common.service.storage') - @istest - def lookup_revision_invalid_msg(self, mock_storage): + def test_lookup_revision_invalid_msg(self, mock_storage): # given stub_rev = self.SAMPLE_REVISION_RAW stub_rev['message'] = b'elegant fix for bug \xff' @@ -1367,8 +1323,7 @@ [self.SHA1_SAMPLE_BIN]) @patch('swh.web.common.service.storage') - @istest - def lookup_revision_msg_ok(self, mock_storage): + def test_lookup_revision_msg_ok(self, mock_storage): # given mock_storage.revision_get.return_value = [self.SAMPLE_REVISION_RAW] @@ -1382,8 +1337,7 @@ [self.SHA1_SAMPLE_BIN]) @patch('swh.web.common.service.storage') - @istest - def lookup_revision_msg_absent(self, mock_storage): + def test_lookup_revision_msg_absent(self, mock_storage): # given stub_revision = self.SAMPLE_REVISION_RAW del stub_revision['message'] @@ -1403,8 +1357,7 @@ ) @patch('swh.web.common.service.storage') - @istest - def lookup_revision_msg_norev(self, mock_storage): + def test_lookup_revision_msg_norev(self, mock_storage): # given mock_storage.revision_get.return_value = None @@ -1422,8 +1375,7 @@ ) @patch('swh.web.common.service.storage') - @istest - def lookup_revision_multiple(self, mock_storage): + def test_lookup_revision_multiple(self, mock_storage): # given sha1 = self.SHA1_SAMPLE sha1_other = 'adc83b19e793491b1c6ea0fd8b46cd9f32e592fc' @@ -1504,8 +1456,7 @@ hash_to_bytes(sha1_other)]) @patch('swh.web.common.service.storage') - @istest - def lookup_revision_multiple_none_found(self, mock_storage): + def test_lookup_revision_multiple_none_found(self, mock_storage): # given sha1_bin = self.SHA1_SAMPLE sha1_other = 'adc83b19e793491b1c6ea0fd8b46cd9f32e592fc' @@ -1524,8 +1475,7 @@ hash_to_bytes(sha1_other)]) @patch('swh.web.common.service.storage') - @istest - def lookup_revision_log(self, mock_storage): + def test_lookup_revision_log(self, mock_storage): # given stub_revision_log = [self.SAMPLE_REVISION_RAW] mock_storage.revision_log = MagicMock(return_value=stub_revision_log) @@ -1542,8 +1492,7 @@ [hash_to_bytes('abcdbe353ed3480476f032475e7c233eff7371d5')], 25) @patch('swh.web.common.service.storage') - @istest - def lookup_revision_log_by(self, mock_storage): + def test_lookup_revision_log_by(self, mock_storage): # given stub_revision_log = [self.SAMPLE_REVISION_RAW] mock_storage.revision_log_by = MagicMock( @@ -1559,8 +1508,7 @@ 1, 'refs/heads/master', None, limit=100) @patch('swh.web.common.service.storage') - @istest - def lookup_revision_log_by_nolog(self, mock_storage): + def test_lookup_revision_log_by_nolog(self, mock_storage): # given mock_storage.revision_log_by = MagicMock(return_value=None) @@ -1573,8 +1521,7 @@ 1, 'refs/heads/master', None, limit=100) @patch('swh.web.common.service.storage') - @istest - def lookup_content_raw_not_found(self, mock_storage): + def test_lookup_content_raw_not_found(self, mock_storage): # given mock_storage.content_find = MagicMock(return_value=None) @@ -1589,8 +1536,7 @@ {'sha1': hash_to_bytes(self.SHA1_SAMPLE)}) @patch('swh.web.common.service.storage') - @istest - def lookup_content_raw(self, mock_storage): + def test_lookup_content_raw(self, mock_storage): # given mock_storage.content_find = MagicMock(return_value={ 'sha1': self.SHA1_SAMPLE, @@ -1611,8 +1557,7 @@ [self.SHA1_SAMPLE]) @patch('swh.web.common.service.storage') - @istest - def lookup_content_not_found(self, mock_storage): + def test_lookup_content_not_found(self, mock_storage): # given mock_storage.content_find = MagicMock(return_value=None) @@ -1628,8 +1573,7 @@ {'sha1': self.SHA1_SAMPLE_BIN}) @patch('swh.web.common.service.storage') - @istest - def lookup_content_with_sha1(self, mock_storage): + def test_lookup_content_with_sha1(self, mock_storage): # given mock_storage.content_find = MagicMock( return_value=self.SAMPLE_CONTENT_RAW) @@ -1645,8 +1589,7 @@ {'sha1': hash_to_bytes(self.SHA1_SAMPLE)}) @patch('swh.web.common.service.storage') - @istest - def lookup_content_with_sha256(self, mock_storage): + def test_lookup_content_with_sha256(self, mock_storage): # given stub_content = self.SAMPLE_CONTENT_RAW stub_content['status'] = 'visible' @@ -1667,8 +1610,7 @@ {'sha256': self.SHA256_SAMPLE_BIN}) @patch('swh.web.common.service.storage') - @istest - def lookup_person(self, mock_storage): + def test_lookup_person(self, mock_storage): # given mock_storage.person_get = MagicMock(return_value=[{ 'id': 'person_id', @@ -1689,8 +1631,7 @@ mock_storage.person_get.assert_called_with(['person_id']) @patch('swh.web.common.service.storage') - @istest - def lookup_directory_bad_checksum(self, mock_storage): + def test_lookup_directory_bad_checksum(self, mock_storage): # given mock_storage.directory_ls = MagicMock() @@ -1703,8 +1644,7 @@ @patch('swh.web.common.service.storage') @patch('swh.web.common.service.query') - @istest - def lookup_directory_not_found(self, mock_query, mock_storage): + def test_lookup_directory_not_found(self, mock_query, mock_storage): # given mock_query.parse_hash_with_algorithms_or_throws.return_value = ( 'sha1', @@ -1725,8 +1665,7 @@ @patch('swh.web.common.service.storage') @patch('swh.web.common.service.query') - @istest - def lookup_directory(self, mock_query, mock_storage): + def test_lookup_directory(self, mock_query, mock_storage): mock_query.parse_hash_with_algorithms_or_throws.return_value = ( 'sha1', 'directory-sha1-bin') @@ -1772,8 +1711,7 @@ 'directory-sha1-bin') @patch('swh.web.common.service.storage') - @istest - def lookup_directory_empty(self, mock_storage): + def test_lookup_directory_empty(self, mock_storage): empty_dir_sha1 = '4b825dc642cb6eb9a060e54bf8d69288fbee4904' mock_storage.directory_ls.return_value = [] @@ -1786,8 +1724,7 @@ self.assertFalse(mock_storage.directory_ls.called) @patch('swh.web.common.service.storage') - @istest - def lookup_revision_by_nothing_found(self, mock_storage): + def test_lookup_revision_by_nothing_found(self, mock_storage): # given mock_storage.revision_get_by.return_value = None @@ -1801,8 +1738,7 @@ timestamp=None) @patch('swh.web.common.service.storage') - @istest - def lookup_revision_by(self, mock_storage): + def test_lookup_revision_by(self, mock_storage): # given stub_rev = self.SAMPLE_REVISION_RAW @@ -1821,8 +1757,7 @@ timestamp='some-ts') @patch('swh.web.common.service.storage') - @istest - def lookup_revision_by_nomerge(self, mock_storage): + def test_lookup_revision_by_nomerge(self, mock_storage): # given stub_rev = self.SAMPLE_REVISION_RAW stub_rev['parents'] = [ @@ -1843,8 +1778,7 @@ timestamp='some-ts') @patch('swh.web.common.service.storage') - @istest - def lookup_revision_by_merge(self, mock_storage): + def test_lookup_revision_by_merge(self, mock_storage): # given stub_rev = self.SAMPLE_REVISION_RAW stub_rev['parents'] = [ @@ -1872,8 +1806,7 @@ timestamp='some-ts') @patch('swh.web.common.service.storage') - @istest - def lookup_revision_with_context_by_ko(self, mock_storage): + def test_lookup_revision_with_context_by_ko(self, mock_storage): # given mock_storage.revision_get_by.return_value = None @@ -1896,9 +1829,9 @@ @patch('swh.web.common.service.lookup_revision_with_context') @patch('swh.web.common.service.storage') - @istest - def lookup_revision_with_context_by(self, mock_storage, - mock_lookup_revision_with_context): + def test_lookup_revision_with_context_by( + self, mock_storage, mock_lookup_revision_with_context, + ): # given stub_root_rev = {'id': 'root-rev-id'} mock_storage.revision_get_by.return_value = [{'id': 'root-rev-id'}] @@ -1924,8 +1857,7 @@ @patch('swh.web.common.service.storage') @patch('swh.web.common.service.query') - @istest - def lookup_entity_by_uuid(self, mock_query, mock_storage): + def test_lookup_entity_by_uuid(self, mock_query, mock_storage): # given uuid_test = 'correct-uuid' mock_query.parse_uuid4.return_value = uuid_test @@ -1942,8 +1874,7 @@ mock_query.parse_uuid4.assert_called_once_with(uuid_test) mock_storage.entity_get.assert_called_once_with(uuid_test) - @istest - def lookup_revision_through_ko_not_implemented(self): + def test_lookup_revision_through_ko_not_implemented(self): # then with self.assertRaises(NotImplementedError): service.lookup_revision_through({ @@ -1951,8 +1882,7 @@ }) @patch('swh.web.common.service.lookup_revision_with_context_by') - @istest - def lookup_revision_through_with_context_by(self, mock_lookup): + def test_lookup_revision_through_with_context_by(self, mock_lookup): # given stub_rev = {'id': 'rev'} mock_lookup.return_value = stub_rev @@ -1972,8 +1902,7 @@ 1, 'master', None, 'sha1-git', 1000) @patch('swh.web.common.service.lookup_revision_by') - @istest - def lookup_revision_through_with_revision_by(self, mock_lookup): + def test_lookup_revision_through_with_revision_by(self, mock_lookup): # given stub_rev = {'id': 'rev'} mock_lookup.return_value = stub_rev @@ -1992,8 +1921,7 @@ 2, 'master2', 'some-ts') @patch('swh.web.common.service.lookup_revision_with_context') - @istest - def lookup_revision_through_with_context(self, mock_lookup): + def test_lookup_revision_through_with_context(self, mock_lookup): # given stub_rev = {'id': 'rev'} mock_lookup.return_value = stub_rev @@ -2011,8 +1939,7 @@ 'some-sha1-root', 'some-sha1', 100) @patch('swh.web.common.service.lookup_revision') - @istest - def lookup_revision_through_with_revision(self, mock_lookup): + def test_lookup_revision_through_with_revision(self, mock_lookup): # given stub_rev = {'id': 'rev'} mock_lookup.return_value = stub_rev @@ -2029,8 +1956,7 @@ 'some-sha1') @patch('swh.web.common.service.lookup_revision_through') - @istest - def lookup_directory_through_revision_ko_not_found( + def test_lookup_directory_through_revision_ko_not_found( self, mock_lookup_rev): # given mock_lookup_rev.return_value = None @@ -2044,8 +1970,7 @@ @patch('swh.web.common.service.lookup_revision_through') @patch('swh.web.common.service.lookup_directory_with_revision') - @istest - def lookup_directory_through_revision_ok_with_data( + def test_lookup_directory_through_revision_ok_with_data( self, mock_lookup_dir, mock_lookup_rev): # given mock_lookup_rev.return_value = {'id': 'rev-id'} @@ -2065,8 +1990,7 @@ @patch('swh.web.common.service.lookup_revision_through') @patch('swh.web.common.service.lookup_directory_with_revision') - @istest - def lookup_directory_through_revision_ok_with_content( + def test_lookup_directory_through_revision_ok_with_content( self, mock_lookup_dir, mock_lookup_rev): # given mock_lookup_rev.return_value = {'id': 'rev-id'} diff --git a/swh/web/tests/common/test_templatetags.py b/swh/web/tests/common/test_templatetags.py --- a/swh/web/tests/common/test_templatetags.py +++ b/swh/web/tests/common/test_templatetags.py @@ -3,15 +3,13 @@ # License: GNU Affero General Public License version 3, or any later version # See top-level LICENSE file for more information -from nose.tools import istest from swh.web.common import swh_templatetags from swh.web.tests.testcase import SWHWebTestCase class SWHTemplateTagsTest(SWHWebTestCase): - @istest - def urlize_api_links_api(self): + def test_urlize_api_links_api(self): # update api link with html links content with links content = '{"url": "/api/1/abc/"}' expected_content = ('{"url": "/api/1/abc/"}') @@ -19,8 +17,7 @@ self.assertEquals(swh_templatetags.urlize_links_and_mails(content), expected_content) - @istest - def urlize_api_links_browse(self): + def test_urlize_api_links_browse(self): # update /browse link with html links content with links content = '{"url": "/browse/def/"}' expected_content = ('{"url": "' @@ -28,8 +25,7 @@ self.assertEquals(swh_templatetags.urlize_links_and_mails(content), expected_content) - @istest - def urlize_header_links(self): + def test_urlize_header_links(self): # update api link with html links content with links content = """; rel="next" ; rel="prev" @@ -41,8 +37,7 @@ self.assertEquals(swh_templatetags.urlize_header_links(content), expected_content) - @istest - def safe_docstring_display(self): + def test_safe_docstring_display(self): # update api link with html links content with links docstring = """This is my list header: diff --git a/swh/web/tests/common/test_throttling.py b/swh/web/tests/common/test_throttling.py --- a/swh/web/tests/common/test_throttling.py +++ b/swh/web/tests/common/test_throttling.py @@ -18,7 +18,6 @@ from rest_framework.test import APIRequestFactory from rest_framework.decorators import api_view -from nose.tools import istest, nottest from swh.web.common.throttling import ( SwhWebRateThrottle, throttle_scope @@ -83,7 +82,6 @@ cache.clear() self.factory = APIRequestFactory() - @nottest def check_response(self, response, status_code, limit=None, remaining=None): assert response.status_code == status_code @@ -96,8 +94,7 @@ else: assert 'X-RateLimit-Remaining' not in response - @istest - def scope1_requests_are_throttled(self): + def test_scope1_requests_are_throttled(self): """ Ensure request rate is limited in scope1 """ @@ -117,8 +114,7 @@ response = self.client.post('/scope1_class') self.check_response(response, 429, scope1_limiter_rate_post, 0) - @istest - def scope2_requests_are_throttled(self): + def test_scope2_requests_are_throttled(self): """ Ensure request rate is limited in scope2 """ @@ -138,8 +134,7 @@ response = self.client.post('/scope2_func') self.check_response(response, 429, scope2_limiter_rate_post, 0) - @istest - def scope3_requests_are_throttled_exempted(self): + def test_scope3_requests_are_throttled_exempted(self): """ Ensure request rate is not limited in scope3 as requests coming from localhost are exempted from rate limit. diff --git a/swh/web/tests/common/test_utils.py b/swh/web/tests/common/test_utils.py --- a/swh/web/tests/common/test_utils.py +++ b/swh/web/tests/common/test_utils.py @@ -5,7 +5,6 @@ import datetime -from nose.tools import istest from unittest.mock import patch from swh.web.common import utils @@ -14,8 +13,7 @@ class UtilsTestCase(SWHWebTestCase): - @istest - def shorten_path_noop(self): + def test_shorten_path_noop(self): noops = [ '/api/', '/browse/', @@ -28,8 +26,7 @@ noop ) - @istest - def shorten_path_sha1(self): + def test_shorten_path_sha1(self): sha1 = 'aafb16d69fd30ff58afdd69036a26047f3aebdc6' short_sha1 = sha1[:8] + '...' @@ -46,8 +43,7 @@ template % short_sha1 ) - @istest - def shorten_path_sha256(self): + def test_shorten_path_sha256(self): sha256 = ('aafb16d69fd30ff58afdd69036a26047' '213add102934013a014dfca031c41aef') short_sha256 = sha256[:8] + '...' @@ -64,8 +60,7 @@ template % short_sha256 ) - @istest - def parse_timestamp(self): + def test_parse_timestamp(self): input_timestamps = [ None, '2016-01-12', @@ -87,13 +82,11 @@ for ts, exp_date in zip(input_timestamps, output_dates): self.assertEquals(utils.parse_timestamp(ts), exp_date) - @istest - def format_utc_iso_date(self): + def test_format_utc_iso_date(self): self.assertEqual(utils.format_utc_iso_date('2017-05-04T13:27:13+02:00'), # noqa '04 May 2017, 11:27 UTC') - @istest - def gen_path_info(self): + def test_gen_path_info(self): input_path = '/home/user/swh-environment/swh-web/' expected_result = [ {'name': 'home', 'path': 'home'}, @@ -109,8 +102,7 @@ self.assertEquals(path_info, expected_result) @patch('swh.web.common.utils.service') - @istest - def get_origin_visits(self, mock_service): + def test_get_origin_visits(self, mock_service): mock_service.MAX_LIMIT = 2 def _lookup_origin_visits(*args, **kwargs): @@ -140,8 +132,7 @@ self.assertEqual(len(origin_visits), 3) - @istest - def get_swh_persisent_id(self): + def test_get_swh_persisent_id(self): swh_object_type = 'content' sha1_git = 'aafb16d69fd30ff58afdd69036a26047f3aebdc6'