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 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()
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.'})
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))
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_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)
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 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 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 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_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')
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.'})
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()
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."} )
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 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_set_identifier_allready_set(self): """ If the motion already has a identifier, the method does nothing. """ motion = Motion(identifier="My test identifier") motion.set_identifier() self.assertEqual(motion.identifier, "My test identifier")
def test_set_identifier_allready_set(self): """ If the motion already has a identifier, the method does nothing. """ motion = Motion(identifier='My test identifier') motion.set_identifier() self.assertEqual(motion.identifier, 'My test identifier')
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 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 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_set_identifier_manually(self): """ If the config is set to manually, the method does nothing. """ config['motions_identifier'] = 'manually' motion = Motion() motion.set_identifier() # If the identifier should be set manually, the method does nothing self.assertIsNone(motion.identifier)
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_set_identifier_manually(self): """ If the config is set to manually, the method does nothing. """ config["motions_identifier"] = "manually" motion = Motion() motion.set_identifier() # If the identifier should be set manually, the method does nothing self.assertIsNone(motion.identifier)
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_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_set_identifier_manually(self): """ If the config is set to manually, the method does nothing. """ config['motions_identifier'] = 'manually' get_redis_connection("default").flushall() motion = Motion() motion.set_identifier() # If the identifier should be set manually, the method does nothing self.assertIsNone(motion.identifier)
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.'})
def test_set_identifier_amendment(self): """ If the motion is an amendment, the identifier is the identifier from the parent + a suffix. """ config["motions_amendments_enabled"] = True self.motion.identifier = "Parent identifier" self.motion.save() motion = Motion(parent=self.motion) motion.set_identifier() self.assertEqual(motion.identifier, "Parent identifier A 1")
def test_set_identifier_amendment(self): """ If the motion is an amendment, the identifier is the identifier from the parent + a suffix. """ config['motions_amendments_enabled'] = True self.motion.identifier = 'Parent identifier' self.motion.save() motion = Motion(parent=self.motion) motion.set_identifier() self.assertEqual(motion.identifier, 'Parent identifier A 1')
def test_set_identifier_second_amendment(self): """ If a motion has already an amendment, the second motion gets another identifier. """ config["motions_amendments_enabled"] = True self.motion.identifier = "Parent identifier" self.motion.save() Motion.objects.create(title="Amendment1", parent=self.motion) motion = Motion(parent=self.motion) motion.set_identifier() self.assertEqual(motion.identifier, "Parent identifier - 2")
def test_set_identifier_second_amendment(self): """ If a motion has already an amendment, the second motion gets another identifier. """ config['motions_amendments_enabled'] = True self.motion.identifier = 'Parent identifier' self.motion.save() Motion.objects.create(title='Amendment1', parent=self.motion) motion = Motion(parent=self.motion) motion.set_identifier() self.assertEqual(motion.identifier, 'Parent identifier - 2')
def test_set_identifier_amendment(self): """ If the motion is an amendment, the identifier is the identifier from the parent + a suffix. """ config['motions_amendments_enabled'] = True self.motion.identifier = 'Parent identifier' self.motion.save() get_redis_connection("default").flushall() motion = Motion(parent=self.motion) motion.set_identifier() self.assertEqual(motion.identifier, 'Parent identifier - 1')
def test_version_data(self): motion = Motion() self.assertEqual(motion.title, '') with self.assertRaises(AttributeError): self._title motion.title = 'title' self.assertEqual(motion._title, 'title') motion.text = 'text' self.assertEqual(motion._text, 'text') motion.reason = 'reason' self.assertEqual(motion._reason, 'reason')
def test_set_identifier_amendment(self): """ If the motion is an amendment, the identifier is the identifier from the parent + a suffix. """ config["motions_amendments_enabled"] = True config["motions_identifier_with_blank"] = False self.motion.identifier = "Parent identifier" self.motion.save() motion = Motion(parent=self.motion) motion.set_identifier() self.assertEqual(motion.identifier, "Parent identifier-1")
def test_version_data(self): motion = Motion() self.assertEqual(motion.title, "") with self.assertRaises(AttributeError): self._title motion.title = "title" self.assertEqual(motion._title, "title") motion.text = "text" self.assertEqual(motion._text, "text") motion.reason = "reason" self.assertEqual(motion._reason, "reason")
def test_set_identifier_second_amendment(self): """ If a motion has already an amendment, the second motion gets another identifier. """ config["motions_amendments_enabled"] = True self.motion.identifier = "Parent identifier" self.motion.save() Motion.objects.create(title="Amendment1", parent=self.motion) motion = Motion(parent=self.motion) motion.set_identifier() self.assertEqual(motion.identifier, "Parent identifier A 2")
def test_set_identifier_second_amendment(self): """ If a motion has already an amendment, the second motion gets another identifier. """ config['motions_amendments_enabled'] = True self.motion.identifier = 'Parent identifier' self.motion.save() Motion.objects.create(title='Amendment1', parent=self.motion) motion = Motion(parent=self.motion) motion.set_identifier() self.assertEqual(motion.identifier, 'Parent identifier A 2')
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()
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]))
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 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 setUp(self): self.client = APIClient() self.client.login(username='******', password='******') self.motion = Motion( title='test_title_aeng7ahChie3waiR8xoh', text='test_text_xeigheeha7thopubeu4U') self.motion.save()
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)
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 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 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 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.")
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 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 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.')
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.'})
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()
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)
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))
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)
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')
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')