Пример #1
0
    def test_submitter_can_change_workgroup_via_edit_page(self):
        # based on the idea that 'submitter' is set in ARISTOTLE_SETTINGS.WORKGROUP
        self.wg_other = models.Workgroup.objects.create(name="Test WG to move to")

        self.login_editor()
        response = self.client.get(reverse('aristotle:edit_item',args=[self.item1.id]))
        self.assertEqual(response.status_code,200)
        updated_item = utils.modeL_to_dict_with_change_time(response.context['item'])
        updated_item['workgroup'] = str(self.wg_other.pk)

        response = self.client.post(reverse('aristotle:edit_item',args=[self.item1.id]), updated_item)
        self.assertEqual(response.status_code,200)

        form = response.context['form']

        self.assertTrue('Select a valid choice.' in form.errors['workgroup'][0])

        self.wg_other.submitters.add(self.editor)

        response = self.client.post(reverse('aristotle:edit_item',args=[self.item1.id]), updated_item)
        self.assertEqual(response.status_code,302)

        updated_item['workgroup'] = str(self.wg2.pk)
        response = self.client.post(reverse('aristotle:edit_item',args=[self.item1.id]), updated_item)
        self.assertEqual(response.status_code,200)

        self.assertTrue('Select a valid choice.' in form.errors['workgroup'][0])
Пример #2
0
    def test_submitter_cannot_change_workgroup_via_edit_page(self):
        # based on the idea that 'submitter' is not set in ARISTOTLE_SETTINGS.WORKGROUP
        self.wg_other = models.Workgroup.objects.create(name="Test WG to move to")
        self.wg_other.submitters.add(self.editor)

        self.login_editor()
        response = self.client.get(reverse('aristotle:edit_item',args=[self.item1.id]))
        self.assertEqual(response.status_code,200)

        updated_item = utils.modeL_to_dict_with_change_time(response.context['item'])

        updated_item['workgroup'] = str(self.wg_other.pk)

        response = self.client.post(reverse('aristotle:edit_item',args=[self.item1.id]), updated_item)
        self.assertEqual(response.status_code,200)

        form = response.context['form']

        self.assertTrue('workgroup' in form.errors.keys())
        self.assertTrue(len(form.errors['workgroup'])==1)

        # Submitter is logged in, tries to move item - fails because
        self.assertFalse(perms.user_can_remove_from_workgroup(self.editor,self.item1.workgroup))
        self.assertTrue(form.errors['workgroup'][0] == WorkgroupVerificationMixin.cant_move_any_permission_error)

        updated_item['workgroup'] = str(self.wg2.pk)
        response = self.client.post(reverse('aristotle:edit_item',args=[self.item1.id]), updated_item)
        self.assertEqual(response.status_code,200)

        form = response.context['form']

        self.assertTrue('workgroup' in form.errors.keys())
        self.assertTrue(len(form.errors['workgroup'])==1)

        self.assertTrue('Select a valid choice.' in form.errors['workgroup'][0])
Пример #3
0
    def test_admin_can_change_workgroup_via_edit_page(self):
        # based on the idea that 'admin' is set in ARISTOTLE_SETTINGS.WORKGROUP
        self.wg_other = models.Workgroup.objects.create(name="Test WG to move to")

        self.login_superuser()
        response = self.client.get(reverse('aristotle:edit_item',args=[self.item1.id]))
        self.assertEqual(response.status_code,200)
        updated_item = utils.modeL_to_dict_with_change_time(self.item1)
        updated_item['workgroup'] = str(self.wg_other.pk)

        response = self.client.post(reverse('aristotle:edit_item',args=[self.item1.id]), updated_item)
        self.assertEqual(response.status_code,302)

        updated_item = utils.modeL_to_dict_with_change_time(self.item1)
        updated_item['workgroup'] = str(self.wg2.pk)
        response = self.client.post(reverse('aristotle:edit_item',args=[self.item1.id]), updated_item)
        self.assertEqual(response.status_code,302)
Пример #4
0
    def test_user_recent_dashboard_panel(self):

        self.login_editor()

        response = self.client.get(reverse('aristotle:userHome', ))
        self.assertEqual(response.status_code, 200)
        self.assertEqual(len(response.context['recent']), 0)

        wizard_url = reverse('aristotle:createItem',
                             args=['aristotle_mdr', 'objectclass'])
        wizard_form_name = "dynamic_aristotle_wizard"

        step_1_data = {
            wizard_form_name + '-current_step': 'initial',
            'initial-name': "Test Item"
        }

        response = self.client.post(wizard_url, step_1_data)
        self.assertFalse(
            models._concept.objects.filter(name="Test Item").exists())
        step_2_data = {
            wizard_form_name + '-current_step': 'results',
            'results-name': "Test Item",
            'results-definition': "Test Definition",
            'results-workgroup': self.wg1.pk
        }
        response = self.client.post(wizard_url, step_2_data)
        self.assertTrue(
            models._concept.objects.filter(name="Test Item").exists())
        self.assertEqual(
            models._concept.objects.filter(name="Test Item").count(), 1)
        item = models._concept.objects.filter(name="Test Item").first()

        from reversion.models import Revision

        response = self.client.get(reverse('aristotle:userHome'))
        self.assertEqual(response.status_code, 200)
        self.assertEqual(len(response.context['recent']),
                         Revision.objects.filter(user=self.editor).count())

        # Lets update an item so there is some recent history
        updated_item = utils.modeL_to_dict_with_change_time(item)
        updated_name = updated_item['name'] + " updated!"
        updated_item['name'] = updated_name
        response = self.client.post(
            reverse('aristotle:edit_item', args=[item.id]), updated_item)
        self.assertEqual(response.status_code, 302)

        response = self.client.get(reverse('aristotle:userHome', ))
        self.assertEqual(response.status_code, 200)
        self.assertEqual(len(response.context['recent']),
                         Revision.objects.filter(user=self.editor).count())

        self.assertContains(response, "Changed name")
Пример #5
0
    def test_manager_of_two_workgroups_can_change_workgroup_via_edit_page(self):
        # based on the idea that 'manager' is set in ARISTOTLE_SETTINGS.WORKGROUP
        self.wg_other = models.Workgroup.objects.create(name="Test WG to move to")
        self.wg_other.submitters.add(self.editor)

        self.login_editor()
        response = self.client.get(reverse('aristotle:edit_item',args=[self.item1.id]))
        self.assertEqual(response.status_code,200)
        updated_item = utils.modeL_to_dict_with_change_time(response.context['item'])
        updated_item['workgroup'] = str(self.wg_other.pk)
        response = self.client.post(reverse('aristotle:edit_item',args=[self.item1.id]), updated_item)
        self.assertEqual(response.status_code,200)

        form = response.context['form']
        # Submitter can't move because they aren't a manager of any workgroups.
        self.assertTrue(form.errors['workgroup'][0] == WorkgroupVerificationMixin.cant_move_any_permission_error)

        self.wg_other.managers.add(self.editor)

        response = self.client.post(reverse('aristotle:edit_item',args=[self.item1.id]), updated_item)
        self.assertEqual(response.status_code,200)

        form = response.context['form']
        # Submitter can't move because they aren't a manager of the workgroup the item is in.
        self.assertTrue(form.errors['workgroup'][0] == WorkgroupVerificationMixin.cant_move_from_permission_error)


        self.login_manager()

        response = self.client.post(reverse('aristotle:edit_item',args=[self.item1.id]), updated_item)
        self.assertEqual(response.status_code,403)

        self.wg1.submitters.add(self.manager) # Need to give manager edit permission to allow them to actually edit things
        response = self.client.post(reverse('aristotle:edit_item',args=[self.item1.id]), updated_item)
        self.assertEqual(response.status_code,200)
        form = response.context['form']

        self.assertTrue('Select a valid choice.' in form.errors['workgroup'][0])

        self.wg_other.managers.add(self.manager)

        response = self.client.post(reverse('aristotle:edit_item',args=[self.item1.id]), updated_item)
        self.assertEqual(response.status_code,200)
        self.assertTrue('Select a valid choice.' in form.errors['workgroup'][0])

        self.wg_other.submitters.add(self.manager) # Need to give manager edit permission to allow them to actually edit things
        response = self.client.post(reverse('aristotle:edit_item',args=[self.item1.id]), updated_item)
        self.assertEqual(response.status_code,302)

        updated_item['workgroup'] = str(self.wg2.pk)
        response = self.client.post(reverse('aristotle:edit_item',args=[self.item1.id]), updated_item)
        self.assertEqual(response.status_code,200)

        self.assertTrue('Select a valid choice.' in form.errors['workgroup'][0])
Пример #6
0
    def test_submitter_can_save_via_edit_page(self):
        self.login_editor()
        response = self.client.get(reverse('aristotle:edit_item',args=[self.item1.id]))
        self.assertEqual(response.status_code,200)

        updated_item = utils.modeL_to_dict_with_change_time(response.context['item'])
        updated_name = updated_item['name'] + " updated!"
        updated_item['name'] = updated_name
        response = self.client.post(reverse('aristotle:edit_item',args=[self.item1.id]), updated_item)
        self.item1 = self.itemType.objects.get(pk=self.item1.pk)
        self.assertRedirects(response,url_slugify_concept(self.item1))
        self.assertEqual(self.item1.name,updated_name)
    def test_user_recent_dashboard_panel(self):

        self.login_editor()

        response = self.client.get(reverse('aristotle:userHome',))
        self.assertEqual(response.status_code, 200)
        self.assertEqual(len(response.context['recent']), 0)

        wizard_url = reverse('aristotle:createItem', args=['aristotle_mdr', 'objectclass'])
        wizard_form_name = "dynamic_aristotle_wizard"

        step_1_data = {
            wizard_form_name + '-current_step': 'initial',
            'initial-name': "Test Item"
        }

        response = self.client.post(wizard_url, step_1_data)
        self.assertFalse(models._concept.objects.filter(name="Test Item").exists())
        step_2_data = {
            wizard_form_name + '-current_step': 'results',
            'results-name': "Test Item",
            'results-definition': "Test Definition",
            'results-workgroup': self.wg1.pk
        }
        response = self.client.post(wizard_url, step_2_data)
        self.assertTrue(models._concept.objects.filter(name="Test Item").exists())
        self.assertEqual(models._concept.objects.filter(name="Test Item").count(), 1)
        item = models._concept.objects.filter(name="Test Item").first()

        from reversion.models import Revision

        response = self.client.get(reverse('aristotle:userHome'))
        self.assertEqual(response.status_code, 200)
        self.assertEqual(
            len(response.context['recent']),
            Revision.objects.filter(user=self.editor).count()
        )

        # Lets update an item so there is some recent history
        updated_item = utils.modeL_to_dict_with_change_time(item)
        updated_name = updated_item['name'] + " updated!"
        updated_item['name'] = updated_name
        response = self.client.post(reverse('aristotle:edit_item', args=[item.id]), updated_item)
        self.assertEqual(response.status_code, 302)

        response = self.client.get(reverse('aristotle:userHome',))
        self.assertEqual(response.status_code, 200)
        self.assertEqual(len(response.context['recent']), Revision.objects.filter(user=self.editor).count())

        self.assertContains(response, "Changed name")
Пример #8
0
    def test_submitter_cannot_save_via_edit_page_if_other_saves_made(self):
        from datetime import timedelta
        self.login_editor()
        modified = self.item1.modified
        response = self.client.get(reverse('aristotle:edit_item',args=[self.item1.id]))
        self.assertEqual(response.status_code,200)

        # fake that we fetched the page seconds before modification
        updated_item = utils.modeL_to_dict_with_change_time(response.context['item'],fetch_time=modified-timedelta(seconds=5))
        updated_name = updated_item['name'] + " updated!"
        updated_item['name'] = updated_name
        change_comment = "I changed this because I can"
        updated_item['change_comments'] = change_comment
        time_before_response = timezone.now()
        response = self.client.post(reverse('aristotle:edit_item',args=[self.item1.id]), updated_item)

        self.assertEqual(response.status_code,200)
        form = response.context['form']
        self.assertTrue(form.errors['last_fetched'][0] == CheckIfModifiedMixin.modified_since_form_fetched_error)

        # When sending a response with a bad last_fetch, the new one should come back right
        self.assertTrue(time_before_response < form.fields['last_fetched'].initial)

        # With the new last_fetched we can submit ok!
        updated_item['last_fetched'] = form.fields['last_fetched'].initial
        response = self.client.post(reverse('aristotle:edit_item',args=[self.item1.id]), updated_item)
        self.assertEqual(response.status_code,302)


        updated_item.pop('last_fetched')
        time_before_response = timezone.now()
        response = self.client.post(reverse('aristotle:edit_item',args=[self.item1.id]), updated_item)

        self.assertEqual(response.status_code,200)
        form = response.context['form']
        self.assertTrue(form.errors['last_fetched'][0] == CheckIfModifiedMixin.modified_since_field_missing)
        # When sending a response with no last_fetch, the new one should come back right
        self.assertTrue(time_before_response < form.fields['last_fetched'].initial)

        # With the new last_fetched we can submit ok!
        updated_item['last_fetched'] = form.fields['last_fetched'].initial
        response = self.client.post(reverse('aristotle:edit_item',args=[self.item1.id]), updated_item)
        self.assertEqual(response.status_code,302)