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)
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 )
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" )
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')