Example #1
0
    def test_add_decision(self):
        """
        Test error conditions for the add decision page. 
        """
        path = reverse('publicweb_decision_create',
                       args=[self.bettysorg.slug, Decision.PROPOSAL_STATUS])
        # Test that the decision add view returns an empty form
        site_form = self.client.get(path).context['form']
        code_form = DecisionForm()
        self.assertEqual(
            type(site_form).__name__,
            type(code_form).__name__, "Unexpected form!")

        path = reverse('publicweb_decision_create',
                       args=[self.bettysorg.slug, Decision.DECISION_STATUS])
        # Test that the decision add view returns an empty form
        site_form = self.client.get(path).context['form']
        code_form = DecisionForm()
        self.assertEqual(
            type(site_form).__name__,
            type(code_form).__name__, "Unexpected form!")

        path = reverse('publicweb_decision_create',
                       args=[self.bettysorg.slug, Decision.ARCHIVED_STATUS])
        # Test that the decision add view returns an empty form
        site_form = self.client.get(path).context['form']
        code_form = DecisionForm()
        self.assertEqual(
            type(site_form).__name__,
            type(code_form).__name__, "Unexpected form!")
Example #2
0
def _process_post_and_redirect(request, decision, template_name):
    if request.POST.get('submit', None) == "Cancel":
        return HttpResponseRedirect(reverse(object_list_by_status, args=[decision.status]))
    else:
        form = DecisionForm(request.POST, instance=decision)
        
        if form.is_valid():
            decision = form.save()
            if form.cleaned_data['watch']:
                decision.add_watcher(request.user)
            else:
                decision.remove_watcher(request.user)
            return HttpResponseRedirect(reverse(object_list_by_status, args=[decision.status]))
        
        data = dict(form=form)
        context = RequestContext(request, data)
        return render_to_response(template_name, context)   
Example #3
0
 def test_decision_editor_set_on_update(self):
     # Create the decision
     user1 = UserFactory()
     decision = DecisionFactory(author=user1, editor=user1)
     # Have a different user update it
     user2 = UserFactory()
     request = RequestFactory()
     request.user = user2
     decision_update_view = DecisionUpdate()
     decision_update_view.request = request
     decision_update_view.object = decision
     decision_update_view.get_object = lambda: decision
     decision_update_view.last_status = 'dummy'
     form = DecisionForm(instance=decision)
     form.cleaned_data = {'watch': True}
     decision_update_view.form_valid(form)
     self.assertEqual(decision.editor, user2)
Example #4
0
 def test_decision_editor_set_on_update(self):
     # Create the decision
     user1 = UserFactory()
     decision = DecisionFactory(author=user1,
                                editor=user1)
     # Have a different user update it
     user2 = UserFactory()
     request = RequestFactory()
     request.user = user2
     decision_update_view = DecisionUpdate()
     decision_update_view.request = request
     decision_update_view.object = decision
     decision_update_view.get_object = lambda: decision
     decision_update_view.last_status = 'dummy'
     form = DecisionForm(instance=decision)
     form.cleaned_data = {'watch': True, 'minor_edit': False}
     decision_update_view.form_valid(form)
     self.assertEqual(decision.editor, user2)
Example #5
0
    def test_add_decision(self):
        """
        Test error conditions for the add decision page. 
        """
        path = reverse('publicweb_decision_add')
        # Test that the decision add view returns an empty form
        response = self.client.get(path)
        form = DecisionForm()
        self.assertEqual(form.as_p(), response.context['decision_form'].as_p())

        # Test that the decision add view validates and rejects and empty post

        post_dict = self.get_default_decision_form_dict()
        post_dict.update({
            'feedback_set-TOTAL_FORMS': '3',
            'feedback_set-INITIAL_FORMS': '0',
            'feedback_set-MAX_NUM_FORMS': ''
        })

        response = self.client.post(path, post_dict)

        self.assertFalse(response.context['decision_form'].is_valid())

        # Test that providing a short name is enough to complete the form,
        # save the object and send us back to the home page

        post_dict = self.get_default_decision_form_dict()

        post_dict.update({
            'description': 'Make Eggs',
            'watch': False,
            'submit': "Submit",
            'feedback_set-TOTAL_FORMS': '3',
            'feedback_set-INITIAL_FORMS': '0',
            'feedback_set-MAX_NUM_FORMS': '',
            'feedback_set-0-description': 'The eggs are bad',
            'feedback_set-1-description': 'No one wants them'
        })

        response = self.client.post(path, post_dict, follow=True)

        self.assertRedirects(response,
                             reverse('list', args=['decision']),
                             msg_prefix=response.content)
Example #6
0
    def test_form_has_tags(self):
        decision_form = DecisionForm()
        self.assertTrue("tags" in decision_form.fields,
                        "Decision form does not contain tags entry")

        self.assertEquals(TagField, type(decision_form.fields["tags"]),
                          "Decision form tags is not a TagField")

        self.assertEquals(TextInput, type(decision_form.fields["tags"].widget),
                          "Decision form tags is not a TextInput widget")
Example #7
0
    def test_add_decision(self):
        """
        Test error conditions for the add decision page. 
        """
        path = reverse("publicweb_decision_add")
        # Test that the decision add view returns an empty form
        response = self.client.get(path)
        form = DecisionForm()
        self.assertEqual(form.as_p(), response.context["decision_form"].as_p())

        # Test that the decision add view validates and rejects and empty post

        post_dict = self.get_default_decision_form_dict()
        post_dict.update(
            {"feedback_set-TOTAL_FORMS": "3", "feedback_set-INITIAL_FORMS": "0", "feedback_set-MAX_NUM_FORMS": ""}
        )

        response = self.client.post(path, post_dict)

        self.assertFalse(response.context["decision_form"].is_valid())

        # Test that providing a short name is enough to complete the form,
        # save the object and send us back to the home page

        post_dict = self.get_default_decision_form_dict()

        post_dict.update(
            {
                "description": "Make Eggs",
                "watch": False,
                "submit": "Submit",
                "feedback_set-TOTAL_FORMS": "3",
                "feedback_set-INITIAL_FORMS": "0",
                "feedback_set-MAX_NUM_FORMS": "",
                "feedback_set-0-description": "The eggs are bad",
                "feedback_set-1-description": "No one wants them",
            }
        )

        response = self.client.post(path, post_dict, follow=True)

        self.assertRedirects(response, reverse("list", args=["decision"]), msg_prefix=response.content)
Example #8
0
 def test_user_can_unwatch_a_decision(self):
     org_user = OrganizationUserFactory()
     org = org_user.organization
     user = org_user.user
     decision = DecisionFactory(organization=org)
     # Confirm decision has a single watcher
     self.assertEqual(decision.watchers.count(), 1)
     # Get the view ready
     request = RequestFactory()
     request.user = user
     decision_update_view = DecisionUpdate()
     decision_update_view.request = request
     decision_update_view.object = decision
     decision_update_view.get_object = lambda: decision
     decision_update_view.last_status = 'dummy'
     form = DecisionForm(instance=decision)
     form.cleaned_data = {'watch': False}
     # Run the form_valid method to stop observing
     decision_update_view.form_valid(form)
     self.assertEqual(decision.watchers.count(), 0)
Example #9
0
 def test_user_can_unwatch_a_decision(self):
     org_user = OrganizationUserFactory()
     org = org_user.organization
     user = org_user.user
     decision = DecisionFactory(organization=org)
     # Confirm decision has a single watcher
     self.assertEqual(decision.watchers.count(), 1)
     # Get the view ready
     request = RequestFactory()
     request.user = user
     decision_update_view = DecisionUpdate()
     decision_update_view.request = request
     decision_update_view.object = decision
     decision_update_view.get_object = lambda: decision
     decision_update_view.last_status = 'dummy'
     form = DecisionForm(instance=decision)
     form.cleaned_data = {'watch': False, 'minor_edit': False}
     # Run the form_valid method to stop observing
     decision_update_view.form_valid(form)
     self.assertEqual(decision.watchers.count(), 0)
Example #10
0
    def test_form_has_watch(self):
        decision_form = DecisionForm()
        self.assertTrue("watch" in decision_form.fields,
                        "Decision form does not contain watch checkbox")

        self.assertEquals(BooleanField, type(decision_form.fields["watch"]),
                          "Decision form watch is not a BooleanField")

        self.assertEquals(CheckboxInput,
                          type(decision_form.fields["watch"].widget),
                          "Decision form watch is not a CheckboxInput widget")
Example #11
0
    def test_edit_decision(self):
        decision = self.create_and_return_example_decision_with_feedback()

        path = reverse('publicweb_decision_edit', args=[decision.id])
        response = self.client.get(path)

        test_form_str = str(DecisionForm(instance=decision))
        decision_form_str = str(response.context['decision_form'])

        self.assertEqual(test_form_str, decision_form_str,
                         self.get_diff(test_form_str, decision_form_str))
Example #12
0
    def test_add_decision(self):
        """
        Test error conditions for the add decision page. 
        """
        path = reverse('publicweb_decision_create',
                       args=[self.bettysorg.slug, Decision.PROPOSAL_STATUS])
        # Test that the decision add view returns an empty form
        actual = self.client.get(path).context['form'].as_p().splitlines()

        expected = DecisionForm().as_p().splitlines()

        self.assertEqual(expected, actual)

        # Test that the decision add view validates and rejects an empty post
        post_dict = self.get_default_decision_form_dict()

        response = self.client.post(path, post_dict)

        self.assertFalse(response.context['form'].is_valid())

        # Test that providing a short name is enough to complete the form,
        # save the object and send us to the list screen of the relevant status

        post_dict = self.get_default_decision_form_dict()

        post_dict.update({
            'description': 'Make Eggs',
            'watch': False,
            'submit': "Submit"
        })

        response = self.client.post(path, post_dict, follow=True)

        self.assertRedirects(
            response,
            reverse('publicweb_item_list',
                    args=[self.bettysorg.slug, post_dict['status']]))
Example #13
0
 def test_email_not_sent_when_watcher_removed(self, notifications):
     dispatch_uid = "publicweb.models.decision_signal_handler"
     Signal.disconnect(signals.post_save, sender=Decision,
                       dispatch_uid=dispatch_uid)
     decision = self.create_and_return_decision()
     data = {
           'description': decision.description,
           'status': decision.status,
           'deadline': decision.deadline,
           'people': decision.people,
           'watch': True
     }
     form = DecisionForm(data, instance=decision)
     form.watch = False
     form.is_valid()
     form.save()
     Signal.connect(
         signals.post_save,
         sender=Decision,
         receiver=decision_signal_handler,
         dispatch_uid=dispatch_uid
     )
     self.assertFalse(notifications.called)
Example #14
0
 def test_decision_form_omits_watchers(self):
     decision_form = DecisionForm()
     self.assertTrue("watcher" not in decision_form.fields,
                     "Decision form should not contain watchers")
Example #15
0
    def assert_decision_datepickers(self, field):
        form = DecisionForm()

        self.assertEquals(JQueryUIDateWidget, type(form.fields[field].widget))