Example #1
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')
Example #2
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')
Example #3
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"
        )
Example #4
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")
Example #5
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)
Example #6
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 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')
Example #7
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):
        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)
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])