def test_tool_importers(self, iep): eps = iep.return_value = [ ep('ep1', 'foo'), ep('ep2', 'bar'), ep('ep3', 'foo')] pi = base.ProjectImporter(mock.Mock(name='neighborhood')) pi.source = 'foo' self.assertEqual(pi.tool_importers, {'ep1': eps[0].lv, 'ep3': eps[2].lv}) iep.assert_called_once_with('allura.importers')
def test_login_overlay(self, c, require_access, request): pi = base.ProjectImporter(mock.Mock()) require_access.side_effect = HTTPUnauthorized c.show_login_overlay = False request.path = '/test-importer/' pi._check_security() self.assertEqual(c.show_login_overlay, True) c.show_login_overlay = False request.path = '/test-importer/check_names/' pi._check_security() self.assertEqual(c.show_login_overlay, True) c.show_login_overlay = False request.path = '/test-importer/process/' with td.raises(HTTPUnauthorized): pi._check_security() self.assertEqual(c.show_login_overlay, False)
def test_process(self, c, M, import_tool, flash, redirect, by_name): by_name.return_value = base.ToolImporter() pi = base.ProjectImporter(mock.Mock()) pi.source = 'Source' pi.after_project_create = mock.Mock() pi.neighborhood.register_project.return_value.script_name = 'script_name/' kw = { 'project_name': 'project_name', 'project_shortname': 'shortname', 'tools': ['tool'], } with mock.patch.dict(base.config, {'site_name': 'foo'}): pi.process(**kw) pi.neighborhood.register_project.assert_called_once_with( 'shortname', project_name='project_name') pi.after_project_create.assert_called_once_with(c.project, **kw) import_tool.post.assert_called_once_with( 'forgeimporters.base.ToolImporter', **kw) M.AuditLog.log.assert_called_once_with('import project from Source') self.assertEqual(flash.call_count, 1) redirect.assert_called_once_with('script_name/admin/overview')