diff --git a/horizon/test/unit/forms/test_fields.py b/horizon/test/unit/forms/test_fields.py index 1edd5186e0..7d7784d96d 100644 --- a/horizon/test/unit/forms/test_fields.py +++ b/horizon/test/unit/forms/test_fields.py @@ -209,7 +209,7 @@ class MACAddressFieldTests(test.TestCase): self.assertEqual(field.mac_address, "00:11:88:99:aa:ff") -class TestChoiceFieldForm(forms.SelfHandlingForm): +class ChoiceFieldForm(forms.SelfHandlingForm): title_dic = {"label1": {"title": "This is choice 1"}, "label2": {"title": "This is choice 2"}, "label3": {"title": "This is choice 3"}} @@ -227,8 +227,7 @@ class TestChoiceFieldForm(forms.SelfHandlingForm): transform_html_attrs=title_dic.get)) def __init__(self, request, *args, **kwargs): - super(TestChoiceFieldForm, self).__init__(request, *args, - **kwargs) + super(ChoiceFieldForm, self).__init__(request, *args, **kwargs) choices = ([('choice1', 'label1'), ('choice2', 'label2')]) self.fields['test_choices'].choices = choices @@ -243,7 +242,7 @@ class ChoiceFieldTests(test.TestCase): def setUp(self): super(ChoiceFieldTests, self).setUp() - self.form = TestChoiceFieldForm(self.request) + self.form = ChoiceFieldForm(self.request) def _render_form(self): return shortcuts.render(self.request, self.template, @@ -261,7 +260,7 @@ class ChoiceFieldTests(test.TestCase): count=1, html=True) -class TestThemableChoiceFieldForm(forms.SelfHandlingForm): +class ThemableChoiceFieldForm(forms.SelfHandlingForm): # It's POSSIBLE to combine this with the test helper form above, but # I fear we'd run into collisions where one test's desired output is # actually within a separate widget's output. @@ -283,8 +282,7 @@ class TestThemableChoiceFieldForm(forms.SelfHandlingForm): transform_html_attrs=title_dic.get)) def __init__(self, request, *args, **kwargs): - super(TestThemableChoiceFieldForm, self).__init__(request, *args, - **kwargs) + super(ThemableChoiceFieldForm, self).__init__(request, *args, **kwargs) choices = ([('choice1', 'label1'), ('choice2', 'label2')]) self.fields['test_choices'].choices = choices @@ -299,7 +297,7 @@ class ThemableChoiceFieldTests(test.TestCase): def setUp(self): super(ThemableChoiceFieldTests, self).setUp() - self.form = TestThemableChoiceFieldForm(self.request) + self.form = ThemableChoiceFieldForm(self.request) def _render_form(self): return shortcuts.render(self.request, self.template, diff --git a/horizon/test/unit/forms/test_forms.py b/horizon/test/unit/forms/test_forms.py index 58539917a9..f8f2f1c6e4 100644 --- a/horizon/test/unit/forms/test_forms.py +++ b/horizon/test/unit/forms/test_forms.py @@ -28,7 +28,7 @@ class FormMixinTests(test.TestCase): view.kwargs = kwargs view.template_name = 'test_template' # Note(Itxaka): ModalFormView requires a form_class to behave properly - view.form_class = TestForm + view.form_class = FormForTesting return view def test_modal_form_mixin_hide_true_if_ajax(self): @@ -68,8 +68,7 @@ class FormMixinTests(test.TestCase): self.assertEqual(view.template_name, view.get_template_names()) -class TestForm(forms.SelfHandlingForm): - +class FormForTesting(forms.SelfHandlingForm): name = forms.CharField(max_length=255) def handle(self, request, data): @@ -84,7 +83,7 @@ class FormErrorTests(test.TestCase): super(FormErrorTests, self).setUp() # Note(Itxaka): We pass data to the form so its bound and has the # proper cleaned_data fields - self.form = TestForm(self.request, data={'fake': 'data'}) + self.form = FormForTesting(self.request, data={'fake': 'data'}) def _render_form(self): return shortcuts.render(self.request, self.template, diff --git a/horizon/test/unit/workflows/test_workflows.py b/horizon/test/unit/workflows/test_workflows.py index f4e455176b..8ef75e686b 100644 --- a/horizon/test/unit/workflows/test_workflows.py +++ b/horizon/test/unit/workflows/test_workflows.py @@ -39,13 +39,13 @@ def extra_callback_func(request, context): return "extra" -class TestActionOne(workflows.Action): +class ActionOne(workflows.Action): project_id = forms.ChoiceField(label="Project") user_id = forms.ChoiceField(label="User") class Meta(object): - name = "Test Action One" - slug = "test_action_one" + name = "Action One" + slug = "action_one" def populate_project_id_choices(self, request, context): return [(PROJECT_ID, "test_project")] @@ -57,28 +57,28 @@ class TestActionOne(workflows.Action): return {"foo": "bar"} -class TestActionTwo(workflows.Action): +class ActionTwo(workflows.Action): instance_id = forms.CharField(label="Instance") class Meta(object): - name = "Test Action Two" - slug = "test_action_two" + name = "Action Two" + slug = "action_two" -class TestActionThree(workflows.Action): +class ActionThree(workflows.Action): extra = forms.CharField(widget=forms.widgets.Textarea) class Meta(object): - name = "Test Action Three" - slug = "test_action_three" + name = "Action Three" + slug = "action_three" -class TestActionFour(workflows.Action): +class ActionFour(workflows.Action): field_four = forms.CharField(widget=forms.widgets.Textarea) class Meta(object): - name = "Test Action Four" - slug = "test_action_four" + name = "Action Four" + slug = "action_four" class AdminAction(workflows.Action): @@ -90,12 +90,12 @@ class AdminAction(workflows.Action): permissions = ("horizon.test",) -class TestDisabledAction(workflows.Action): +class DisabledAction(workflows.Action): disabled_id = forms.CharField(label="Disabled") class Meta(object): - name = "Test Action Disabled" - slug = "test_action_disabled" + name = "Action Disabled" + slug = "action_disabled" class AdminForbiddenAction(workflows.Action): @@ -107,13 +107,13 @@ class AdminForbiddenAction(workflows.Action): policy_rules = (('action', 'forbidden'),) -class TestStepOne(workflows.Step): - action_class = TestActionOne +class StepOne(workflows.Step): + action_class = ActionOne contributes = ("project_id", "user_id") -class TestStepTwo(workflows.Step): - action_class = TestActionTwo +class StepTwo(workflows.Step): + action_class = ActionTwo depends_on = ("project_id",) contributes = ("instance_id",) connections = {"project_id": @@ -122,29 +122,29 @@ class TestStepTwo(workflows.Step): "other_callback_func")} -class TestStepThree(workflows.Step): - action_class = TestActionThree +class StepThree(workflows.Step): + action_class = ActionThree depends_on = ("project_id",) contributes = ("extra_data",) connections = {"project_id": (extra_callback_func,)} - after = TestStepOne - before = TestStepTwo + after = StepOne + before = StepTwo -class TestStepFour(workflows.Step): - action_class = TestActionFour +class StepFour(workflows.Step): + action_class = ActionFour contributes = ("field_four",) class AdminStep(workflows.Step): action_class = AdminAction contributes = ("admin_id",) - after = TestStepOne - before = TestStepTwo + after = StepOne + before = StepTwo -class TestDisabledStep(workflows.Step): - action_class = TestDisabledAction +class DisabledStep(workflows.Step): + action_class = DisabledAction contributes = ("disabled_id",) def allowed(self, request): @@ -155,29 +155,29 @@ class AdminForbiddenStep(workflows.Step): action_class = AdminForbiddenAction -class TestWorkflow(workflows.Workflow): +class WorkflowForTesting(workflows.Workflow): slug = "test_workflow" - default_steps = (TestStepOne, TestStepTwo) + default_steps = (StepOne, StepTwo) -class TestWorkflowWithConfig(workflows.Workflow): +class WorkflowWithConfig(workflows.Workflow): slug = "test_workflow" - default_steps = (TestStepOne,) + default_steps = (StepOne,) -class TestWorkflowView(workflows.WorkflowView): - workflow_class = TestWorkflow +class WorkflowViewForTesting(workflows.WorkflowView): + workflow_class = WorkflowForTesting template_name = "workflow.html" -class TestFullscreenWorkflow(workflows.Workflow): +class FullscreenWorkflow(workflows.Workflow): slug = 'test_fullscreen_workflow' - default_steps = (TestStepOne, TestStepTwo) + default_steps = (StepOne, StepTwo) fullscreen = True -class TestFullscreenWorkflowView(workflows.WorkflowView): - workflow_class = TestFullscreenWorkflow +class FullscreenWorkflowView(workflows.WorkflowView): + workflow_class = FullscreenWorkflow template_name = "workflow.html" @@ -194,86 +194,86 @@ class WorkflowsTests(test.TestCase): self._reset_workflow() def _reset_workflow(self): - TestWorkflow._cls_registry = [] + WorkflowForTesting._cls_registry = [] def test_workflow_construction(self): - TestWorkflow.register(TestStepThree) - flow = TestWorkflow(self.request) + WorkflowForTesting.register(StepThree) + flow = WorkflowForTesting(self.request) self.assertQuerysetEqual(flow.steps, - ['', - '', - '']) + ['', + '', + '']) self.assertEqual(set(['project_id']), flow.depends_on) @test.update_settings(HORIZON_CONFIG={'extra_steps': { - 'horizon.test.unit.workflows.test_workflows.TestWorkflowWithConfig': ( - 'horizon.test.unit.workflows.test_workflows.TestStepTwo', - 'horizon.test.unit.workflows.test_workflows.TestStepThree', - 'horizon.test.unit.workflows.test_workflows.TestStepFour', + 'horizon.test.unit.workflows.test_workflows.WorkflowWithConfig': ( + 'horizon.test.unit.workflows.test_workflows.StepTwo', + 'horizon.test.unit.workflows.test_workflows.StepThree', + 'horizon.test.unit.workflows.test_workflows.StepFour', ), }}) def test_workflow_construction_with_config(self): - flow = TestWorkflowWithConfig(self.request) - # NOTE: TestStepThree must be placed between TestStepOne and - # TestStepTwo in honor of before/after of TestStepThree. + flow = WorkflowWithConfig(self.request) + # NOTE: StepThree must be placed between StepOne and + # StepTwo in honor of before/after of StepThree. self.assertQuerysetEqual(flow.steps, - ['', - '', - '', - '', + ['', + '', + '', + '', ]) def test_step_construction(self): - step_one = TestStepOne(TestWorkflow(self.request)) + step_one = StepOne(WorkflowForTesting(self.request)) # Action slug is moved from Meta by metaclass, and # Step inherits slug from action. - self.assertEqual(TestActionOne.name, step_one.name) - self.assertEqual(TestActionOne.slug, step_one.slug) + self.assertEqual(ActionOne.name, step_one.name) + self.assertEqual(ActionOne.slug, step_one.slug) # Handlers should be empty since there are no connections. self.assertEqual(step_one._handlers, {}) - step_two = TestStepTwo(TestWorkflow(self.request)) + step_two = StepTwo(WorkflowForTesting(self.request)) # Handlers should be populated since we do have connections. self.assertEqual([local_callback_func, other_callback_func], step_two._handlers["project_id"]) def test_step_invalid_connections_handlers_not_list_or_tuple(self): - class InvalidStepA(TestStepTwo): + class InvalidStepA(StepTwo): connections = {'project_id': {}} - class InvalidStepB(TestStepTwo): + class InvalidStepB(StepTwo): connections = {'project_id': ''} with self.assertRaises(TypeError): - InvalidStepA(TestWorkflow(self.request)) + InvalidStepA(WorkflowForTesting(self.request)) with self.assertRaises(TypeError): - InvalidStepB(TestWorkflow(self.request)) + InvalidStepB(WorkflowForTesting(self.request)) def test_step_invalid_connection_handler_not_string_or_callable(self): - class InvalidStepA(TestStepTwo): + class InvalidStepA(StepTwo): connections = {'project_id': (None,)} - class InvalidStepB(TestStepTwo): + class InvalidStepB(StepTwo): connections = {'project_id': (0,)} with self.assertRaises(TypeError): - InvalidStepA(TestWorkflow(self.request)) + InvalidStepA(WorkflowForTesting(self.request)) with self.assertRaises(TypeError): - InvalidStepB(TestWorkflow(self.request)) + InvalidStepB(WorkflowForTesting(self.request)) def test_step_invalid_callback(self): # This should raise an exception - class InvalidStep(TestStepTwo): + class InvalidStep(StepTwo): connections = {"project_id": ('local_callback_func',)} with self.assertRaises(ValueError): - InvalidStep(TestWorkflow(self.request)) + InvalidStep(WorkflowForTesting(self.request)) def test_connection_handlers_called(self): - TestWorkflow.register(TestStepThree) - flow = TestWorkflow(self.request) + WorkflowForTesting.register(StepThree) + flow = WorkflowForTesting(self.request) # This should set the value without any errors, but trigger nothing flow.context['does_not_exist'] = False @@ -283,12 +283,12 @@ class WorkflowsTests(test.TestCase): # steps one and two, and one has no handlers, so we should see # a response from extra, then one from each of step two's handlers. val = flow.context.set('project_id', PROJECT_ID) - self.assertEqual([('test_action_three', 'extra'), - ('test_action_two', 'one'), - ('test_action_two', 'two')], val) + self.assertEqual([('action_three', 'extra'), + ('action_two', 'one'), + ('action_two', 'two')], val) def test_workflow_validation(self): - flow = TestWorkflow(self.request) + flow = WorkflowForTesting(self.request) # Missing items fail validation. with self.assertRaises(exceptions.WorkflowValidationError): @@ -300,7 +300,7 @@ class WorkflowsTests(test.TestCase): "instance_id": INSTANCE_ID} req = self.factory.post("/", seed) req.user = self.user - flow = TestWorkflow(req, context_seed={"project_id": PROJECT_ID}) + flow = WorkflowForTesting(req, context_seed={"project_id": PROJECT_ID}) for step in flow.steps: if not step.action.is_valid(): self.fail("Step %s was unexpectedly invalid: %s" @@ -312,71 +312,71 @@ class WorkflowsTests(test.TestCase): self.assertTrue(flow.is_valid()) def test_workflow_finalization(self): - flow = TestWorkflow(self.request) + flow = WorkflowForTesting(self.request) self.assertTrue(flow.finalize()) def test_workflow_view(self): - view = TestWorkflowView.as_view() + view = WorkflowViewForTesting.as_view() req = self.factory.get("/") res = view(req) self.assertEqual(200, res.status_code) def test_workflow_registration(self): req = self.factory.get("/foo") - flow = TestWorkflow(req) + flow = WorkflowForTesting(req) self.assertQuerysetEqual(flow.steps, - ['', - '']) + ['', + '']) - TestWorkflow.register(TestStepThree) - flow = TestWorkflow(req) + WorkflowForTesting.register(StepThree) + flow = WorkflowForTesting(req) self.assertQuerysetEqual(flow.steps, - ['', - '', - '']) + ['', + '', + '']) def test_workflow_unregister_unexisting_workflow(self): with self.assertRaises(base.NotRegistered): - TestWorkflow.unregister(TestDisabledStep) + WorkflowForTesting.unregister(DisabledStep) def test_workflow_render(self): - TestWorkflow.register(TestStepThree) + WorkflowForTesting.register(StepThree) req = self.factory.get("/foo") - flow = TestWorkflow(req) + flow = WorkflowForTesting(req) output = http.HttpResponse(flow.render()) self.assertContains(output, flow.name) - self.assertContains(output, TestActionOne.name) - self.assertContains(output, TestActionTwo.name) - self.assertContains(output, TestActionThree.name) + self.assertContains(output, ActionOne.name) + self.assertContains(output, ActionTwo.name) + self.assertContains(output, ActionThree.name) def test_has_permissions(self): - self.assertQuerysetEqual(TestWorkflow._cls_registry, []) - TestWorkflow.register(AdminStep) - flow = TestWorkflow(self.request) + self.assertQuerysetEqual(WorkflowForTesting._cls_registry, []) + WorkflowForTesting.register(AdminStep) + flow = WorkflowForTesting(self.request) step = AdminStep(flow) self.assertCountEqual(step.permissions, ("horizon.test",)) self.assertQuerysetEqual(flow.steps, - ['', - '']) + ['', + '']) self.set_permissions(['test']) self.request.user = self.user - flow = TestWorkflow(self.request) + flow = WorkflowForTesting(self.request) self.assertQuerysetEqual(flow.steps, - ['', + ['', '', - '']) + '']) def test_has_allowed(self): - TestWorkflow.register(TestDisabledStep) - flow = TestWorkflow(self.request) - # Check TestDisabledStep is not included - # even though TestDisabledStep is registered. + WorkflowForTesting.register(DisabledStep) + flow = WorkflowForTesting(self.request) + # Check DisabledStep is not included + # even though DisabledStep is registered. self.assertQuerysetEqual(flow.steps, - ['', - '']) + ['', + '']) def test_step_is_hidden_on_policy(self): self.policy_patcher.stop() @@ -387,15 +387,15 @@ class WorkflowsTests(test.TestCase): return True with mock.patch('openstack_auth.policy.check', policy_check): - TestWorkflow.register(AdminForbiddenStep) - flow = TestWorkflow(self.request) + WorkflowForTesting.register(AdminForbiddenStep) + flow = WorkflowForTesting(self.request) output = http.HttpResponse(flow.render()) self.assertNotContains(output, AdminForbiddenAction.name) def test_entry_point(self): req = self.factory.get("/foo") - flow = TestWorkflow(req) - self.assertEqual("test_action_one", flow.get_entry_point()) + flow = WorkflowForTesting(req) + self.assertEqual("action_one", flow.get_entry_point()) - flow = TestWorkflow(req, entry_point="test_action_two") - self.assertEqual("test_action_two", flow.get_entry_point()) + flow = WorkflowForTesting(req, entry_point="action_two") + self.assertEqual("action_two", flow.get_entry_point())