def test_should_not_include_files_outside_config_directory(self): mock_svn_service = Mock(SvnService) mock_svn_service.config_url = 'svn://url/for/configuration/repository' mock_svn_service.path_to_config = '/config' mock_svn_service.client = Mock() mock_info = Mock() mock_path_object_1 = Mock() mock_path_object_1.path = '/config/foo' mock_path_object_1.action = 'A' mock_path_object_2 = Mock() mock_path_object_2.path = '/XXXXXX/bar' mock_path_object_2.action = 'A' mock_path_object_3 = Mock() mock_path_object_3.path = '/XXX/foobar' mock_path_object_3.action = 'A' mock_info.changed_paths = [mock_path_object_1, mock_path_object_2, mock_path_object_3] mock_svn_service.get_logs_for_revision.return_value = [mock_info] actual = SvnService.get_changed_paths_with_action(mock_svn_service, '1980') self.assertEqual([('foo', 'A')], actual)
def get_git_tree_mock(commit_sha, recursive=False): first_file = Mock() first_file.type = "blob" first_file.path = "Dockerfile" second_file = Mock() second_file.type = "other" second_file.path = "/some/Dockerfile" third_file = Mock() third_file.type = "blob" third_file.path = "somesubdir/Dockerfile" t = Mock() if commit_sha == "aaaaaaa": t.tree = [ first_file, second_file, third_file, ] else: t.tree = [] return t
def get_git_tree_mock(commit_sha, recursive=False): first_file = Mock() first_file.type = 'blob' first_file.path = 'Dockerfile' second_file = Mock() second_file.type = 'other' second_file.path = '/some/Dockerfile' third_file = Mock() third_file.type = 'blob' third_file.path = 'somesubdir/Dockerfile' t = Mock() if commit_sha == 'aaaaaaa': t.tree = [ first_file, second_file, third_file, ] else: t.tree = [] return t
def test_should_return_list_with_tuples_including_one_tuple_which_has_a_delete_action( self): mock_svn_service = Mock(SvnService) mock_svn_service.config_url = 'svn://url/for/configuration/repository' mock_svn_service.path_to_config = '/config' mock_svn_service.client = Mock() mock_info = Mock() mock_path_object_1 = Mock() mock_path_object_1.path = '/config/' mock_path_object_1.action = 'A' mock_info.changed_paths = [mock_path_object_1] mock_path_object_2 = Mock() mock_path_object_2.path = '/config/spam.egg' mock_path_object_2.action = 'A' mock_path_object_3 = Mock() mock_path_object_3.path = '/config/foo.bar' mock_path_object_3.action = 'D' mock_info.changed_paths = [ mock_path_object_1, mock_path_object_2, mock_path_object_3 ] mock_svn_service.get_logs_for_revision.return_value = [mock_info] actual = SvnService.get_changed_paths_with_action( mock_svn_service, '1980') self.assertEqual([('', 'A'), ('spam.egg', 'A'), ('foo.bar', 'D')], actual)
def _given_dst_has_files(self): name1 = "src1" name2 = "src2" url1 = Mock() url1.path = name1 url2 = Mock() url2.path = name2 self._dst.list.return_value = [url1, url2] return [name1, name2]
def test_remove_duplicates(self): self.assertEqual([], remove_duplicates([])) issue1 = Mock() issue2 = Mock() issue1.path = '/filename' issue2.path = '/filename' issue1.severity = 10 issue2.severity = 10 issue1.line_number_start = None issue2.line_number_start = None issue1.line_position = None issue2.line_position = None issue1.message = 'foo' issue2.message = 'bar' self.assertEqual([issue1, issue2], remove_duplicates([issue1, issue2])) issue1.line_number_start = 42 issue2.line_number_start = 42 issue1.message = 'line too long' issue2.message = 'unused import foo' self.assertEqual([issue1, issue2], remove_duplicates([issue1, issue2])) issue1.line_number_start = 42 issue2.line_number_start = 42 issue1.line_position = -1 issue2.line_position = -1 issue1.message = 'unused import bar' issue2.message = 'module bar not used' self.assertEqual([issue1], remove_duplicates([issue1, issue2])) issue1.line_number_start = 42 issue2.line_number_start = 42 issue1.line_position = 12 issue2.line_position = 28 issue1.message = 'unused import bar' issue2.message = 'module foo not used' self.assertEqual([issue1, issue2], remove_duplicates([issue1, issue2])) issue1.line_number_start = 32 issue2.line_number_start = 32 issue1.line_position = 80 issue2.line_position = -1 issue1.message = 'line too long (92 characters)' issue2.message = 'Line too long (92/80)' self.assertEqual([issue1], remove_duplicates([issue1, issue2])) issue1.line_number_start = 32 issue2.line_number_start = 33 issue1.line_position = 80 issue2.line_position = -1 issue1.message = 'line too long (92 characters)' issue2.message = 'Line too long (92/80)' self.assertEqual([issue1, issue2], remove_duplicates([issue1, issue2]))
def _test_request(self, domain, path, response_code=200, expected_event=True): request = Mock() request.path = path request.domain = domain request.GET = {} request.POST = {} request.META = { 'HTTP_X_FORWARDED_FOR': '10.99.100.1' } request.user = Mock() request.user.is_authenticated = True request.user.username = '******' request.couch_user = self.user request.session = Mock() request.session.session_key = uuid.uuid4().hex response = Mock() response.status_code = response_code ICDSAuditMiddleware().process_response(request, response) events = list(ICDSAuditEntryRecord.objects.all()) event = events[0] if events else None if expected_event: self.assertIsNotNone(event) self.assertEqual(event.url, path) self.assertEqual(event.response_code, response_code) else: self.assertIsNone(event)
def test_find_all_markdown_in_shallow_repo(exists): "DocumentIndexer#find_all_markdown_files() in a folder with no child nodes" origin = '/foo/bar' maker = DocumentIndexer(origin) maker.node = Mock(path='/weeee') maker.node.relative.side_effect = lambda x: "relative[{0}]".format(x) markdown_node = Mock() markdown_node.dir.path = '/ccc/aaa' markdown_node.path = '/FFF/000' maker.node.grep.return_value = [markdown_node] files = list(maker.find_all_markdown_files()) files.should.equal([{ u'path': u'/ccc/aaa', u'type': u'tree', u'relative_path': u'relative[/ccc/aaa]' }, { u'path': u'/FFF/000', u'type': u'blob', u'relative_path': u'relative[/FFF/000]' } ]) repr(maker).should.equal('<markment.fs.DocumentIndexer(path=/weeee)>')
def default_args(): args = Mock() args.conf_file = '.lamvery.yml' args.path = 'requirements.txt' args.name = 'bar.txt' args.store = False return args
def default_args(): args = Mock() args.conf_file = '.lamvery.yml' args.path = 'requirements.txt' args.file = 'bar.txt' args.store = False return args
def test_owner_or_mod_required_passes_url_parameters(self): @owner_or_moderator_required def mock_view(request, user, context): return None request = Mock(spec=('path', 'REQUEST', 'user')) request.user = AnonymousUser() request.REQUEST = {'abra': 'cadabra', 'foo': 'bar'} request.path = '/some/path/' user = self.create_user('user') response = mock_view(request, user, {}) self.assertEqual(isinstance(response, HttpResponseRedirect), True) url = response['location'] parsed_url = urlparse.urlparse(url) self.assertEqual(parsed_url.path, reverse('user_signin')) next = dict(urlparse.parse_qsl(parsed_url.query))['next'] next_url = urllib.unquote(next) parsed_url = urlparse.urlparse(next_url) self.assertEqual(parsed_url.path, request.path) query = dict(urlparse.parse_qsl(parsed_url.query)) self.assertEqual(set(query.keys()), set(['foo', 'abra'])) self.assertEqual(set(query.values()), set(['bar', 'cadabra'])) self.assertEqual(query['abra'], 'cadabra')
def test_api_resource(): """ Test APIResource class """ resource = pdrest.APIResource() resource.register("method", "method", do_nothing) request = Mock() request.method = "method" request.path = "method" result = resource._get_callback(request) assert result[0] == do_nothing resource.getChild("method", request) resource.unregister(regex="method") # After unregister, the callback should be gone. result = resource._get_callback(request) assert result[0] is None resource.getChild("method", request) resource.children = Mock(name="what") result = resource.getChild("method", request) resource.getChild("method", request)
def test_is_ros_in_setupfile(self): try: mock_subprocess = Mock() mock_process = Mock(name='mockprocess') mock_subprocess.Popen.return_value = mock_process if sys.version < '3': mock_process.communicate.return_value = ( '/somewhere/mock_ros_root/foo/..', None) else: mock_process.communicate.return_value = ( b'/somewhere/mock_ros_root/foo/..', None) mock_os = Mock() mock_path = Mock() mock_os.path = mock_path mock_os.environ = {} mock_path.split = os.path.split mock_path.normpath = os.path.normpath mock_path.isfile.return_value = True rosinstall.helpers.subprocess = mock_subprocess rosinstall.helpers.os = mock_os result = rosinstall.helpers.get_ros_root_from_setupfile( "fooroot/foodir/setup.sh") self.assertEqual('/somewhere/mock_ros_root', os.path.normpath(result)) finally: rosinstall.helpers.subprocess = subprocess rosinstall.helpers.os = os
def _get_mock_page(path='mock', depth=0, parent=None): mock_page = Mock() mock_page.path = path mock_page.save.return_value = True mock_page.parent = parent mock_page.children = _get_children_mock(depth, parent=mock_page) return mock_page
def test_owner_or_mod_required_passes_url_parameters(self): @owner_or_moderator_required def mock_view(request, user, context): return None request = Mock(spec=('path', 'POST', 'user', 'method')) request.method = "POST" request.user = AnonymousUser() request.POST = {'abra': 'cadabra', 'foo': 'bar'} request.path = '/some/path/' user = self.create_user('user') response = mock_view(request, user, {}) self.assertEqual(isinstance(response, HttpResponseRedirect), True) url = response['location'] parsed_url = urllib.parse.urlparse(url) self.assertEqual(parsed_url.path, reverse('user_signin')) next_jwt = dict(urllib.parse.parse_qsl(parsed_url.query))['next'] next_url = decode_jwt(next_jwt).get('next_url') parsed_url = urllib.parse.urlparse(next_url) self.assertEqual(parsed_url.path, request.path) query = dict(urllib.parse.parse_qsl(parsed_url.query)) self.assertEqual(set(query.keys()), set(['foo', 'abra'])) self.assertEqual(set(query.values()), set(['bar', 'cadabra'])) self.assertEqual(query['abra'], 'cadabra')
def make_mock_request(self): mock_request = Mock() mock_request.path = '/' mock_request.user = Mock() mock_request.user.is_authenticated = Mock() mock_request.user.groups = Mock() mock_request.user.groups.all = Mock() return mock_request
def create_mock_text_editor(content): """ :param str content: Fake edits to return """ mock = Mock(spec=TextEditor) mock.edit.return_value = content mock.path = None return mock
def test_active(self): """Test the active template tag""" mock_request = Mock() mock_request.user = '******' mock_request.path = '/test1/adam/' nose.tools.eq_(tags.active(mock_request, '/test1/{{user}}/'), 'current-tab') nose.tools.eq_(tags.active(mock_request, '/test2/{{user}}/'), '')
def create_mock(name, build_depends, path): m = Mock() m.name = name m.build_depends = build_depends m.buildtool_depends = [] m.run_depends = [] m.exports = [] m.path = path return m
def test_active(self): """Test the active template tag""" mock_request = Mock() mock_request.user = "******" mock_request.path = "/test1/adam/" nose.tools.eq_(tags.active(mock_request, "/test1/{{user}}/"), "current-tab") nose.tools.eq_(tags.active(mock_request, "/test2/{{user}}/"), "")
def test_get_path(self): request = Mock() request.path = '/v2/recordsets' recordset = Mock() recordset.zone_id = 'a-b-c-d' expected_path = '/v2/zones/a-b-c-d/recordsets' path = adapters.RecordSetAPIv2Adapter._get_path(request, recordset) self.assertEqual(expected_path, path)
def test_no_long_url(self): url = '1234567890' * 19 # 190-character URL mock_request = Mock() mock_request.META = {'CONTENT_TYPE': 'text/plain'} mock_request.GET = {} mock_request.path = url mock_request.method = 'get' request_model = RequestModelFactory(mock_request).construct_request_model() self.assertEqual(request_model.path, url)
def create_mock(name, build_depends, run_depends, path): m = Mock() m.name = name m.build_depends = build_depends m.buildtool_depends = [] m.run_depends = run_depends m.exports = [] m.path = path return m
def create_mock(name, builddeps, path): m = Mock() m.name = name m.builddeps = builddeps m.buildtooldeps = [] m.rundeps = [] m.exports = [] m.path = path return m
def test_max_request(self): SilkyConfig().SILKY_MAX_REQUEST_BODY_SIZE = 10 # 10kb mock_request = Mock() mock_request.META = {"CONTENT_TYPE": "text/plain"} mock_request.GET = {} mock_request.body = "a".encode("ascii") * 1024 * 100 # 100kb mock_request.path = reverse("silk:requests") request_model = RequestModelFactory(mock_request).construct_request_model() self.assertFalse(request_model.raw_body)
def test_max_request(self): SilkyConfig().SILKY_MAX_REQUEST_BODY_SIZE = 10 # 10kb mock_request = Mock() mock_request.META = {'CONTENT_TYPE': 'text/plain'} mock_request.GET = {} mock_request.method = 'get' mock_request.body = 'a'.encode('ascii') * 1024 * 100 # 100kb mock_request.path = reverse('silk:requests') request_model = RequestModelFactory(mock_request).construct_request_model() self.assertFalse(request_model.raw_body)
def test_user_access_to_page_with_group(self): """ Test that method 'process_request' of PageAuthMiddleware middleware return None if user of request is a django user member of group associated with the page of the request """ mock_request = Mock() mock_request.user = self.app_operator mock_request.path = self.pages_with_group[0].slug self.assertIsNone(self.middlware.process_request(mock_request))
def test_long_url(self): url = '1234567890' * 200 # 2000-character URL mock_request = Mock() mock_request.META = {'CONTENT_TYPE': 'text/plain'} mock_request.GET = {} mock_request.method = 'get' mock_request.path = url request_model = RequestModelFactory(mock_request).construct_request_model() self.assertEqual(request_model.path, '%s...%s' % (url[:94], url[1907:])) self.assertEqual(len(request_model.path), 190)
def test_identify(): extension = IgnorePackageIdentification() metadata = Mock() with TemporaryDirectory(prefix='test_colcon_') as basepath: metadata.path = Path(basepath) assert extension.identify(metadata) is None (metadata.path / IGNORE_MARKER).write_text('') with pytest.raises(IgnoreLocationException): extension.identify(metadata)
def test_anonymous_user_access_to_page_without_group(self): """ Test that method 'process_request' of PageAuthMiddleware middleware return None if user of request is an 'AnonymousUser' and the request page don't have groups associated. """ mock_request = Mock() mock_request.user = AnonymousUser() mock_request.path = self.pages_no_group[0].slug self.assertIsNone(self.middlware.process_request(mock_request))
def test_user_access_to_page_without_group(self): """ Test that method 'process_request' of PageAuthMiddleware middleware return None (page is accessible) if user of request is a django user and the request page don't have groups associated. """ mock_request = Mock() mock_request.user = self.app_operator mock_request.path = self.pages_no_group[0].slug self.assertIsNone(self.middlware.process_request(mock_request))
def test_no_long_url(self): url = '1234567890' * 19 # 190-character URL mock_request = Mock() mock_request.META = {'CONTENT_TYPE': 'text/plain'} mock_request.GET = {} mock_request.path = url mock_request.method = 'get' request_model = RequestModelFactory( mock_request).construct_request_model() self.assertEqual(request_model.path, url)
def new_device(self, *args, **kwargs): """ Return a new Device instance suitable for testing. """ device_class = kwargs.pop("device_class") # we intentionally don't pass the "exists" kwarg to the constructor # becauses this causes issues with some devices (especially partitions) # but we still need it for some LVs like VDO because we can't create # those so we need to fake their existence even for the constructor if device_class is blivet.devices.LVMLogicalVolumeDevice: exists = kwargs.get("exists", False) else: exists = kwargs.pop("exists", False) part_type = kwargs.pop("part_type", parted.PARTITION_NORMAL) device = device_class(*args, **kwargs) if exists: device._current_size = kwargs.get("size") if isinstance(device, blivet.devices.PartitionDevice): # if exists: # device.parents = device.req_disks device.parents = device.req_disks parted_partition = Mock() if device.disk: part_num = device.name[len(device.disk.name):].split("p")[-1] parted_partition.number = int(part_num) parted_partition.type = part_type parted_partition.path = device.path parted_partition.get_device_node_name = Mock( return_value=device.name) if len(device.parents) == 1: disk_name = device.parents[0].name number = device.name.replace(disk_name, "") try: parted_partition.number = int(number) except ValueError: pass device._parted_partition = parted_partition elif isinstance(device, blivet.devices.LVMVolumeGroupDevice) and exists: device._complete = True device.exists = exists device.format.exists = exists if isinstance(device, blivet.devices.PartitionDevice): # PartitionDevice.probe sets up data needed for resize operations device.probe() return device
def test_should_return_list_with_directory_name_and_action_for_path_to_file_when_a_file_has_been_added(self): mock_svn_service = Mock(SvnService) mock_svn_service.config_url = 'svn://url/for/configuration/repository' mock_svn_service.path_to_config = '/config' mock_svn_service.client = Mock() mock_info = Mock() mock_path_object_1 = Mock() mock_path_object_1.path = '/config/' mock_path_object_1.action = 'A' mock_info.changed_paths = [mock_path_object_1] mock_path_object_2 = Mock() mock_path_object_2.path = '/config/spam.egg' mock_path_object_2.action = 'A' mock_info.changed_paths = [mock_path_object_1, mock_path_object_2] mock_svn_service.get_logs_for_revision.return_value = [mock_info] actual = SvnService.get_changed_paths_with_action(mock_svn_service, '1980') self.assertEqual([('', 'A'), ('spam.egg', 'A')], actual)
def test_long_url(self): url = '1234567890' * 200 # 2000-character URL mock_request = Mock() mock_request.META = {'CONTENT_TYPE': 'text/plain'} mock_request.GET = {} mock_request.method = 'get' mock_request.path = url request_model = RequestModelFactory( mock_request).construct_request_model() self.assertEqual(request_model.path, '%s...%s' % (url[:94], url[1907:])) self.assertEqual(len(request_model.path), 190)
def test_listeners_hear_to_speakers(): "Listeners should hear to speaker" before = Speaker('before', ['file_created']) @before.file_created def obeyer(event, node): node.received_successfully(True) node = Mock() node.path = 'foo/bar' before.shout('file_created', node) node.received_successfully.assert_called_once_with(True)
def test_user_access_to_page_with_other_group(self): """ Test that method 'process_request' of PageAuthMiddleware middleware return an HttpResponseForbidden object if user of request is a django user who is not a member of group associated with the page of the request """ mock_request = Mock() mock_request.user = self.app_admin mock_request.path = self.pages_with_group[0].slug self.assertIsInstance(self.middlware.process_request(mock_request), HttpResponseForbidden)
def test_unicode_path(self): request = Mock() request.GET = {u"member": [u"1"]} request.method = "GET" request.path = "/api/0/organizations/üuuuu/" endpoint = Endpoint() result = endpoint.build_cursor_link(request, "next", "1492107369532:0:0") assert result == ( "<http://testserver/api/0/organizations/%C3%BCuuuu/?" "member=%5Bu%271%27%5D&cursor=1492107369532:0:0>;" ' rel="next"; results="true"; cursor="1492107369532:0:0"')
def test_unicode_path(self): request = Mock() request.GET = {u'member': [u'1']} request.method = 'GET' request.path = '/api/0/organizations/üuuuu/' endpoint = Endpoint() result = endpoint.build_cursor_link(request, 'next', '1492107369532:0:0') assert result == ( '<http://testserver/api/0/organizations/%C3%BCuuuu/?' 'member=%5Bu%271%27%5D&cursor=1492107369532:0:0>;' ' rel="next"; results="true"; cursor="1492107369532:0:0\"' )
def test_getZenPackDirs_error(self): zp_name = 'noname_zp' zp_path = '/path/to/test_zp' zp_obj = Mock(id='test_zp') zp_obj.path = Mock(return_value=zp_path) self.rp_load.dmd.ZenPackManager.packs = create_autospec( self.rp_load.dmd.ZenPackManager.packs, return_value=[zp_obj]) self.rp_load.options.dir = 'reports' #set loglevel to 50(CRITICAL) this will remove error log self.rp_load.log.setLevel('CRITICAL') with self.assertRaises(SystemExit) as exc: self.rp_load.getZenPackDirs(name=zp_name) self.assertEqual(exc.exception.code, 1)
def test_getZenPackDirs(self): zp_name = 'test_zp' zp_path = '/path/to/test_zp' zp_obj = Mock(id='test_zp') zp_obj.path = Mock(return_value=zp_path) self.rp_load.dmd.ZenPackManager.packs = create_autospec( self.rp_load.dmd.ZenPackManager.packs, return_value=[zp_obj]) self.rp_load.options.dir = 'reports' zp_dir_result = ['/path/to/test_zp/reports'] result = self.rp_load.getZenPackDirs(name=zp_name) self.assertEqual(result, zp_dir_result) self.assertIsInstance(result, list) self.assertEqual(len(result), 1)
def test_unicode_path(self): request = Mock() request.GET = {u'member': [u'1']} request.method = 'GET' request.path = '/api/0/organizations/üuuuu/' endpoint = Endpoint() result = endpoint.build_cursor_link(request, 'next', '1492107369532:0:0') assert result == ( '<http://testserver/api/0/organizations/%C3%BCuuuu/?' 'member=%5Bu%271%27%5D&cursor=1492107369532:0:0>;' ' rel="next"; results="true"; cursor="1492107369532:0:0\"')
def test_FilePathBaseBarFile_Base(self): # stub the files method to return a stub file stub_file = Mock(name='file') stub_torrent_handle = Mock(name='handle') stub_torrent_handle.get_torrent_info().files = Mock( return_value=[stub_file]) # stub out file path to return the desired path stub_file.path = 'base/file' handle = DownloadHandle(None, stub_torrent_handle) assert handle.basename == 'base'
def test_should_return_list_with_tuples_including_one_tuple_which_has_a_delete_action(self): mock_svn_service = Mock(SvnService) mock_svn_service.config_url = 'svn://url/for/configuration/repository' mock_svn_service.path_to_config = '/config' mock_svn_service.client = Mock() mock_info = Mock() mock_path_object_1 = Mock() mock_path_object_1.path = '/config/' mock_path_object_1.action = 'A' mock_info.changed_paths = [mock_path_object_1] mock_path_object_2 = Mock() mock_path_object_2.path = '/config/spam.egg' mock_path_object_2.action = 'A' mock_path_object_3 = Mock() mock_path_object_3.path = '/config/foo.bar' mock_path_object_3.action = 'D' mock_info.changed_paths = [mock_path_object_1, mock_path_object_2, mock_path_object_3] mock_svn_service.get_logs_for_revision.return_value = [mock_info] actual = SvnService.get_changed_paths_with_action(mock_svn_service, '1980') self.assertEqual([('', 'A'), ('spam.egg', 'A'), ('foo.bar', 'D')], actual)
def test_img_404_warm_cache(self): """ Ensure we go straight to a 404 response without setting anything new in cache or touching filesystem if we encounter a cached 404. """ req = Mock() req.path = "/lt_cache/thumbnail/48/i/p.jpg" self.renderer._render_and_save = Mock() with patch('lazythumbs.views.cache', self.mc_factory(1)) as mc: resp = self.renderer.get(req, 'thumbnail', '48', 'i/p') self.assertEqual(resp.status_code, 404) self.assertEqual(resp['Content-Type'], 'image/jpeg') self.assertTrue('Cache-Control' in resp) self.assertFalse(mc.set.called)
def test_exec_add(self): """Test workspace add execution.""" ws = Mock() ws.add = Mock() args = Mock() args.workspace_subcommand = "add" args.name = "foo" args.path = "/foo" self.subcommand.ws = ws self.subcommand.execute(args) ws.add.assert_called_with("foo", "/foo")
def test_should_return_list_with_empty_string_and_action_string_when_configuration_directory_has_been_created_in_commit(self): mock_svn_service = Mock(SvnService) mock_svn_service.config_url = 'svn://url/for/configuration/repository' mock_svn_service.path_to_config = '/config' mock_info = Mock() mock_path_object = Mock() mock_path_object.path = '/config/' mock_path_object.action = 'A' mock_info.changed_paths = [mock_path_object] mock_svn_service.get_logs_for_revision.return_value = [mock_info] actual = SvnService.get_changed_paths_with_action(mock_svn_service, '1980') self.assertEqual([('', 'A')], actual)
def test_exec_add_call_slashes2dash(self): """ Test workspace add execution call slashes2dash function for name argument. """ args = Mock() args.workspace_subcommand = "add" args.name = "foo" args.path = "/foo" self.subcommand.ws = Mock() with patch("yoda.subcommand.workspace.slashes2dash") as s2d: self.subcommand.execute(args) s2d.assert_called_once_with("foo")
def test_no_img_should_404(self): """ When save fails with EEXIST error, it will try to read the file again But if it still can't be read, make sure it returns a 404 instead of 0-byte image. """ req = Mock() req.path = "/lt_cache/thumbnail/48/i/p.jpg" self.renderer.fs.save = Mock() err = OSError() err.errno = errno.EEXIST self.renderer.fs.save.side_effect = err with patch('lazythumbs.views.Image', self.mock_Image): with patch('lazythumbs.views.cache', MockCache()): resp = self.renderer.get(req, 'thumbnail', '48', 'i/p') self.assertEqual(resp.status_code, 404)