コード例 #1
0
class SupportMotion(TestCase):
    """
    Tests supporting a motion.
    """
    def setUp(self):
        self.admin = get_user_model().objects.get(username='******')
        self.admin.groups.add(2)
        self.client.login(username='******', password='******')
        self.motion = Motion(title='test_title_chee7ahCha6bingaew4e',
                             text='test_text_birah1theL9ooseeFaip')
        self.motion.save()

    def test_support(self):
        config['motions_min_supporters'] = 1
        get_redis_connection('default').flushall()
        response = self.client.post(
            reverse('motion-support', args=[self.motion.pk]))
        self.assertEqual(response.status_code, status.HTTP_200_OK)
        self.assertEqual(
            response.data,
            {'detail': 'You have supported this motion successfully.'})

    def test_unsupport(self):
        config['motions_min_supporters'] = 1
        self.motion.supporters.add(self.admin)
        response = self.client.delete(
            reverse('motion-support', args=[self.motion.pk]))
        self.assertEqual(response.status_code, status.HTTP_200_OK)
        self.assertEqual(
            response.data,
            {'detail': 'You have unsupported this motion successfully.'})
コード例 #2
0
class CreateMotionPoll(TestCase):
    """
    Tests creating polls of motions.
    """
    def setUp(self):
        self.client = APIClient()
        self.client.login(username='******', password='******')
        self.motion = Motion(title='test_title_Aiqueigh2dae9phabiqu',
                             text='test_text_Neekoh3zou6li5rue8iL')
        self.motion.save()

    def test_create_first_poll_with_values_then_second_poll_without(self):
        self.poll = self.motion.create_poll()
        self.poll.set_vote_objects_with_values(self.poll.get_options().get(), {
            'Yes': 42,
            'No': 43,
            'Abstain': 44
        })
        response = self.client.post(
            reverse('motion-create-poll', args=[self.motion.pk]))
        self.assertEqual(self.motion.polls.count(), 2)
        response = self.client.get(
            reverse('motion-detail', args=[self.motion.pk]))
        for key in ('yes', 'no', 'abstain'):
            self.assertTrue(response.data['polls'][1][key] is None,
                            'Vote value "{}" should be None.'.format(key))
コード例 #3
0
class DeleteMotion(TestCase):
    """
    Tests deleting motions.
    """
    def setUp(self):
        self.client = APIClient()
        self.client.login(username="******", password="******")
        self.admin = get_user_model().objects.get(username="******")
        self.motion = Motion(
            title="test_title_acle3fa93l11lwlkcc31",
            text="test_text_f390sjfyycj29ss56sro",
        )
        self.motion.save()

    def test_simple_delete(self):
        response = self.client.delete(
            reverse("motion-detail", args=[self.motion.pk]))
        self.assertEqual(response.status_code, status.HTTP_204_NO_CONTENT)
        motions = Motion.objects.count()
        self.assertEqual(motions, 0)

    def make_admin_delegate(self):
        self.admin.groups.remove(GROUP_ADMIN_PK)
        self.admin.groups.add(GROUP_DELEGATE_PK)
        inform_changed_data(self.admin)

    def put_motion_in_complex_workflow(self):
        workflow = Workflow.objects.get(name="Complex Workflow")
        self.motion.reset_state(workflow=workflow)
        self.motion.save()

    def test_delete_foreign_motion_as_delegate(self):
        self.make_admin_delegate()
        self.put_motion_in_complex_workflow()

        response = self.client.delete(
            reverse("motion-detail", args=[self.motion.pk]))
        self.assertEqual(response.status_code, status.HTTP_403_FORBIDDEN)

    def test_delete_own_motion_as_delegate(self):
        self.make_admin_delegate()
        self.put_motion_in_complex_workflow()
        Submitter.objects.add(self.admin, self.motion)

        response = self.client.delete(
            reverse("motion-detail", args=[self.motion.pk]))
        self.assertEqual(response.status_code, status.HTTP_204_NO_CONTENT)
        motions = Motion.objects.count()
        self.assertEqual(motions, 0)

    def test_delete_with_two_change_recommendations(self):
        self.cr1 = MotionChangeRecommendation.objects.create(
            motion=self.motion, internal=False, line_from=1, line_to=1)
        self.cr2 = MotionChangeRecommendation.objects.create(
            motion=self.motion, internal=False, line_from=2, line_to=2)
        response = self.client.delete(
            reverse("motion-detail", args=[self.motion.pk]))
        self.assertEqual(response.status_code, status.HTTP_204_NO_CONTENT)
        motions = Motion.objects.count()
        self.assertEqual(motions, 0)
コード例 #4
0
class SupportMotion(TestCase):
    """
    Tests supporting a motion.
    """

    def setUp(self):
        self.admin = get_user_model().objects.get(username="******")
        self.admin.groups.add(GROUP_DELEGATE_PK)
        inform_changed_data(self.admin)
        self.client.login(username="******", password="******")
        self.motion = Motion(
            title="test_title_chee7ahCha6bingaew4e",
            text="test_text_birah1theL9ooseeFaip",
        )
        self.motion.save()

    def test_support(self):
        config["motions_min_supporters"] = 1

        response = self.client.post(reverse("motion-support", args=[self.motion.pk]))
        self.assertEqual(response.status_code, status.HTTP_200_OK)
        self.assertEqual(
            response.data, {"detail": "You have supported this motion successfully."}
        )

    def test_unsupport(self):
        config["motions_min_supporters"] = 1
        self.motion.supporters.add(self.admin)
        response = self.client.delete(reverse("motion-support", args=[self.motion.pk]))
        self.assertEqual(response.status_code, status.HTTP_200_OK)
        self.assertEqual(
            response.data, {"detail": "You have unsupported this motion successfully."}
        )
コード例 #5
0
ファイル: test_viewset.py プロジェクト: funakura/OpenSlides
    def test_delete_with_existing_comments(self):
        """
        Delete a section with existing comments. This should fail, because sections
        are protected.
        """
        section = MotionCommentSection(name="test_name_ecMCq;ymwuZZ723kD)2k")
        section.save()

        motion = Motion(
            title="test_title_SlqfMw(waso0saWMPqcZ",
            text="test_text_f30skclqS9wWF=xdfaSL",
        )
        motion.save()

        comment = MotionComment(comment="test_comment_dlkMD23m)(D9020m0/Zd",
                                motion=motion,
                                section=section)
        comment.save()

        response = self.client.delete(
            reverse("motioncommentsection-detail", args=[section.pk]))
        self.assertEqual(response.data["args"][0],
                         '"test_title_SlqfMw(waso0saWMPqcZ"')
        self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)
        self.assertEqual(MotionCommentSection.objects.count(), 1)
コード例 #6
0
ファイル: test_viewset.py プロジェクト: lesteenman/OpenSlides
class SupportMotion(TestCase):
    """
    Tests supporting a motion.
    """
    def setUp(self):
        self.admin = get_user_model().objects.get(username='******')
        self.admin.groups.add(2)
        self.client.login(username='******', password='******')
        self.motion = Motion(
            title='test_title_chee7ahCha6bingaew4e',
            text='test_text_birah1theL9ooseeFaip')
        self.motion.save()

    def test_support(self):
        config['motions_min_supporters'] = 1
        response = self.client.post(reverse('motion-support', args=[self.motion.pk]))
        self.assertEqual(response.status_code, status.HTTP_200_OK)
        self.assertEqual(response.data, {'detail': 'You have supported this motion successfully.'})

    def test_unsupport(self):
        config['motions_min_supporters'] = 1
        self.motion.supporters.add(self.admin)
        response = self.client.delete(reverse('motion-support', args=[self.motion.pk]))
        self.assertEqual(response.status_code, status.HTTP_200_OK)
        self.assertEqual(response.data, {'detail': 'You have unsupported this motion successfully.'})
コード例 #7
0
class SetState(TestCase):
    """
    Tests setting a state.
    """
    def setUp(self):
        self.client = APIClient()
        self.client.login(username='******', password='******')
        self.motion = Motion(title='test_title_iac4ohquie9Ku6othieC',
                             text='test_text_Xohphei6Oobee0Evooyu')
        self.motion.save()
        self.state_id_accepted = 2  # This should be the id of the state 'accepted'.

    def test_set_state(self):
        response = self.client.put(
            reverse('motion-set-state', args=[self.motion.pk]),
            {'state': self.state_id_accepted})

        self.assertEqual(response.status_code, status.HTTP_200_OK)
        self.assertEqual(
            response.data,
            {'detail': 'The state of the motion was set to accepted.'})
        self.assertEqual(
            Motion.objects.get(pk=self.motion.pk).state.name, 'accepted')

    def test_set_state_with_string(self):
        # Using a string is not allowed even if it is the correct name of the state.
        response = self.client.put(
            reverse('motion-set-state', args=[self.motion.pk]),
            {'state': 'accepted'})
        self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)
        self.assertEqual(response.data,
                         {'detail': 'Invalid data. State must be an integer.'})

    def test_set_unknown_state(self):
        invalid_state_id = 0
        response = self.client.put(
            reverse('motion-set-state', args=[self.motion.pk]),
            {'state': invalid_state_id})
        self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)
        self.assertEqual(
            response.data,
            {'detail': 'You can not set the state to %d.' % invalid_state_id})

    def test_reset(self):
        self.motion.set_state(self.state_id_accepted)
        self.motion.save()
        response = self.client.put(
            reverse('motion-set-state', args=[self.motion.pk]))
        self.assertEqual(response.status_code, status.HTTP_200_OK)
        self.assertEqual(
            response.data,
            {'detail': 'The state of the motion was set to submitted.'})
        self.assertEqual(
            Motion.objects.get(pk=self.motion.pk).state.name, 'submitted')
コード例 #8
0
ファイル: test_viewset.py プロジェクト: topelrapha/OpenSlides
 def test_existing_identifier_no_category(self):
     # config["motions_identifier_with_blank"] = True
     conflicting_motion = Motion(
         title="test_title_al2=2k21fjv1lsck3ehlWExg",
         text="test_text_3omvpEhnfg082ejplk1m",
     )
     conflicting_motion.save()
     conflicting_motion.identifier = "test_C3-2-1"
     conflicting_motion.save()
     response = self.client.post(reverse("category-numbering", args=[self.A.pk]))
     self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)
     self.assertEqual("test_C3-2-1", response.data["args"][0])
コード例 #9
0
class ManageVersion(TestCase):
    """
    Tests permitting and deleting versions.
    """
    def setUp(self):
        self.client = APIClient()
        self.client.login(username='******', password='******')
        self.motion = Motion(title='test_title_InieJ5HieZieg1Meid7K',
                             text='test_text_daePhougho7EenguWe4g')
        self.motion.save()
        self.version_2 = self.motion.get_new_version(
            title='new_title_fee7tef0seechazeefiW')
        self.motion.save(use_version=self.version_2)

    def test_permit(self):
        self.assertEqual(
            Motion.objects.get(
                pk=self.motion.pk).active_version.version_number, 2)
        response = self.client.put(
            reverse('motion-manage-version', args=[self.motion.pk]),
            {'version_number': '1'})
        self.assertEqual(response.status_code, status.HTTP_200_OK)
        self.assertEqual(response.data,
                         {'detail': 'Version 1 permitted successfully.'})
        self.assertEqual(
            Motion.objects.get(
                pk=self.motion.pk).active_version.version_number, 1)

    def test_permit_invalid_version(self):
        response = self.client.put(
            reverse('motion-manage-version', args=[self.motion.pk]),
            {'version_number': '3'})
        self.assertEqual(response.status_code, status.HTTP_404_NOT_FOUND)

    def test_delete(self):
        response = self.client.delete(
            reverse('motion-manage-version', args=[self.motion.pk]),
            {'version_number': '1'})
        self.assertEqual(response.status_code, status.HTTP_200_OK)
        self.assertEqual(response.data,
                         {'detail': 'Version 1 deleted successfully.'})
        self.assertEqual(
            Motion.objects.get(pk=self.motion.pk).versions.count(), 1)

    def test_delete_active_version(self):
        response = self.client.delete(
            reverse('motion-manage-version', args=[self.motion.pk]),
            {'version_number': '2'})
        self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)
        self.assertEqual(
            response.data,
            {'detail': 'You can not delete the active version of a motion.'})
コード例 #10
0
class FollowRecommendationsForMotionBlock(TestCase):
    """
    Tests following the recommendations of motions in an motion block.
    """
    def setUp(self):
        self.state_id_accepted = 2  # This should be the id of the state 'accepted'.
        self.state_id_rejected = 3  # This should be the id of the state 'rejected'.

        self.client = APIClient()
        self.client.login(username='******', password='******')

        self.motion_block = MotionBlock.objects.create(
            title='test_motion_block_name_Ufoopiub7quaezaepeic')

        self.motion = Motion(
            title='test_title_yo8ohy5eifeiyied2AeD',
            text='test_text_chi1aeth5faPhueQu8oh',
            motion_block=self.motion_block)
        self.motion.save()
        self.motion.set_recommendation(self.state_id_accepted)
        self.motion.save()

        self.motion_2 = Motion(
            title='test_title_eith0EemaW8ahZa9Piej',
            text='test_text_haeho1ohk3ou7pau2Jee',
            motion_block=self.motion_block)
        self.motion_2.save()
        self.motion_2.set_recommendation(self.state_id_rejected)
        self.motion_2.save()

    def test_follow_recommendations_for_motion_block(self):
        response = self.client.post(reverse('motionblock-follow-recommendations', args=[self.motion_block.pk]))
        self.assertEqual(response.status_code, status.HTTP_200_OK)
        self.assertEqual(Motion.objects.get(pk=self.motion.pk).state.id, self.state_id_accepted)
        self.assertEqual(Motion.objects.get(pk=self.motion_2.pk).state.id, self.state_id_rejected)
コード例 #11
0
class DeleteMotion(TestCase):
    """
    Tests deleting motions.
    """
    def setUp(self):
        self.client = APIClient()
        self.client.login(username='******', password='******')
        self.admin = get_user_model().objects.get(username='******')
        self.motion = Motion(title='test_title_acle3fa93l11lwlkcc31',
                             text='test_text_f390sjfyycj29ss56sro')
        self.motion.save()

    def test_simple_delete(self):
        response = self.client.delete(
            reverse('motion-detail', args=[self.motion.pk]))
        self.assertEqual(response.status_code, status.HTTP_204_NO_CONTENT)
        motions = Motion.objects.count()
        self.assertEqual(motions, 0)

    def make_admin_delegate(self):
        group_staff = self.admin.groups.get(name='Staff')
        group_delegates = Group.objects.get(name='Delegates')
        self.admin.groups.remove(group_staff)
        self.admin.groups.add(group_delegates)
        CollectionElement.from_instance(self.admin)

    def put_motion_in_complex_workflow(self):
        workflow = Workflow.objects.get(name='Complex Workflow')
        self.motion.reset_state(workflow=workflow)
        self.motion.save()

    def test_delete_foreign_motion_as_delegate(self):
        self.make_admin_delegate()
        self.put_motion_in_complex_workflow()

        response = self.client.delete(
            reverse('motion-detail', args=[self.motion.pk]))
        self.assertEqual(response.status_code, status.HTTP_403_FORBIDDEN)

    def test_delete_own_motion_as_delegate(self):
        self.make_admin_delegate()
        self.put_motion_in_complex_workflow()
        self.motion.submitters.add(self.admin)

        response = self.client.delete(
            reverse('motion-detail', args=[self.motion.pk]))
        self.assertEqual(response.status_code, status.HTTP_204_NO_CONTENT)
        motions = Motion.objects.count()
        self.assertEqual(motions, 0)
コード例 #12
0
class RetrieveMotion(TestCase):
    """
    Tests retrieving a motion (with poll results).
    """
    def setUp(self):
        self.client = APIClient()
        self.client.login(username='******', password='******')
        self.motion = Motion(title='test_title_uj5eeSiedohSh3ohyaaj',
                             text='test_text_ithohchaeThohmae5aug')
        self.motion.save()
        self.motion.create_poll()

    def test_number_of_queries(self):
        with self.assertNumQueries(17):
            self.client.get(reverse('motion-detail', args=[self.motion.pk]))
コード例 #13
0
ファイル: test_viewset.py プロジェクト: lesteenman/OpenSlides
class RetrieveMotion(TestCase):
    """
    Tests retrieving a motion (with poll results).
    """
    def setUp(self):
        self.client = APIClient()
        self.client.login(username='******', password='******')
        self.motion = Motion(
            title='test_title_uj5eeSiedohSh3ohyaaj',
            text='test_text_ithohchaeThohmae5aug')
        self.motion.save()
        self.motion.create_poll()

    def test_number_of_queries(self):
        with self.assertNumQueries(16):
            self.client.get(reverse('motion-detail', args=[self.motion.pk]))
コード例 #14
0
ファイル: test_viewset.py プロジェクト: funakura/OpenSlides
 def test_existing_identifier_with_category(self):
     conflicting_category = Category.objects.create(
         name="test_name_hpsodhakvjdbvkblwfjr")
     conflicting_motion = Motion(
         title="test_title_al2=2k21fjv1lsck3ehlWExg",
         text="test_text_3omvpEhnfg082ejplk1m",
         category=conflicting_category,
     )
     conflicting_motion.save()
     conflicting_motion.identifier = "test_C3-2-1"
     conflicting_motion.save()
     response = self.client.post(
         reverse("category-numbering", args=[self.A.pk]))
     self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)
     self.assertEqual("test_C3-2-1", response.data["args"][0])
     self.assertEqual(conflicting_category.name, response.data["args"][1])
コード例 #15
0
class RetrieveMotion(TestCase):
    """
    Tests retrieving a motion (with poll results).
    """
    def setUp(self):
        self.client = APIClient()
        self.client.login(username='******', password='******')
        self.motion = Motion(
            title='test_title_uj5eeSiedohSh3ohyaaj',
            text='test_text_ithohchaeThohmae5aug')
        self.motion.save()
        self.motion.create_poll()

    def test_number_of_queries(self):
        with self.assertNumQueries(16):
            self.client.get(reverse('motion-detail', args=[self.motion.pk]))

    def test__guest_state_with_required_permission_to_see(self):
        config['general_system_enable_anonymous'] = True
        guest_client = APIClient()
        state = self.motion.state
        state.required_permission_to_see = 'permission_that_the_user_does_not_have_leeceiz9hi7iuta4ahY2'
        state.save()
        response = guest_client.get(reverse('motion-detail', args=[self.motion.pk]))
        self.assertEqual(response.status_code, status.HTTP_403_FORBIDDEN)

    def test_admin_state_with_required_permission_to_see(self):
        state = self.motion.state
        state.required_permission_to_see = 'permission_that_the_user_does_not_have_coo1Iewu8Eing2xahfoo'
        state.save()
        response = self.client.get(reverse('motion-detail', args=[self.motion.pk]))
        self.assertEqual(response.status_code, status.HTTP_200_OK)

    def test_submitter_state_with_required_permission_to_see(self):
        state = self.motion.state
        state.required_permission_to_see = 'permission_that_the_user_does_not_have_eiW8af9caizoh1thaece'
        state.save()
        user = get_user_model().objects.create_user(
            username='******',
            password='******')
        self.motion.submitters.add(user)
        submitter_client = APIClient()
        submitter_client.login(
            username='******',
            password='******')
        response = submitter_client.get(reverse('motion-detail', args=[self.motion.pk]))
        self.assertEqual(response.status_code, status.HTTP_200_OK)
コード例 #16
0
 def create_motions(self, options):
     number_of_motions = options["motions"]
     if number_of_motions is None and not options["only"]:
         number_of_motions = DEFAULT_NUMBER
     if number_of_motions is not None and number_of_motions > 0:
         self.stdout.write(f"Start creating {number_of_motions} motions ...")
         text = ""
         for i in range(MOTION_NUMBER_OF_PARAGRAPHS):
             text += dedent(LOREM_IPSUM[i % 3])
         for i in range(number_of_motions):
             motion = Motion(title=get_random_string(20, self.chars), text=text)
             motion.save(skip_autoupdate=True)
         self.stdout.write(
             self.style.SUCCESS(f"{number_of_motions} motions successfully created.")
         )
     elif number_of_motions is not None and number_of_motions < 0:
         raise CommandError("Number for motions must not be negative.")
コード例 #17
0
 def create_motions(self, options):
     number_of_motions = options["motions"]
     if number_of_motions is None and not options["only"]:
         number_of_motions = DEFAULT_NUMBER
     if number_of_motions is not None and number_of_motions > 0:
         self.stdout.write(f"Start creating {number_of_motions} motions ...")
         text = ""
         for i in range(MOTION_NUMBER_OF_PARAGRAPHS):
             text += dedent(LOREM_IPSUM[i % 3])
         for i in range(number_of_motions):
             motion = Motion(title=get_random_string(20, self.chars), text=text)
             motion.save(skip_autoupdate=True)
         self.stdout.write(
             self.style.SUCCESS(f"{number_of_motions} motions successfully created.")
         )
     elif number_of_motions is not None and number_of_motions < 0:
         raise CommandError("Number for motions must not be negative.")
コード例 #18
0
ファイル: test_viewset.py プロジェクト: lesteenman/OpenSlides
class SetState(TestCase):
    """
    Tests setting a state.
    """
    def setUp(self):
        self.client = APIClient()
        self.client.login(username='******', password='******')
        self.motion = Motion(
            title='test_title_iac4ohquie9Ku6othieC',
            text='test_text_Xohphei6Oobee0Evooyu')
        self.motion.save()
        self.state_id_accepted = 2  # This should be the id of the state 'accepted'.

    def test_set_state(self):
        response = self.client.put(
            reverse('motion-set-state', args=[self.motion.pk]),
            {'state': self.state_id_accepted})

        self.assertEqual(response.status_code, status.HTTP_200_OK)
        self.assertEqual(response.data, {'detail': 'The state of the motion was set to accepted.'})
        self.assertEqual(Motion.objects.get(pk=self.motion.pk).state.name, 'accepted')

    def test_set_state_with_string(self):
        # Using a string is not allowed even if it is the correct name of the state.
        response = self.client.put(
            reverse('motion-set-state', args=[self.motion.pk]),
            {'state': 'accepted'})
        self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)
        self.assertEqual(response.data, {'detail': 'Invalid data. State must be an integer.'})

    def test_set_unknown_state(self):
        invalid_state_id = 0
        response = self.client.put(
            reverse('motion-set-state', args=[self.motion.pk]),
            {'state': invalid_state_id})
        self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)
        self.assertEqual(response.data, {'detail': 'You can not set the state to %d.' % invalid_state_id})

    def test_reset(self):
        self.motion.set_state(self.state_id_accepted)
        self.motion.save()
        response = self.client.put(reverse('motion-set-state', args=[self.motion.pk]))
        self.assertEqual(response.status_code, status.HTTP_200_OK)
        self.assertEqual(response.data, {'detail': 'The state of the motion was set to submitted.'})
        self.assertEqual(Motion.objects.get(pk=self.motion.pk).state.name, 'submitted')
コード例 #19
0
 def create_motions(self, options):
     number_of_motions = options['motions']
     if number_of_motions is None and not options['only']:
         number_of_motions = DEFAULT_NUMBER
     if number_of_motions is not None and number_of_motions > 0:
         self.stdout.write('Start creating {} motions ... (sorry, this might be slow) ...'.format(number_of_motions))
         text = ''
         for i in range(MOTION_NUMBER_OF_PARAGRAPHS):
             text += dedent(LOREM_IPSUM[i % 3])
         for i in range(number_of_motions):
             motion = Motion(
                 title=get_random_string(20, self.chars),
                 text=text,
             )
             motion.save(skip_autoupdate=True)
         self.stdout.write(self.style.SUCCESS('{} motions successfully created.'.format(number_of_motions)))
     elif number_of_motions is not None and number_of_motions < 0:
         raise CommandError('Number for motions must not be negative.')
コード例 #20
0
ファイル: test_pdf.py プロジェクト: lostwarrior404/OpenSlides
class AllMotionPDF(TestCase):
    """
    Tests creating a PDF of all motions.
    """
    def setUp(self):
        self.client.login(username='******', password='******')
        config['motions_identifier'] = 'manually'
        self.motion = Motion(title='test_title_Dik4jaey5ku6axee7Dai',
                             text='test_text_Auvie4euf2oang8ahcie')
        self.motion.save()
        self.motion2 = Motion(title='test_title_AeTheech6euf9siM8uey',
                              text='test_text_Cohsh2egaexae8eebiot',
                              identifier='42')
        self.motion2.save()

    def test_pdf_all_motions(self):
        response = self.client.get(reverse('motions_pdf'))
        self.assertEqual(response.status_code, status.HTTP_200_OK)
コード例 #21
0
ファイル: test_viewset.py プロジェクト: lesteenman/OpenSlides
class ManageVersion(TestCase):
    """
    Tests permitting and deleting versions.
    """
    def setUp(self):
        self.client = APIClient()
        self.client.login(username='******', password='******')
        self.motion = Motion(
            title='test_title_InieJ5HieZieg1Meid7K',
            text='test_text_daePhougho7EenguWe4g')
        self.motion.save()
        self.version_2 = self.motion.get_new_version(title='new_title_fee7tef0seechazeefiW')
        self.motion.save(use_version=self.version_2)

    def test_permit(self):
        self.assertEqual(Motion.objects.get(pk=self.motion.pk).active_version.version_number, 2)
        response = self.client.put(
            reverse('motion-manage-version', args=[self.motion.pk]),
            {'version_number': '1'})
        self.assertEqual(response.status_code, status.HTTP_200_OK)
        self.assertEqual(response.data, {'detail': 'Version 1 permitted successfully.'})
        self.assertEqual(Motion.objects.get(pk=self.motion.pk).active_version.version_number, 1)

    def test_permit_invalid_version(self):
        response = self.client.put(
            reverse('motion-manage-version', args=[self.motion.pk]),
            {'version_number': '3'})
        self.assertEqual(response.status_code, status.HTTP_404_NOT_FOUND)

    def test_delete(self):
        response = self.client.delete(
            reverse('motion-manage-version', args=[self.motion.pk]),
            {'version_number': '1'})
        self.assertEqual(response.status_code, status.HTTP_200_OK)
        self.assertEqual(response.data, {'detail': 'Version 1 deleted successfully.'})
        self.assertEqual(Motion.objects.get(pk=self.motion.pk).versions.count(), 1)

    def test_delete_active_version(self):
        response = self.client.delete(
            reverse('motion-manage-version', args=[self.motion.pk]),
            {'version_number': '2'})
        self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)
        self.assertEqual(response.data, {'detail': 'You can not delete the active version of a motion.'})
コード例 #22
0
class UpdateMotionPoll(TestCase):
    """
    Tests updating polls of motions.
    """
    def setUp(self):
        self.client = APIClient()
        self.client.login(username='******', password='******')
        self.motion = Motion(title='test_title_Aiqueigh2dae9phabiqu',
                             text='test_text_Neekoh3zou6li5rue8iL')
        self.motion.save()
        self.poll = self.motion.create_poll()

    def test_invalid_votesvalid_value(self):
        response = self.client.put(
            reverse('motionpoll-detail', args=[self.poll.pk]), {
                'motion_id': self.motion.pk,
                'votesvalid': '-3'
            })
        self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)

    def test_invalid_votesinvalid_value(self):
        response = self.client.put(
            reverse('motionpoll-detail', args=[self.poll.pk]), {
                'motion_id': self.motion.pk,
                'votesinvalid': '-3'
            })
        self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)

    def test_invalid_votescast_value(self):
        response = self.client.put(
            reverse('motionpoll-detail', args=[self.poll.pk]), {
                'motion_id': self.motion.pk,
                'votescast': '-3'
            })
        self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)

    def test_empty_value_for_votesvalid(self):
        response = self.client.put(
            reverse('motionpoll-detail', args=[self.poll.pk]), {
                'motion_id': self.motion.pk,
                'votesvalid': ''
            })
        self.assertEqual(response.status_code, status.HTTP_200_OK)
コード例 #23
0
ファイル: test_viewset.py プロジェクト: topelrapha/OpenSlides
    def setUp(self):
        self.client = APIClient()
        self.client.login(username="******", password="******")

        motion = Motion(
            title="test_title_3kd)K23,c9239mdj2wcG",
            text="test_text_f8FLP,gvprC;wovVEwlQ",
        )
        motion.save()

        self.public_cr = MotionChangeRecommendation(
            motion=motion, internal=False, line_from=1, line_to=1
        )
        self.public_cr.save()

        self.internal_cr = MotionChangeRecommendation(
            motion=motion, internal=True, line_from=2, line_to=2
        )
        self.internal_cr.save()
コード例 #24
0
ファイル: test_pdf.py プロジェクト: lesteenman/OpenSlides
class AllMotionPDF(TestCase):
    """
    Tests creating a PDF of all motions.
    """
    def setUp(self):
        self.client.login(username='******', password='******')
        config['motions_identifier'] = 'manually'
        self.motion = Motion(
            title='test_title_Dik4jaey5ku6axee7Dai',
            text='test_text_Auvie4euf2oang8ahcie')
        self.motion.save()
        self.motion2 = Motion(
            title='test_title_AeTheech6euf9siM8uey',
            text='test_text_Cohsh2egaexae8eebiot',
            identifier='42')
        self.motion2.save()

    def test_pdf_all_motions(self):
        response = self.client.get(reverse('motions_pdf'))
        self.assertEqual(response.status_code, status.HTTP_200_OK)
コード例 #25
0
ファイル: test_viewset.py プロジェクト: lesteenman/OpenSlides
class CreateMotionPoll(TestCase):
    """
    Tests creating polls of motions.
    """
    def setUp(self):
        self.client = APIClient()
        self.client.login(username='******', password='******')
        self.motion = Motion(
            title='test_title_Aiqueigh2dae9phabiqu',
            text='test_text_Neekoh3zou6li5rue8iL')
        self.motion.save()

    def test_create_first_poll_with_values_then_second_poll_without(self):
        self.poll = self.motion.create_poll()
        self.poll.set_vote_objects_with_values(self.poll.get_options().get(), {'Yes': 42, 'No': 43, 'Abstain': 44})
        response = self.client.post(
            reverse('motion-create-poll', args=[self.motion.pk]))
        self.assertEqual(self.motion.polls.count(), 2)
        response = self.client.get(reverse('motion-detail', args=[self.motion.pk]))
        for key in ('yes', 'no', 'abstain'):
            self.assertTrue(response.data['polls'][1][key] is None, 'Vote value "{}" should be None.'.format(key))
コード例 #26
0
ファイル: test_viewset.py プロジェクト: lesteenman/OpenSlides
class UpdateMotionPoll(TestCase):
    """
    Tests updating polls of motions.
    """
    def setUp(self):
        self.client = APIClient()
        self.client.login(username='******', password='******')
        self.motion = Motion(
            title='test_title_Aiqueigh2dae9phabiqu',
            text='test_text_Neekoh3zou6li5rue8iL')
        self.motion.save()
        self.poll = self.motion.create_poll()

    def test_invalid_votesvalid_value(self):
        response = self.client.put(
            reverse('motionpoll-detail', args=[self.poll.pk]),
            {'motion_id': self.motion.pk,
             'votesvalid': '-3'})
        self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)

    def test_invalid_votesinvalid_value(self):
        response = self.client.put(
            reverse('motionpoll-detail', args=[self.poll.pk]),
            {'motion_id': self.motion.pk,
             'votesinvalid': '-3'})
        self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)

    def test_invalid_votescast_value(self):
        response = self.client.put(
            reverse('motionpoll-detail', args=[self.poll.pk]),
            {'motion_id': self.motion.pk,
             'votescast': '-3'})
        self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)

    def test_empty_value_for_votesvalid(self):
        response = self.client.put(
            reverse('motionpoll-detail', args=[self.poll.pk]),
            {'motion_id': self.motion.pk,
             'votesvalid': ''})
        self.assertEqual(response.status_code, status.HTTP_200_OK)
コード例 #27
0
ファイル: test_viewset.py プロジェクト: topelrapha/OpenSlides
class DeleteWorkflow(TestCase):
    """
    Tests the deletion of workflows.
    """

    def setUp(self):
        self.client = APIClient()
        self.client.login(username="******", password="******")
        self.workflow = Workflow.objects.first()

    def test_simple_delete(self):
        response = self.client.delete(
            reverse("workflow-detail", args=[self.workflow.pk])
        )
        self.assertEqual(response.status_code, status.HTTP_204_NO_CONTENT)
        self.assertEqual(Workflow.objects.count(), 1)  # Just the other default one

    def test_delete_with_assigned_motions(self):
        self.motion = Motion(
            title="test_title_chee7ahCha6bingaew4e",
            text="test_text_birah1theL9ooseeFaip",
        )
        self.motion.reset_state(self.workflow)
        self.motion.save()

        response = self.client.delete(
            reverse("workflow-detail", args=[self.workflow.pk])
        )
        self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)
        self.assertEqual(Workflow.objects.count(), 2)

    def test_delete_last_workflow(self):
        self.workflow.delete()
        other_workflow_pk = Workflow.objects.get().pk
        response = self.client.delete(
            reverse("workflow-detail", args=[other_workflow_pk])
        )
        self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)
        self.assertEqual(Workflow.objects.count(), 1)  # Just the other default one
コード例 #28
0
 def create_motions(self, options):
     number_of_motions = options['motions']
     if number_of_motions is None and not options['only']:
         number_of_motions = DEFAULT_NUMBER
     if number_of_motions is not None and number_of_motions > 0:
         self.stdout.write(
             'Start creating {} motions ... (sorry, this might be slow) ...'
             .format(number_of_motions))
         text = ''
         for i in range(MOTION_NUMBER_OF_PARAGRAPHS):
             text += dedent(LOREM_IPSUM[i % 3])
         for i in range(number_of_motions):
             motion = Motion(
                 title=get_random_string(20, self.chars),
                 text=text,
             )
             motion.save(skip_autoupdate=True)
         self.stdout.write(
             self.style.SUCCESS('{} motions successfully created.'.format(
                 number_of_motions)))
     elif number_of_motions is not None and number_of_motions < 0:
         raise CommandError('Number for motions must not be negative.')
コード例 #29
0
ファイル: test_viewset.py プロジェクト: topelrapha/OpenSlides
class FollowRecommendationsForMotionBlock(TestCase):
    """
    Tests following the recommendations of motions in an motion block.
    """

    def setUp(self):
        self.state_id_accepted = 2  # This should be the id of the state 'accepted'.
        self.state_id_rejected = 3  # This should be the id of the state 'rejected'.

        self.client = APIClient()
        self.client.login(username="******", password="******")

        self.motion_block = MotionBlock.objects.create(
            title="test_motion_block_name_Ufoopiub7quaezaepeic"
        )

        self.motion = Motion(
            title="test_title_yo8ohy5eifeiyied2AeD",
            text="test_text_chi1aeth5faPhueQu8oh",
            motion_block=self.motion_block,
        )
        self.motion.save()
        self.motion.set_recommendation(self.state_id_accepted)
        self.motion.save()

        self.motion_2 = Motion(
            title="test_title_eith0EemaW8ahZa9Piej",
            text="test_text_haeho1ohk3ou7pau2Jee",
            motion_block=self.motion_block,
        )
        self.motion_2.save()
        self.motion_2.set_recommendation(self.state_id_rejected)
        self.motion_2.save()

    def test_follow_recommendations_for_motion_block(self):
        response = self.client.post(
            reverse("motionblock-follow-recommendations", args=[self.motion_block.pk])
        )
        self.assertEqual(response.status_code, status.HTTP_200_OK)
        self.assertEqual(
            Motion.objects.get(pk=self.motion.pk).state.id, self.state_id_accepted
        )
        self.assertEqual(
            Motion.objects.get(pk=self.motion_2.pk).state.id, self.state_id_rejected
        )
コード例 #30
0
    def test_do_not_create_new_version_when_permit_old_version(self):
        motion = Motion()
        motion.title = 'foo'
        motion.text = 'bar'
        motion.save()
        first_version = motion.get_last_version()

        motion = Motion.objects.get(pk=motion.pk)
        motion.title = 'New Title'
        motion.save(use_version=motion.get_new_version())
        new_version = motion.get_last_version()
        self.assertEqual(motion.versions.count(), 2)

        motion.active_version = new_version
        motion.save()
        self.assertEqual(motion.versions.count(), 2)

        motion.active_version = first_version
        motion.save(use_version=False)
        self.assertEqual(motion.versions.count(), 2)
コード例 #31
0
ファイル: test_models.py プロジェクト: munasharma/OpenSlides
    def test_do_not_create_new_version_when_permit_old_version(self):
        motion = Motion()
        motion.title = "foo"
        motion.text = "bar"
        motion.save()
        first_version = motion.get_last_version()

        motion = Motion.objects.get(pk=motion.pk)
        motion.title = "New Title"
        motion.save(use_version=motion.get_new_version())
        new_version = motion.get_last_version()
        self.assertEqual(motion.versions.count(), 2)

        motion.active_version = new_version
        motion.save()
        self.assertEqual(motion.versions.count(), 2)

        motion.active_version = first_version
        motion.save(use_version=False)
        self.assertEqual(motion.versions.count(), 2)
コード例 #32
0
ファイル: test_viewset.py プロジェクト: lesteenman/OpenSlides
class NumberMotionsInCategory(TestCase):
    """
    Tests numbering motions in a category.
    """
    def setUp(self):
        self.client = APIClient()
        self.client.login(username='******', password='******')
        self.category = Category.objects.create(
            name='test_cateogory_name_zah6Ahd4Ifofaeree6ai',
            prefix='test_prefix_ahz6tho2mooH8')
        self.motion = Motion(
            title='test_title_Eeha8Haf6peulu8ooc0z',
            text='test_text_faghaZoov9ooV4Acaquk',
            category=self.category)
        self.motion.save()
        self.motion.identifier = ''
        self.motion.save()
        self.motion_2 = Motion(
            title='test_title_kuheih2eja2Saeshusha',
            text='test_text_Ha5ShaeraeSuthooP2Bu',
            category=self.category)
        self.motion_2.save()
        self.motion_2.identifier = ''
        self.motion_2.save()

    def test_numbering(self):
        response = self.client.post(
            reverse('category-numbering', args=[self.category.pk]))
        self.assertEqual(response.status_code, status.HTTP_200_OK)
        self.assertEqual(response.data, {'detail': 'All motions in category test_cateogory_name_zah6Ahd4Ifofaeree6ai numbered successfully.'})
        self.assertEqual(Motion.objects.get(pk=self.motion.pk).identifier, 'test_prefix_ahz6tho2mooH8 1')
        self.assertEqual(Motion.objects.get(pk=self.motion_2.pk).identifier, 'test_prefix_ahz6tho2mooH8 2')

    def test_numbering_existing_identifier(self):
        self.motion_2.identifier = 'test_prefix_ahz6tho2mooH8 1'
        self.motion_2.save()
        response = self.client.post(
            reverse('category-numbering', args=[self.category.pk]))
        self.assertEqual(response.status_code, status.HTTP_200_OK)
        self.assertEqual(response.data, {'detail': 'All motions in category test_cateogory_name_zah6Ahd4Ifofaeree6ai numbered successfully.'})
        self.assertEqual(Motion.objects.get(pk=self.motion.pk).identifier, 'test_prefix_ahz6tho2mooH8 1')
        self.assertEqual(Motion.objects.get(pk=self.motion_2.pk).identifier, 'test_prefix_ahz6tho2mooH8 2')

    def test_numbering_with_given_order(self):
        self.motion_3 = Motion(
            title='test_title_eeb0kua5ciike4su2auJ',
            text='test_text_ahshuGhaew3eim8yoht7',
            category=self.category)
        self.motion_3.save()
        self.motion_3.identifier = ''
        self.motion_3.save()
        response = self.client.post(
            reverse('category-numbering', args=[self.category.pk]),
            {'motions': [3, 2]},
            format='json')
        self.assertEqual(response.status_code, status.HTTP_200_OK)
        self.assertEqual(response.data, {'detail': 'All motions in category test_cateogory_name_zah6Ahd4Ifofaeree6ai numbered successfully.'})
        self.assertEqual(Motion.objects.get(pk=self.motion.pk).identifier, None)
        self.assertEqual(Motion.objects.get(pk=self.motion_2.pk).identifier, 'test_prefix_ahz6tho2mooH8 2')
        self.assertEqual(Motion.objects.get(pk=self.motion_3.pk).identifier, 'test_prefix_ahz6tho2mooH8 1')
コード例 #33
0
class SetState(TestCase):
    """
    Tests setting a state.
    """

    def setUp(self):
        self.client = APIClient()
        self.client.login(username="******", password="******")
        self.motion = Motion(
            title="test_title_iac4ohquie9Ku6othieC",
            text="test_text_Xohphei6Oobee0Evooyu",
        )
        self.motion.save()
        self.state_id_accepted = 2  # This should be the id of the state 'accepted'.

    def test_set_state(self):
        response = self.client.put(
            reverse("motion-set-state", args=[self.motion.pk]),
            {"state": self.state_id_accepted},
        )

        self.assertEqual(response.status_code, status.HTTP_200_OK)
        self.assertEqual(
            response.data, {"detail": "The state of the motion was set to accepted."}
        )
        self.assertEqual(Motion.objects.get(pk=self.motion.pk).state.name, "accepted")

    def test_set_state_with_string(self):
        # Using a string is not allowed even if it is the correct name of the state.
        response = self.client.put(
            reverse("motion-set-state", args=[self.motion.pk]), {"state": "accepted"}
        )
        self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)
        self.assertEqual(
            response.data, {"detail": "Invalid data. State must be an integer."}
        )

    def test_set_unknown_state(self):
        invalid_state_id = 0
        response = self.client.put(
            reverse("motion-set-state", args=[self.motion.pk]),
            {"state": invalid_state_id},
        )
        self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)
        self.assertEqual(
            response.data,
            {
                "detail": "You can not set the state to {0}.",
                "args": [str(invalid_state_id)],
            },
        )

    def test_reset(self):
        self.motion.set_state(self.state_id_accepted)
        self.motion.save()
        response = self.client.put(reverse("motion-set-state", args=[self.motion.pk]))
        self.assertEqual(response.status_code, status.HTTP_200_OK)
        self.assertEqual(
            response.data, {"detail": "The state of the motion was set to submitted."}
        )
        self.assertEqual(Motion.objects.get(pk=self.motion.pk).state.name, "submitted")
コード例 #34
0
class SetRecommendation(TestCase):
    """
    Tests setting a recommendation.
    """

    def setUp(self):
        self.client = APIClient()
        self.client.login(username="******", password="******")
        self.motion = Motion(
            title="test_title_ahfooT5leilahcohJ2uz",
            text="test_text_enoogh7OhPoo6eohoCus",
        )
        self.motion.save()
        self.state_id_accepted = 2  # This should be the id of the state 'accepted'.

    def test_set_recommendation(self):
        response = self.client.put(
            reverse("motion-set-recommendation", args=[self.motion.pk]),
            {"recommendation": self.state_id_accepted},
        )
        self.assertEqual(response.status_code, status.HTTP_200_OK)
        self.assertEqual(
            response.data,
            {
                "detail": "The recommendation of the motion was set to {0}.",
                "args": ["Acceptance"],
            },
        )
        self.assertEqual(
            Motion.objects.get(pk=self.motion.pk).recommendation.name, "accepted"
        )

    def test_set_state_with_string(self):
        # Using a string is not allowed even if it is the correct name of the state.
        response = self.client.put(
            reverse("motion-set-recommendation", args=[self.motion.pk]),
            {"recommendation": "accepted"},
        )
        self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)
        self.assertEqual(
            response.data,
            {"detail": "Invalid data. Recommendation must be an integer."},
        )

    def test_set_unknown_recommendation(self):
        invalid_state_id = 0
        response = self.client.put(
            reverse("motion-set-recommendation", args=[self.motion.pk]),
            {"recommendation": invalid_state_id},
        )
        self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)
        self.assertEqual(
            response.data,
            {
                "detail": "You can not set the recommendation to {0}.",
                "args": [str(invalid_state_id)],
            },
        )

    def test_set_invalid_recommendation(self):
        # This is a valid state id, but this state is not recommendable because it belongs to a different workflow.
        invalid_state_id = 6  # State 'permitted'
        response = self.client.put(
            reverse("motion-set-recommendation", args=[self.motion.pk]),
            {"recommendation": invalid_state_id},
        )
        self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)
        self.assertEqual(
            response.data,
            {
                "detail": "You can not set the recommendation to {0}.",
                "args": [str(invalid_state_id)],
            },
        )

    def test_set_invalid_recommendation_2(self):
        # This is a valid state id, but this state is not recommendable because it has not recommendation label
        invalid_state_id = 1  # State 'submitted'
        self.motion.set_state(self.state_id_accepted)
        self.motion.save()
        response = self.client.put(
            reverse("motion-set-recommendation", args=[self.motion.pk]),
            {"recommendation": invalid_state_id},
        )
        self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)
        self.assertEqual(
            response.data,
            {
                "detail": "You can not set the recommendation to {0}.",
                "args": [str(invalid_state_id)],
            },
        )

    def test_reset(self):
        self.motion.set_recommendation(self.state_id_accepted)
        self.motion.save()
        response = self.client.put(
            reverse("motion-set-recommendation", args=[self.motion.pk])
        )
        self.assertEqual(response.status_code, status.HTTP_200_OK)
        self.assertEqual(
            response.data,
            {
                "detail": "The recommendation of the motion was set to {0}.",
                "args": ["None"],
            },
        )
        self.assertTrue(Motion.objects.get(pk=self.motion.pk).recommendation is None)

    def test_set_recommendation_to_current_state(self):
        self.motion.set_state(self.state_id_accepted)
        self.motion.save()
        response = self.client.put(
            reverse("motion-set-recommendation", args=[self.motion.pk]),
            {"recommendation": self.state_id_accepted},
        )
        self.assertEqual(response.status_code, status.HTTP_200_OK)
        self.assertEqual(
            response.data,
            {
                "detail": "The recommendation of the motion was set to {0}.",
                "args": ["Acceptance"],
            },
        )
        self.assertEqual(
            Motion.objects.get(pk=self.motion.pk).recommendation.name, "accepted"
        )
コード例 #35
0
class ManageMultipleSubmitters(TestCase):
    """
    Tests adding and removing of submitters.
    """

    def setUp(self):
        self.client = APIClient()
        self.client.login(username="******", password="******")

        self.admin = get_user_model().objects.get()
        self.motion1 = Motion(
            title="test_title_SlqfMw(waso0saWMPqcZ",
            text="test_text_f30skclqS9wWF=xdfaSL",
        )
        self.motion1.save()
        self.motion2 = Motion(
            title="test_title_f>FLEim38MC2m9PFp2jG",
            text="test_text_kg39KFGm,ao)22FK9lLu",
        )
        self.motion2.save()

    def test_set_submitters(self):
        response = self.client.post(
            reverse("motion-manage-multiple-submitters"),
            json.dumps(
                {
                    "motions": [
                        {"id": self.motion1.id, "submitters": [self.admin.pk]},
                        {"id": self.motion2.id, "submitters": [self.admin.pk]},
                    ]
                }
            ),
            content_type="application/json",
        )
        self.assertEqual(response.status_code, 200)
        self.assertEqual(self.motion1.submitters.count(), 1)
        self.assertEqual(self.motion2.submitters.count(), 1)
        self.assertEqual(
            self.motion1.submitters.get().user.pk, self.motion2.submitters.get().user.pk
        )

    def test_non_existing_user(self):
        response = self.client.post(
            reverse("motion-manage-multiple-submitters"),
            {"motions": [{"id": self.motion1.id, "submitters": [1337]}]},
        )
        self.assertEqual(response.status_code, 400)
        self.assertEqual(self.motion1.submitters.count(), 0)

    def test_add_user_no_data(self):
        response = self.client.post(reverse("motion-manage-multiple-submitters"))
        self.assertEqual(response.status_code, 400)
        self.assertEqual(self.motion1.submitters.count(), 0)
        self.assertEqual(self.motion2.submitters.count(), 0)

    def test_add_user_invalid_data(self):
        response = self.client.post(
            reverse("motion-manage-multiple-submitters"), {"motions": ["invalid_str"]}
        )
        self.assertEqual(response.status_code, 400)
        self.assertEqual(self.motion1.submitters.count(), 0)
        self.assertEqual(self.motion2.submitters.count(), 0)

    def test_add_without_permission(self):
        admin = get_user_model().objects.get(username="******")
        admin.groups.add(GROUP_DELEGATE_PK)
        admin.groups.remove(GROUP_ADMIN_PK)
        inform_changed_data(admin)

        response = self.client.post(
            reverse("motion-manage-multiple-submitters"),
            {"motions": [{"id": self.motion1.id, "submitters": [self.admin.pk]}]},
        )
        self.assertEqual(response.status_code, 403)
        self.assertEqual(self.motion1.submitters.count(), 0)
        self.assertEqual(self.motion2.submitters.count(), 0)
コード例 #36
0
ファイル: test_viewset.py プロジェクト: lesteenman/OpenSlides
class SetRecommendation(TestCase):
    """
    Tests setting a recommendation.
    """
    def setUp(self):
        self.client = APIClient()
        self.client.login(username='******', password='******')
        self.motion = Motion(
            title='test_title_ahfooT5leilahcohJ2uz',
            text='test_text_enoogh7OhPoo6eohoCus')
        self.motion.save()
        self.state_id_accepted = 2  # This should be the id of the state 'accepted'.

    def test_set_recommendation(self):
        response = self.client.put(
            reverse('motion-set-recommendation', args=[self.motion.pk]),
            {'recommendation': self.state_id_accepted})
        self.assertEqual(response.status_code, status.HTTP_200_OK)
        self.assertEqual(response.data, {'detail': 'The recommendation of the motion was set to Acceptance.'})
        self.assertEqual(Motion.objects.get(pk=self.motion.pk).recommendation.name, 'accepted')

    def test_set_state_with_string(self):
        # Using a string is not allowed even if it is the correct name of the state.
        response = self.client.put(
            reverse('motion-set-recommendation', args=[self.motion.pk]),
            {'recommendation': 'accepted'})
        self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)
        self.assertEqual(response.data, {'detail': 'Invalid data. Recommendation must be an integer.'})

    def test_set_unknown_recommendation(self):
        invalid_state_id = 0
        response = self.client.put(
            reverse('motion-set-recommendation', args=[self.motion.pk]),
            {'recommendation': invalid_state_id})
        self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)
        self.assertEqual(response.data, {'detail': 'You can not set the recommendation to %d.' % invalid_state_id})

    def test_set_invalid_recommendation(self):
        # This is a valid state id, but this state is not recommendable because it belongs to a different workflow.
        invalid_state_id = 6  # State 'permitted'
        response = self.client.put(
            reverse('motion-set-recommendation', args=[self.motion.pk]),
            {'recommendation': invalid_state_id})
        self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)
        self.assertEqual(response.data, {'detail': 'You can not set the recommendation to %d.' % invalid_state_id})

    def test_set_invalid_recommendation_2(self):
        # This is a valid state id, but this state is not recommendable because it has not recommendation label
        invalid_state_id = 1  # State 'submitted'
        self.motion.set_state(self.state_id_accepted)
        self.motion.save()
        response = self.client.put(
            reverse('motion-set-recommendation', args=[self.motion.pk]),
            {'recommendation': invalid_state_id})
        self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)
        self.assertEqual(response.data, {'detail': 'You can not set the recommendation to %d.' % invalid_state_id})

    def test_reset(self):
        self.motion.set_recommendation(self.state_id_accepted)
        self.motion.save()
        response = self.client.put(reverse('motion-set-recommendation', args=[self.motion.pk]))
        self.assertEqual(response.status_code, status.HTTP_200_OK)
        self.assertEqual(response.data, {'detail': 'The recommendation of the motion was set to None.'})
        self.assertTrue(Motion.objects.get(pk=self.motion.pk).recommendation is None)

    def test_set_recommendation_to_current_state(self):
        self.motion.set_state(self.state_id_accepted)
        self.motion.save()
        response = self.client.put(
            reverse('motion-set-recommendation', args=[self.motion.pk]),
            {'recommendation': self.state_id_accepted})
        self.assertEqual(response.status_code, status.HTTP_200_OK)
        self.assertEqual(response.data, {'detail': 'The recommendation of the motion was set to Acceptance.'})
        self.assertEqual(Motion.objects.get(pk=self.motion.pk).recommendation.name, 'accepted')
コード例 #37
0
ファイル: test_viewset.py プロジェクト: lesteenman/OpenSlides
class UpdateMotion(TestCase):
    """
    Tests updating motions.
    """
    def setUp(self):
        self.client = APIClient()
        self.client.login(username='******', password='******')
        self.motion = Motion(
            title='test_title_aeng7ahChie3waiR8xoh',
            text='test_text_xeigheeha7thopubeu4U')
        self.motion.save()

    def test_simple_patch(self):
        response = self.client.patch(
            reverse('motion-detail', args=[self.motion.pk]),
            {'identifier': 'test_identifier_jieseghohj7OoSah1Ko9'})
        self.assertEqual(response.status_code, status.HTTP_200_OK)
        motion = Motion.objects.get()
        self.assertEqual(motion.title, 'test_title_aeng7ahChie3waiR8xoh')
        self.assertEqual(motion.identifier, 'test_identifier_jieseghohj7OoSah1Ko9')

    def test_patch_workflow(self):
        """
        Tests to only update the workflow of a motion.
        """
        response = self.client.patch(
            reverse('motion-detail', args=[self.motion.pk]),
            {'workflow_id': '2'})

        motion = Motion.objects.get()
        self.assertEqual(response.status_code, status.HTTP_200_OK)
        self.assertEqual(motion.title, 'test_title_aeng7ahChie3waiR8xoh')
        self.assertEqual(motion.workflow, 2)

    def test_patch_supporters(self):
        supporter = get_user_model().objects.create_user(
            username='******',
            password='******')
        response = self.client.patch(
            reverse('motion-detail', args=[self.motion.pk]),
            json.dumps({'supporters_id': [supporter.pk]}),
            content_type='application/json')
        self.assertEqual(response.status_code, status.HTTP_200_OK)
        motion = Motion.objects.get()
        self.assertEqual(motion.title, 'test_title_aeng7ahChie3waiR8xoh')
        self.assertEqual(motion.supporters.get().username, 'test_username_ieB9eicah0uqu6Phoovo')

    def test_patch_supporters_non_manager(self):
        non_admin = get_user_model().objects.create_user(
            username='******',
            password='******')
        self.client.login(
            username='******',
            password='******')
        motion = Motion.objects.get()
        motion.submitters.add(non_admin)
        motion.supporters.clear()
        response = self.client.patch(
            reverse('motion-detail', args=[self.motion.pk]),
            json.dumps({'supporters_id': [1]}),
            content_type='application/json')
        self.assertEqual(response.status_code, status.HTTP_200_OK)
        self.assertFalse(motion.supporters.exists())

    def test_removal_of_supporters(self):
        admin = get_user_model().objects.get(username='******')
        group_staff = admin.groups.get(name='Staff')
        admin.groups.remove(group_staff)
        self.motion.submitters.add(admin)
        supporter = get_user_model().objects.create_user(
            username='******',
            password='******')
        self.motion.supporters.add(supporter)
        config['motions_remove_supporters'] = True
        self.assertEqual(self.motion.supporters.count(), 1)

        response = self.client.patch(
            reverse('motion-detail', args=[self.motion.pk]),
            {'title': 'new_title_ohph1aedie5Du8sai2ye'})

        self.assertEqual(response.status_code, status.HTTP_200_OK)
        motion = Motion.objects.get()
        self.assertEqual(motion.title, 'new_title_ohph1aedie5Du8sai2ye')
        self.assertEqual(motion.supporters.count(), 0)

    def test_with_new_version(self):
        self.motion.set_state(State.objects.get(name='permitted'))
        self.motion.save()
        response = self.client.patch(
            reverse('motion-detail', args=[self.motion.pk]),
            {'text': 'test_text_aeb1iaghahChong5od3a'})
        self.assertEqual(response.status_code, status.HTTP_200_OK)
        motion = Motion.objects.get()
        self.assertEqual(motion.versions.count(), 2)

    def test_without_new_version(self):
        self.motion.set_state(State.objects.get(name='permitted'))
        self.motion.save()
        response = self.client.patch(
            reverse('motion-detail', args=[self.motion.pk]),
            {'text': 'test_text_aeThaeroneiroo7Iophu',
             'disable_versioning': True})
        self.assertEqual(response.status_code, status.HTTP_200_OK)
        motion = Motion.objects.get()
        self.assertEqual(motion.versions.count(), 1)
コード例 #38
0
class UpdateMotion(TestCase):
    """
    Tests updating motions.
    """

    def setUp(self):
        self.client = APIClient()
        self.client.login(username="******", password="******")
        self.motion = Motion(
            title="test_title_aeng7ahChie3waiR8xoh",
            text="test_text_xeigheeha7thopubeu4U",
        )
        self.motion.save()

    def test_simple_patch(self):
        response = self.client.patch(
            reverse("motion-detail", args=[self.motion.pk]),
            {"identifier": "test_identifier_jieseghohj7OoSah1Ko9"},
        )
        self.assertEqual(response.status_code, status.HTTP_200_OK)
        motion = Motion.objects.get()
        self.assertEqual(motion.title, "test_title_aeng7ahChie3waiR8xoh")
        self.assertEqual(motion.identifier, "test_identifier_jieseghohj7OoSah1Ko9")

    def test_patch_as_anonymous_without_manage_perms(self):
        config["general_system_enable_anonymous"] = True
        guest_client = APIClient()
        response = guest_client.patch(
            reverse("motion-detail", args=[self.motion.pk]),
            {"identifier": "test_identifier_4g2jgj1wrnmvvIRhtqqPO84WD"},
        )
        self.assertEqual(response.status_code, status.HTTP_403_FORBIDDEN)
        motion = Motion.objects.get()
        self.assertEqual(motion.identifier, "1")

    def test_patch_empty_text(self):
        response = self.client.patch(
            reverse("motion-detail", args=[self.motion.pk]), {"text": ""}
        )
        self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)
        motion = Motion.objects.get()
        self.assertEqual(motion.text, "test_text_xeigheeha7thopubeu4U")

    def test_patch_amendment_paragraphs_no_manage_perms(self):
        admin = get_user_model().objects.get(username="******")
        admin.groups.remove(GROUP_ADMIN_PK)
        admin.groups.add(GROUP_DELEGATE_PK)
        Submitter.objects.add(admin, self.motion)
        self.motion.state.allow_submitter_edit = True
        self.motion.state.save()
        inform_changed_data(admin)

        response = self.client.patch(
            reverse("motion-detail", args=[self.motion.pk]),
            {"amendment_paragraphs": ["test_paragraph_39fo8qcpcaFMmjfaD2Lb"]},
        )
        self.assertEqual(response.status_code, status.HTTP_200_OK)
        motion = Motion.objects.get()
        self.assertTrue(isinstance(motion.amendment_paragraphs, list))
        self.assertEqual(len(motion.amendment_paragraphs), 1)
        self.assertEqual(
            motion.amendment_paragraphs[0], "test_paragraph_39fo8qcpcaFMmjfaD2Lb"
        )
        self.assertEqual(motion.text, "")

    def test_patch_workflow(self):
        """
        Tests to only update the workflow of a motion.
        """
        response = self.client.patch(
            reverse("motion-detail", args=[self.motion.pk]), {"workflow_id": "2"}
        )

        motion = Motion.objects.get()
        self.assertEqual(response.status_code, status.HTTP_200_OK)
        self.assertEqual(motion.title, "test_title_aeng7ahChie3waiR8xoh")
        self.assertEqual(motion.workflow_id, 2)

    def test_patch_category(self):
        """
        Tests to only update the category of a motion. Expects the
        category_weight to be resetted.
        """
        category = Category.objects.create(
            name="test_category_name_FE3jO(Fm83doqqlwcvlv",
            prefix="test_prefix_w3ofg2mv79UGFqjk3f8h",
        )
        self.motion.category_weight = 1
        self.motion.save()
        response = self.client.patch(
            reverse("motion-detail", args=[self.motion.pk]),
            {"category_id": category.pk},
        )
        self.assertEqual(response.status_code, status.HTTP_200_OK)
        motion = Motion.objects.get()
        self.assertEqual(motion.category, category)
        self.assertEqual(motion.category_weight, 10000)

    def test_patch_supporters(self):
        supporter = get_user_model().objects.create_user(
            username="******",
            password="******",
        )
        response = self.client.patch(
            reverse("motion-detail", args=[self.motion.pk]),
            json.dumps({"supporters_id": [supporter.pk]}),
            content_type="application/json",
        )
        self.assertEqual(response.status_code, status.HTTP_200_OK)
        motion = Motion.objects.get()
        self.assertEqual(motion.title, "test_title_aeng7ahChie3waiR8xoh")
        self.assertEqual(
            motion.supporters.get().username, "test_username_ieB9eicah0uqu6Phoovo"
        )

    def test_patch_supporters_non_manager(self):
        non_admin = get_user_model().objects.create_user(
            username="******",
            password="******",
        )
        self.client.login(
            username="******",
            password="******",
        )
        motion = Motion.objects.get()
        Submitter.objects.add(non_admin, self.motion)
        motion.supporters.clear()
        response = self.client.patch(
            reverse("motion-detail", args=[self.motion.pk]),
            json.dumps({"supporters_id": [1]}),
            content_type="application/json",
        )
        # Forbidden because of changed workflow state.
        self.assertEqual(response.status_code, status.HTTP_403_FORBIDDEN)

    def test_removal_of_supporters(self):
        # No cache used here.
        admin = get_user_model().objects.get(username="******")
        group_admin = admin.groups.get(name="Admin")
        admin.groups.remove(group_admin)
        Submitter.objects.add(admin, self.motion)
        supporter = get_user_model().objects.create_user(
            username="******",
            password="******",
        )
        self.motion.supporters.add(supporter)
        config["motions_remove_supporters"] = True
        self.assertEqual(self.motion.supporters.count(), 1)
        inform_changed_data((admin, self.motion))

        response = self.client.patch(
            reverse("motion-detail", args=[self.motion.pk]),
            {"title": "new_title_ohph1aedie5Du8sai2ye"},
        )

        # Forbidden because of changed workflow state.
        self.assertEqual(response.status_code, status.HTTP_403_FORBIDDEN)

    def test_patch_recommendation_extension(self):
        group = get_group_model().objects.get(pk=GROUP_DELEGATE_PK)
        group.permissions.clear()
        group.permissions.add(
            Permission.objects.get(
                content_type__app_label="motions",
                codename="can_see",
            ),
            Permission.objects.get(
                content_type__app_label="motions",
                codename="can_manage_metadata",
            ),
        )
        group.save()
        password = "******"
        user = get_user_model().objects.create_user(
            username="******",
            password=password,
        )
        user.groups.add(group)
        user.save()
        self.client.login(username=user.username, password=password)

        response = self.client.patch(
            reverse("motion-detail", args=[self.motion.pk]),
            {"recommendation_extension": "extension"},
        )
        self.assertEqual(response.status_code, status.HTTP_200_OK)
        motion = Motion.objects.get()
        self.assertEqual(motion.recommendation_extension, "extension")
コード例 #39
0
ファイル: test_viewset.py プロジェクト: funakura/OpenSlides
class NumberMotionsInCategories(TestCase):
    """
    Tests numbering motions in categories.

    Default test environment:
     - *without* blanks
     - 1 min digit

    Testdata. All names (and prefixes) are prefixed with "test_". The
    ordering is ensured with "category_weight".
    Category tree (with motions M and amendments A):
    A-A
      <M1>
      <M2-A2>
      B
        <M2-A1>
        <M3>
      C-C
        <M2>
        <M2-A1-A1>
    """
    def setUp(self):
        self.client = APIClient()
        self.client.login(username="******", password="******")
        self.A = Category.objects.create(name="test_A", prefix="test_A")
        self.B = Category.objects.create(name="test_B", parent=self.A)
        self.C = Category.objects.create(name="test_C",
                                         prefix="test_C",
                                         parent=self.A)

        self.M1 = Motion(
            title="test_title_Eeha8Haf6peulu8ooc0z",
            text="test_text_faghaZoov9ooV4Acaquk",
            category=self.A,
            category_weight=1,
        )
        self.M1.save()
        self.M1.identifier = ""
        self.M1.save()

        self.M2 = Motion(
            title="test_title_kuheih2eja2Saeshusha",
            text="test_text_Ha5ShaeraeSuthooP2Bu",
            category=self.C,
            category_weight=1,
        )
        self.M2.save()
        self.M2.identifier = ""
        self.M2.save()

        self.M2_A1 = Motion(
            title="test_title_av3ejIJvwon3jvnNVaie",
            text="test_text_FJPiejfwdcoiwjvijao1",
            category=self.B,
            category_weight=1,
            parent=self.M2,
        )
        self.M2_A1.save()
        self.M2_A1.identifier = ""
        self.M2_A1.save()

        self.M2_A1_A1 = Motion(
            title="test_title_ejvhwoxngixoqkxy.qfi",
            text="test_text_euh2gfaiaqfu3.f(3hgf",
            category=self.C,
            category_weight=2,
            parent=self.M2_A1,
        )
        self.M2_A1_A1.save()
        self.M2_A1_A1.identifier = ""
        self.M2_A1_A1.save()

        self.M2_A2 = Motion(
            title="test_title_xoerFiwebbpiUEeuvxMa",
            text="test_text_zbwZWPefiisdISfwLKqN",
            category=self.A,
            category_weight=2,
            parent=self.M2,
        )
        self.M2_A2.save()
        self.M2_A2.identifier = ""
        self.M2_A2.save()

        self.M3 = Motion(
            title="test_title_VWIVeiNVenudn(23J92§",
            text="test_text_VEDno328hn8/TBbScVEb",
            category=self.B,
            category_weight=2,
        )
        self.M3.save()
        self.M3.identifier = ""
        self.M3.save()

    def test_numbering(self):
        response = self.client.post(
            reverse("category-numbering", args=[self.A.pk]))
        self.assertEqual(response.status_code, status.HTTP_200_OK)
        self.assertEqual(
            Motion.objects.get(pk=self.M1.pk).identifier, "test_A1")
        self.assertEqual(
            Motion.objects.get(pk=self.M3.pk).identifier, "test_A2")
        self.assertEqual(
            Motion.objects.get(pk=self.M2.pk).identifier, "test_C3")
        self.assertEqual(
            Motion.objects.get(pk=self.M2_A1.pk).identifier, "test_C3-2")
        self.assertEqual(
            Motion.objects.get(pk=self.M2_A1_A1.pk).identifier, "test_C3-2-1")
        self.assertEqual(
            Motion.objects.get(pk=self.M2_A2.pk).identifier, "test_C3-1")

    def test_with_blanks_and_leading_zeros(self):
        config["motions_amendments_prefix"] = "-X"
        config["motions_identifier_with_blank"] = True
        config["motions_identifier_min_digits"] = 3
        response = self.client.post(
            reverse("category-numbering", args=[self.A.pk]))
        config["motions_identifier_with_blank"] = False
        config["motions_identifier_min_digits"] = 1

        self.assertEqual(response.status_code, status.HTTP_200_OK)
        self.assertEqual(
            Motion.objects.get(pk=self.M1.pk).identifier, "test_A 001")
        self.assertEqual(
            Motion.objects.get(pk=self.M3.pk).identifier, "test_A 002")
        self.assertEqual(
            Motion.objects.get(pk=self.M2.pk).identifier, "test_C 003")
        self.assertEqual(
            Motion.objects.get(pk=self.M2_A1.pk).identifier,
            "test_C 003 -X 002")
        self.assertEqual(
            Motion.objects.get(pk=self.M2_A1_A1.pk).identifier,
            "test_C 003 -X 002 -X 001",
        )
        self.assertEqual(
            Motion.objects.get(pk=self.M2_A2.pk).identifier,
            "test_C 003 -X 001")

    def test_existing_identifier_no_category(self):
        # config["motions_identifier_with_blank"] = True
        conflicting_motion = Motion(
            title="test_title_al2=2k21fjv1lsck3ehlWExg",
            text="test_text_3omvpEhnfg082ejplk1m",
        )
        conflicting_motion.save()
        conflicting_motion.identifier = "test_C3-2-1"
        conflicting_motion.save()
        response = self.client.post(
            reverse("category-numbering", args=[self.A.pk]))
        self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)
        self.assertEqual("test_C3-2-1", response.data["args"][0])

    def test_existing_identifier_with_category(self):
        conflicting_category = Category.objects.create(
            name="test_name_hpsodhakvjdbvkblwfjr")
        conflicting_motion = Motion(
            title="test_title_al2=2k21fjv1lsck3ehlWExg",
            text="test_text_3omvpEhnfg082ejplk1m",
            category=conflicting_category,
        )
        conflicting_motion.save()
        conflicting_motion.identifier = "test_C3-2-1"
        conflicting_motion.save()
        response = self.client.post(
            reverse("category-numbering", args=[self.A.pk]))
        self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)
        self.assertEqual("test_C3-2-1", response.data["args"][0])
        self.assertEqual(conflicting_category.name, response.data["args"][1])

    def test_incomplete_amendment_tree(self):
        self.M2_A1.category = None
        self.M2_A1.save()
        response = self.client.post(
            reverse("category-numbering", args=[self.A.pk]))
        self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)
        self.assertEqual(self.M2_A1_A1.title, response.data["args"][0])
        self.assertEqual(self.M2_A1.title, response.data["args"][1])
コード例 #40
0
class NumberMotionsInCategory(TestCase):
    """
    Tests numbering motions in a category.
    """
    def setUp(self):
        self.client = APIClient()
        self.client.login(username='******', password='******')
        self.category = Category.objects.create(
            name='test_cateogory_name_zah6Ahd4Ifofaeree6ai',
            prefix='test_prefix_ahz6tho2mooH8')
        self.motion = Motion(title='test_title_Eeha8Haf6peulu8ooc0z',
                             text='test_text_faghaZoov9ooV4Acaquk',
                             category=self.category)
        self.motion.save()
        self.motion.identifier = ''
        self.motion.save()
        self.motion_2 = Motion(title='test_title_kuheih2eja2Saeshusha',
                               text='test_text_Ha5ShaeraeSuthooP2Bu',
                               category=self.category)
        self.motion_2.save()
        self.motion_2.identifier = ''
        self.motion_2.save()

    def test_numbering(self):
        response = self.client.post(
            reverse('category-numbering', args=[self.category.pk]))
        self.assertEqual(response.status_code, status.HTTP_200_OK)
        self.assertEqual(
            response.data, {
                'detail':
                'All motions in category test_cateogory_name_zah6Ahd4Ifofaeree6ai numbered successfully.'
            })
        self.assertEqual(
            Motion.objects.get(pk=self.motion.pk).identifier,
            'test_prefix_ahz6tho2mooH8 1')
        self.assertEqual(
            Motion.objects.get(pk=self.motion_2.pk).identifier,
            'test_prefix_ahz6tho2mooH8 2')

    def test_numbering_existing_identifier(self):
        self.motion_2.identifier = 'test_prefix_ahz6tho2mooH8 1'
        self.motion_2.save()
        response = self.client.post(
            reverse('category-numbering', args=[self.category.pk]))
        self.assertEqual(response.status_code, status.HTTP_200_OK)
        self.assertEqual(
            response.data, {
                'detail':
                'All motions in category test_cateogory_name_zah6Ahd4Ifofaeree6ai numbered successfully.'
            })
        self.assertEqual(
            Motion.objects.get(pk=self.motion.pk).identifier,
            'test_prefix_ahz6tho2mooH8 1')
        self.assertEqual(
            Motion.objects.get(pk=self.motion_2.pk).identifier,
            'test_prefix_ahz6tho2mooH8 2')

    def test_numbering_with_given_order(self):
        self.motion_3 = Motion(title='test_title_eeb0kua5ciike4su2auJ',
                               text='test_text_ahshuGhaew3eim8yoht7',
                               category=self.category)
        self.motion_3.save()
        self.motion_3.identifier = ''
        self.motion_3.save()
        response = self.client.post(reverse('category-numbering',
                                            args=[self.category.pk]),
                                    {'motions': [3, 2]},
                                    format='json')
        self.assertEqual(response.status_code, status.HTTP_200_OK)
        self.assertEqual(
            response.data, {
                'detail':
                'All motions in category test_cateogory_name_zah6Ahd4Ifofaeree6ai numbered successfully.'
            })
        self.assertEqual(
            Motion.objects.get(pk=self.motion.pk).identifier, None)
        self.assertEqual(
            Motion.objects.get(pk=self.motion_2.pk).identifier,
            'test_prefix_ahz6tho2mooH8 2')
        self.assertEqual(
            Motion.objects.get(pk=self.motion_3.pk).identifier,
            'test_prefix_ahz6tho2mooH8 1')
コード例 #41
0
class RetrieveMotion(TestCase):
    """
    Tests retrieving a motion (with poll results).
    """
    def setUp(self):
        self.client = APIClient()
        self.client.login(username='******', password='******')
        self.motion = Motion(title='test_title_uj5eeSiedohSh3ohyaaj',
                             text='test_text_ithohchaeThohmae5aug')
        self.motion.save()
        self.motion.create_poll()
        for index in range(10):
            get_user_model().objects.create_user(
                username='******'.format(index), password='******')

    def test_number_of_queries(self):
        """
        Tests that only the following db queries are done:
        * 7 requests to get the session and the request user with its permissions (3 of them are possibly a bug)
        * 1 request to get the motion,
        * 1 request to get the version,
        * 1 request to get the agenda item,
        * 1 request to get the log,
        * 3 request to get the polls (1 of them is possibly a bug),
        * 1 request to get the attachments,
        * 1 request to get the tags,
        * 2 requests to get the submitters and supporters.
        TODO: Fix all bugs.
        """
        get_redis_connection('default').flushall()
        with self.assertNumQueries(18):
            self.client.get(reverse('motion-detail', args=[self.motion.pk]))

    def test_guest_state_with_required_permission_to_see(self):
        config['general_system_enable_anonymous'] = True
        guest_client = APIClient()
        state = self.motion.state
        state.required_permission_to_see = 'permission_that_the_user_does_not_have_leeceiz9hi7iuta4ahY2'
        state.save()
        # The cache has to be cleared, see:
        # https://github.com/OpenSlides/OpenSlides/issues/3396
        get_redis_connection('default').flushall()
        response = guest_client.get(
            reverse('motion-detail', args=[self.motion.pk]))
        self.assertEqual(response.status_code, status.HTTP_403_FORBIDDEN)

    def test_admin_state_with_required_permission_to_see(self):
        state = self.motion.state
        state.required_permission_to_see = 'permission_that_the_user_does_not_have_coo1Iewu8Eing2xahfoo'
        state.save()
        response = self.client.get(
            reverse('motion-detail', args=[self.motion.pk]))
        self.assertEqual(response.status_code, status.HTTP_200_OK)

    def test_submitter_state_with_required_permission_to_see(self):
        state = self.motion.state
        state.required_permission_to_see = 'permission_that_the_user_does_not_have_eiW8af9caizoh1thaece'
        state.save()
        user = get_user_model().objects.create_user(
            username='******',
            password='******')
        self.motion.submitters.add(user)
        submitter_client = APIClient()
        submitter_client.force_login(user)
        response = submitter_client.get(
            reverse('motion-detail', args=[self.motion.pk]))
        self.assertEqual(response.status_code, status.HTTP_200_OK)

    def test_user_without_can_see_user_permission_to_see_motion_and_submitter_data(
            self):
        self.motion.submitters.add(
            get_user_model().objects.get(username='******'))
        group = Group.objects.get(
            pk=1)  # Group with pk 1 is for anonymous and default users.
        permission_string = 'users.can_see_name'
        app_label, codename = permission_string.split('.')
        permission = group.permissions.get(content_type__app_label=app_label,
                                           codename=codename)
        group.permissions.remove(permission)
        config['general_system_enable_anonymous'] = True
        guest_client = APIClient()
        get_redis_connection('default').flushall()

        response_1 = guest_client.get(
            reverse('motion-detail', args=[self.motion.pk]))
        self.assertEqual(response_1.status_code, status.HTTP_200_OK)
        response_2 = guest_client.get(
            reverse('user-detail', args=[response_1.data['submitters_id'][0]]))
        self.assertEqual(response_2.status_code, status.HTTP_200_OK)

        extra_user = get_user_model().objects.create_user(
            username='******',
            password='******')
        get_redis_connection('default').flushall()
        response_3 = guest_client.get(
            reverse('user-detail', args=[extra_user.pk]))
        self.assertEqual(response_3.status_code, status.HTTP_403_FORBIDDEN)
コード例 #42
0
ファイル: test_viewset.py プロジェクト: funakura/OpenSlides
class ManageComments(TestCase):
    """
    Tests the manage_comment view.

    Tests creation/updating and deletion of motion comments.
    """
    def setUp(self):
        self.client = APIClient()
        self.client.login(username="******", password="******")

        self.admin = get_user_model().objects.get()
        self.group_out = get_group_model().objects.get(
            pk=GROUP_DELEGATE_PK)  # The admin should not be in this group

        # Put the admin into the staff group, becaust in the admin group, he has all permissions for
        # every single comment section.
        self.admin.groups.add(GROUP_STAFF_PK)
        self.admin.groups.remove(GROUP_ADMIN_PK)
        inform_changed_data(self.admin)
        self.group_in = get_group_model().objects.get(pk=GROUP_STAFF_PK)

        self.motion = Motion(
            title="test_title_SlqfMw(waso0saWMPqcZ",
            text="test_text_f30skclqS9wWF=xdfaSL",
        )
        self.motion.save()

        self.section_no_groups = MotionCommentSection(
            name='test_name_gj4F§(fj"(edm"§F3f3fs')
        self.section_no_groups.save()

        self.section_read = MotionCommentSection(
            name="test_name_2wv30(d2S&kvelkakl39")
        self.section_read.save()
        self.section_read.read_groups.add(
            self.group_in,
            self.group_out)  # Group out for testing multiple groups
        self.section_read.write_groups.add(self.group_out)

        self.section_read_write = MotionCommentSection(
            name="test_name_a3m9sd0(Mw2%slkrv30,")
        self.section_read_write.save()
        self.section_read_write.read_groups.add(self.group_in)
        self.section_read_write.write_groups.add(self.group_in)

    def test_wrong_data_type(self):
        response = self.client.post(
            reverse("motion-manage-comments", args=[self.motion.pk]), None)
        self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)
        self.assertEqual(response.data["detail"],
                         "You have to provide a section_id of type int.")

    def test_wrong_comment_data_type(self):
        response = self.client.post(
            reverse("motion-manage-comments", args=[self.motion.pk]),
            {
                "section_id": self.section_read_write.id,
                "comment": [32, "no_correct_data"],
            },
        )
        self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)
        self.assertEqual(response.data["detail"],
                         "The comment should be a string.")

    def test_non_existing_section(self):
        response = self.client.post(
            reverse("motion-manage-comments", args=[self.motion.pk]),
            {"section_id": 42})
        self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)
        self.assertEqual(response.data["detail"],
                         "A comment section with id {0} does not exist.")
        self.assertEqual(response.data["args"][0], "42")

    def test_create_comment(self):
        response = self.client.post(
            reverse("motion-manage-comments", args=[self.motion.pk]),
            {
                "section_id": self.section_read_write.pk,
                "comment": "test_comment_fk3jrnfwsdg%fj=feijf",
            },
        )
        self.assertEqual(response.status_code, status.HTTP_200_OK)
        self.assertEqual(MotionComment.objects.count(), 1)
        comment = MotionComment.objects.get()
        self.assertEqual(comment.comment, "test_comment_fk3jrnfwsdg%fj=feijf")

    def test_update_comment(self):
        comment = MotionComment(
            motion=self.motion,
            section=self.section_read_write,
            comment="test_comment_fji387fqwdf&ff=)Fe3j",
        )
        comment.save()

        response = self.client.post(
            reverse("motion-manage-comments", args=[self.motion.pk]),
            {
                "section_id": self.section_read_write.pk,
                "comment": "test_comment_fk3jrnfwsdg%fj=feijf",
            },
        )
        self.assertEqual(response.status_code, status.HTTP_200_OK)
        comment = MotionComment.objects.get()
        self.assertEqual(comment.comment, "test_comment_fk3jrnfwsdg%fj=feijf")

    def test_delete_comment(self):
        comment = MotionComment(
            motion=self.motion,
            section=self.section_read_write,
            comment='test_comment_5CJ"8f23jd3j2,r93keZ',
        )
        comment.save()

        response = self.client.delete(
            reverse("motion-manage-comments", args=[self.motion.pk]),
            {"section_id": self.section_read_write.pk},
        )
        self.assertEqual(response.status_code, status.HTTP_200_OK)
        self.assertEqual(MotionComment.objects.count(), 0)

    def test_delete_not_existing_comment(self):
        """
        This should fail silently; no error, if the user wants to delete
        a not existing comment.
        """
        response = self.client.delete(
            reverse("motion-manage-comments", args=[self.motion.pk]),
            {"section_id": self.section_read_write.pk},
        )
        self.assertEqual(response.status_code, status.HTTP_200_OK)
        self.assertEqual(MotionComment.objects.count(), 0)

    def test_create_comment_no_write_permission(self):
        response = self.client.post(
            reverse("motion-manage-comments", args=[self.motion.pk]),
            {
                "section_id": self.section_read.pk,
                "comment": "test_comment_f38jfwqfj830fj4j(FU3",
            },
        )
        self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)
        self.assertEqual(MotionComment.objects.count(), 0)
        self.assertEqual(
            response.data["detail"],
            "You are not allowed to see or write to the comment section.",
        )

    def test_update_comment_no_write_permission(self):
        comment = MotionComment(
            motion=self.motion,
            section=self.section_read,
            comment="test_comment_jg38dwiej2D832(D§dk)",
        )
        comment.save()

        response = self.client.post(
            reverse("motion-manage-comments", args=[self.motion.pk]),
            {
                "section_id": self.section_read.pk,
                "comment": "test_comment_fk3jrnfwsdg%fj=feijf",
            },
        )
        self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)
        comment = MotionComment.objects.get()
        self.assertEqual(comment.comment, "test_comment_jg38dwiej2D832(D§dk)")

    def test_delete_comment_no_write_permission(self):
        comment = MotionComment(
            motion=self.motion,
            section=self.section_read,
            comment="test_comment_fej(NF§kfePOF383o8DN",
        )
        comment.save()

        response = self.client.delete(
            reverse("motion-manage-comments", args=[self.motion.pk]),
            {"section_id": self.section_read.pk},
        )
        self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)
        self.assertEqual(MotionComment.objects.count(), 1)
        comment = MotionComment.objects.get()
        self.assertEqual(comment.comment, "test_comment_fej(NF§kfePOF383o8DN")
コード例 #43
0
class UpdateMotion(TestCase):
    """
    Tests updating motions.
    """
    def setUp(self):
        self.client = APIClient()
        self.client.login(username='******', password='******')
        self.motion = Motion(title='test_title_aeng7ahChie3waiR8xoh',
                             text='test_text_xeigheeha7thopubeu4U')
        self.motion.save()

    def test_simple_patch(self):
        response = self.client.patch(
            reverse('motion-detail', args=[self.motion.pk]),
            {'identifier': 'test_identifier_jieseghohj7OoSah1Ko9'})
        self.assertEqual(response.status_code, status.HTTP_200_OK)
        motion = Motion.objects.get()
        self.assertEqual(motion.title, 'test_title_aeng7ahChie3waiR8xoh')
        self.assertEqual(motion.identifier,
                         'test_identifier_jieseghohj7OoSah1Ko9')

    def test_patch_workflow(self):
        """
        Tests to only update the workflow of a motion.
        """
        response = self.client.patch(
            reverse('motion-detail', args=[self.motion.pk]),
            {'workflow_id': '2'})

        motion = Motion.objects.get()
        self.assertEqual(response.status_code, status.HTTP_200_OK)
        self.assertEqual(motion.title, 'test_title_aeng7ahChie3waiR8xoh')
        self.assertEqual(motion.workflow, 2)

    def test_patch_supporters(self):
        supporter = get_user_model().objects.create_user(
            username='******',
            password='******')
        response = self.client.patch(reverse('motion-detail',
                                             args=[self.motion.pk]),
                                     json.dumps(
                                         {'supporters_id': [supporter.pk]}),
                                     content_type='application/json')
        self.assertEqual(response.status_code, status.HTTP_200_OK)
        motion = Motion.objects.get()
        self.assertEqual(motion.title, 'test_title_aeng7ahChie3waiR8xoh')
        self.assertEqual(motion.supporters.get().username,
                         'test_username_ieB9eicah0uqu6Phoovo')

    def test_patch_supporters_non_manager(self):
        non_admin = get_user_model().objects.create_user(
            username='******',
            password='******')
        self.client.login(username='******',
                          password='******')
        motion = Motion.objects.get()
        motion.submitters.add(non_admin)
        motion.supporters.clear()
        response = self.client.patch(reverse('motion-detail',
                                             args=[self.motion.pk]),
                                     json.dumps({'supporters_id': [1]}),
                                     content_type='application/json')
        self.assertEqual(response.status_code, status.HTTP_200_OK)
        self.assertFalse(motion.supporters.exists())

    def test_removal_of_supporters(self):
        # No cache used here.
        admin = get_user_model().objects.get(username='******')
        group_staff = admin.groups.get(name='Staff')
        admin.groups.remove(group_staff)
        self.motion.submitters.add(admin)
        supporter = get_user_model().objects.create_user(
            username='******',
            password='******')
        self.motion.supporters.add(supporter)
        config['motions_remove_supporters'] = True
        self.assertEqual(self.motion.supporters.count(), 1)
        get_redis_connection('default').flushall()

        response = self.client.patch(
            reverse('motion-detail', args=[self.motion.pk]),
            {'title': 'new_title_ohph1aedie5Du8sai2ye'})

        self.assertEqual(response.status_code, status.HTTP_200_OK)
        motion = Motion.objects.get()
        self.assertEqual(motion.title, 'new_title_ohph1aedie5Du8sai2ye')
        self.assertEqual(motion.supporters.count(), 0)

    def test_with_new_version(self):
        self.motion.set_state(State.objects.get(name='permitted'))
        self.motion.save()
        response = self.client.patch(
            reverse('motion-detail', args=[self.motion.pk]),
            {'text': 'test_text_aeb1iaghahChong5od3a'})
        self.assertEqual(response.status_code, status.HTTP_200_OK)
        motion = Motion.objects.get()
        self.assertEqual(motion.versions.count(), 2)

    def test_without_new_version(self):
        self.motion.set_state(State.objects.get(name='permitted'))
        self.motion.save()
        response = self.client.patch(
            reverse('motion-detail', args=[self.motion.pk]), {
                'text': 'test_text_aeThaeroneiroo7Iophu',
                'disable_versioning': True
            })
        self.assertEqual(response.status_code, status.HTTP_200_OK)
        motion = Motion.objects.get()
        self.assertEqual(motion.versions.count(), 1)
コード例 #44
0
class UpdateMotion(TestCase):
    """
    Tests updating motions.
    """
    def setUp(self):
        self.client = APIClient()
        self.client.login(username='******', password='******')
        self.motion = Motion(title='test_title_aeng7ahChie3waiR8xoh',
                             text='test_text_xeigheeha7thopubeu4U')
        self.motion.save()

    def test_simple_patch(self):
        response = self.client.patch(
            reverse('motion-detail', args=[self.motion.pk]),
            {'identifier': 'test_identifier_jieseghohj7OoSah1Ko9'})
        self.assertEqual(response.status_code, status.HTTP_200_OK)
        motion = Motion.objects.get()
        self.assertEqual(motion.title, 'test_title_aeng7ahChie3waiR8xoh')
        self.assertEqual(motion.identifier,
                         'test_identifier_jieseghohj7OoSah1Ko9')

    def test_patch_workflow(self):
        """
        Tests to only update the workflow of a motion.
        """
        response = self.client.patch(
            reverse('motion-detail', args=[self.motion.pk]),
            {'workflow_id': '2'})

        motion = Motion.objects.get()
        self.assertEqual(response.status_code, status.HTTP_200_OK)
        self.assertEqual(motion.title, 'test_title_aeng7ahChie3waiR8xoh')
        self.assertEqual(motion.workflow, 2)

    def test_patch_supporters(self):
        supporter = get_user_model().objects.create_user(
            username='******',
            password='******')
        response = self.client.patch(reverse('motion-detail',
                                             args=[self.motion.pk]),
                                     json.dumps(
                                         {'supporters_id': [supporter.pk]}),
                                     content_type='application/json')
        self.assertEqual(response.status_code, status.HTTP_200_OK)
        motion = Motion.objects.get()
        self.assertEqual(motion.title, 'test_title_aeng7ahChie3waiR8xoh')
        self.assertEqual(motion.supporters.get().username,
                         'test_username_ieB9eicah0uqu6Phoovo')

    def test_patch_supporters_non_manager(self):
        non_admin = get_user_model().objects.create_user(
            username='******',
            password='******')
        self.client.login(username='******',
                          password='******')
        motion = Motion.objects.get()
        motion.submitters.add(non_admin)
        motion.supporters.clear()
        response = self.client.patch(reverse('motion-detail',
                                             args=[self.motion.pk]),
                                     json.dumps({'supporters_id': [1]}),
                                     content_type='application/json')
        self.assertEqual(response.status_code, status.HTTP_200_OK)
        self.assertFalse(motion.supporters.exists())

    def test_removal_of_supporters(self):
        # No cache used here.
        admin = get_user_model().objects.get(username='******')
        group_admin = admin.groups.get(name='Admin')
        admin.groups.remove(group_admin)
        self.motion.submitters.add(admin)
        supporter = get_user_model().objects.create_user(
            username='******',
            password='******')
        self.motion.supporters.add(supporter)
        config['motions_remove_supporters'] = True
        self.assertEqual(self.motion.supporters.count(), 1)
        get_redis_connection('default').flushall()

        response = self.client.patch(
            reverse('motion-detail', args=[self.motion.pk]),
            {'title': 'new_title_ohph1aedie5Du8sai2ye'})

        self.assertEqual(response.status_code, status.HTTP_200_OK)
        motion = Motion.objects.get()
        self.assertEqual(motion.title, 'new_title_ohph1aedie5Du8sai2ye')
        self.assertEqual(motion.supporters.count(), 0)

    def test_with_new_version(self):
        self.motion.set_state(State.objects.get(name='permitted'))
        self.motion.save()
        response = self.client.patch(
            reverse('motion-detail', args=[self.motion.pk]),
            {'text': 'test_text_aeb1iaghahChong5od3a'})
        self.assertEqual(response.status_code, status.HTTP_200_OK)
        motion = Motion.objects.get()
        self.assertEqual(motion.versions.count(), 2)

    def test_without_new_version(self):
        self.motion.set_state(State.objects.get(name='permitted'))
        self.motion.save()
        response = self.client.patch(
            reverse('motion-detail', args=[self.motion.pk]), {
                'text': 'test_text_aeThaeroneiroo7Iophu',
                'disable_versioning': True
            })
        self.assertEqual(response.status_code, status.HTTP_200_OK)
        motion = Motion.objects.get()
        self.assertEqual(motion.versions.count(), 1)

    def test_update_comment_creates_log_entry(self):
        field_name = 'comment_field_name_texl2i7%sookqerpl29a'
        config['motions_comments'] = {
            '1': {
                'name': field_name,
                'public': False
            }
        }

        # Update Config cache
        CollectionElement.from_instance(
            ConfigStore.objects.get(key='motions_comments'))

        response = self.client.patch(reverse(
            'motion-detail', args=[self.motion.pk]), {
                'title': 'title_test_sfdAaufd56HR7sd5FDq7av',
                'text': 'text_test_fiuhefF86()ew1Ef346AF6W',
                'comments': {
                    '1': 'comment1_sdpoiuffo3%7dwDwW)'
                }
            },
                                     format='json')
        self.assertEqual(response.status_code, status.HTTP_200_OK)

        motion_logs = MotionLog.objects.filter(motion=self.motion)
        self.assertEqual(motion_logs.count(), 2)

        motion_log = motion_logs.order_by('-time').first()
        self.assertTrue(field_name in motion_log.message_list[0])
コード例 #45
0
ファイル: test_motions.py プロジェクト: topelrapha/OpenSlides
class RetrieveMotion(TestCase):
    """
    Tests retrieving a motion
    """
    def setUp(self):
        self.client = APIClient()
        self.client.login(username="******", password="******")
        self.motion = Motion(
            title="test_title_uj5eeSiedohSh3ohyaaj",
            text="test_text_ithohchaeThohmae5aug",
        )
        self.motion.save()
        for index in range(10):
            get_user_model().objects.create_user(username=f"user_{index}",
                                                 password="******")

    def test_guest_state_with_restriction(self):
        config["general_system_enable_anonymous"] = True
        guest_client = APIClient()
        state = self.motion.state
        state.restriction = ["motions.can_manage"]
        state.save()
        # The cache has to be cleared, see:
        # https://github.com/OpenSlides/OpenSlides/issues/3396
        inform_changed_data(self.motion)

        response = guest_client.get(
            reverse("motion-detail", args=[self.motion.pk]))
        self.assertEqual(response.status_code, 404)

    def test_admin_state_with_restriction(self):
        state = self.motion.state
        state.restriction = ["motions.can_manage"]
        state.save()
        response = self.client.get(
            reverse("motion-detail", args=[self.motion.pk]))
        self.assertEqual(response.status_code, status.HTTP_200_OK)

    def test_submitter_state_with_restriction(self):
        state = self.motion.state
        state.restriction = ["is_submitter"]
        state.save()
        user = get_user_model().objects.create_user(
            username="******",
            password="******",
        )
        Submitter.objects.add(user, self.motion)
        submitter_client = APIClient()
        submitter_client.force_login(user)
        response = submitter_client.get(
            reverse("motion-detail", args=[self.motion.pk]))
        self.assertEqual(response.status_code, status.HTTP_200_OK)

    def test_user_without_can_see_user_permission_to_see_motion_and_submitter_data(
        self, ):
        admin = get_user_model().objects.get(username="******")
        Submitter.objects.add(admin, self.motion)
        group = get_group_model().objects.get(
            pk=GROUP_DEFAULT_PK
        )  # Group with pk 1 is for anonymous and default users.
        permission_string = "users.can_see_name"
        app_label, codename = permission_string.split(".")
        permission = group.permissions.get(content_type__app_label=app_label,
                                           codename=codename)
        group.permissions.remove(permission)
        config["general_system_enable_anonymous"] = True
        guest_client = APIClient()
        inform_changed_data(group)
        inform_changed_data(self.motion)

        response_1 = guest_client.get(
            reverse("motion-detail", args=[self.motion.pk]))
        self.assertEqual(response_1.status_code, status.HTTP_200_OK)
        submitter_id = response_1.data["submitters"][0]["user_id"]
        response_2 = guest_client.get(
            reverse("user-detail", args=[submitter_id]))
        self.assertEqual(response_2.status_code, status.HTTP_200_OK)

        extra_user = get_user_model().objects.create_user(
            username="******",
            password="******",
        )

        response_3 = guest_client.get(
            reverse("user-detail", args=[extra_user.pk]))
        self.assertEqual(response_3.status_code, 404)