def test_str(self): transfer = factories.TransferFactory() self.assertEqual( str(transfer), 'paying_user transfers 35.79 to receiving_user' )
def test_execute__OK(self): transfer = factories.TransferFactory() response = self.client.post( '/transfers/{0}/execute/'.format(transfer.pk), follow=True ) self.assertEqual(response.status_code, 200) self.assertEqual(response.json()['detail'], 'Success')
def test_execute_state_is_not_pending(self): transfer = factories.TransferFactory(state='COMPLETED') response = self.client.post( '/transfers/{0}/execute/'.format(transfer.pk), follow=True ) self.assertEqual(response.status_code, 403) self.assertEqual( response.json()['detail'], 'The order is not ready to be sent.', )
def test_execute__is_not_admin_but_he_is_the_sender(self): user_receiving = user_models.User.objects.get( username='******', ) transfer = factories.TransferFactory( from_user=self.user, to_user=user_receiving, ) response = self.client.post( '/transfers/{0}/execute/'.format(transfer.pk), follow=True, ) self.assertEqual(response.status_code, 200) self.assertEqual(response.json()['detail'], 'Success')
def test_execute_transfer__do_not_allow_twice(self): from_user = user_factories.UserFactory( username='******', balance=150, ) to_user = user_factories.UserFactory( username='******', balance=25, ) transfer = factories.TransferFactory( from_user=from_user, to_user=to_user, quantity=50, ) self.assertTrue(transfer.execute_transfer()) self.assertFalse(transfer.execute_transfer())
def test_execute_transfer__negative(self): from_user = user_factories.UserFactory( username='******', balance=-250.33, ) to_user = user_factories.UserFactory( username='******', balance=-1500.708, ) transfer = factories.TransferFactory( from_user=from_user, to_user=to_user, quantity=285.49, ) self.assertTrue(transfer.execute_transfer()) self.assertEqual(from_user.get_balance(), -535.82) self.assertEqual(to_user.get_balance(), -1215.218)
def test_execute_transfer(self): from_user = user_factories.UserFactory( username='******', balance=150, ) to_user = user_factories.UserFactory( username='******', balance=25, ) transfer = factories.TransferFactory( from_user=from_user, to_user=to_user, quantity=50, ) self.assertTrue(transfer.execute_transfer()) self.assertEqual(from_user.get_balance(), 100) self.assertEqual(to_user.get_balance(), 75)
def test_execute__is_not_admin_and_he_is_not_the_sender(self): user = user_models.User.objects.get(username='******') user.user_permissions.add(self.perm) transfer = factories.TransferFactory( from_user=user, to_user=self.user, ) response = self.client.post( '/transfers/{0}/execute/'.format(transfer.pk), follow=True, ) self.assertEqual(response.status_code, 403) self.assertEqual( response.json()['detail'], 'You don\'t have permissions to execute this transfer', )
def test_execute__twice(self): transfer = factories.TransferFactory() response = self.client.post( '/transfers/{0}/execute/'.format(transfer.pk), follow=True ) self.assertEqual(response.status_code, 200) self.assertEqual(response.json()['detail'], 'Success') response = self.client.post( '/transfers/{0}/execute/'.format(transfer.pk), follow=True ) self.assertEqual(response.status_code, 403) self.assertEqual( response.json()['detail'], 'The order is not ready to be sent.', )