def test_create_new_po_save_error(self): post_data = { 'name': 'new_payment_object', 'currency_id': Dummies.get_or_create_po_type().guid, 'type_id': Dummies.get_or_create_po_type().guid } response = self.client.post(self.url, data = post_data, content_type = self.request_content_type) self.assertEqual(response.status_code, 500, response.content) content = json.loads(response.content) self.assertEqual(content.get('message').get('text'), 'The error was occured during saving process')
def setUp(self): self.url = '/api/cmn/po_types/' self.request_content_type = 'application/json' self.client = Client() po_type = Dummies.get_or_create_po_type() user = Dummies.get_or_create_user() self.client.login(username=user.username, password=Dummies.get_password())
def test_create_new_po_name_length_error(self): post_data = { 'name': 'the name is longer than thirty letters in a row', 'currency_id': Dummies.get_or_create_currency().guid, 'type_id': Dummies.get_or_create_po_type().guid } response = self.client.post(self.url, data = post_data, content_type = self.request_content_type) self.assertEqual(response.status_code, 400, response.content) content = json.loads(response.content) self.assertEqual(content.get('name')[0], 'Ensure this value has at most 30 characters (it has 47).', content.get('name')[0])
def test_create_new_po_success(self): post_data = { 'name': 'new_payment_object', 'currency_id': Dummies.get_or_create_currency().guid, 'type_id': Dummies.get_or_create_po_type().guid } number_of_pos = len(PaymentObject.objects.all()) response = self.client.post(self.url, data = post_data, content_type = self.request_content_type) self.assertEqual(response.status_code, 201, response.content) po = json.loads(response.content) self.assertIsInstance(po, dict, po) po = po.get(self.key) self.assertIn('guid', po) self.assertEqual(po['name'], post_data['name']) self.assertEqual(number_of_pos + 1, len(PaymentObject.objects.all()))