def test_post_a_payment(self):
     """Create a payment using a POST"""
     js = {'user_id': 0, 'order_id': 0, 'status': PaymentStatus.UNPAID.value,
         'method_id': 0}
     resp = self.app.post('/payments', data=json.dumps(js), follow_redirects=True, content_type='application/json')
     self.assertEqual(resp.status_code, status.HTTP_201_CREATED)
     get_resp = self.app.get('/payments/1')
     p = Payment()
     p.deserialize(json.loads(get_resp.data))
     self.assertEqual(p.id, 1)
Beispiel #2
0
 def test_create_a_payment(self):
     """Create a payment and add it to the database"""
     # pm = PaymentMethod(method_type=PaymentMethodType.CREDIT)
     payment = Payment(user_id=0,
                       order_id=0,
                       status=PaymentStatus.UNPAID,
                       method_id=0)
     self.assertTrue(payment != None)
     payment.save()
     self.assertEqual(payment.id, 1)
     # This should be the only payment in the database, sqlite starts primary keys at 1
     p = Payment.find(1)
     self.assertEqual(p, payment)
    def test_get_a_payment(self):
        """Create a payment, then GET it"""
        js = {'user_id': 0, 'order_id': 0, 'status': PaymentStatus.UNPAID.value,
            'method_id': PaymentMethodType.CREDIT.value}
        resp = self.app.post('/payments', data=json.dumps(js), content_type='application/json')
        self.assertEqual(resp.status_code, status.HTTP_201_CREATED)

        resp = self.app.get('/payments/1')
        self.assertEqual(resp.status_code, status.HTTP_200_OK)
        p = Payment()
        p.deserialize(json.loads(resp.data))
        self.assertEqual(p.id, 1)
        self.assertEqual(p.user_id, js['user_id'])
        self.assertEqual(p.order_id, js['order_id'])
        self.assertEqual(p.status, PaymentStatus(js['status']))
        self.assertEqual(p.method_id, js['method_id'])
Beispiel #4
0
 def test_construct_a_payment(self):
     """Create a payment and assert that it exists and was properly initialized"""
     # pm = PaymentMethod(method_type=PaymentMethodType.CREDIT)
     payment = Payment(user_id=0,
                       order_id=0,
                       status=PaymentStatus.UNPAID,
                       method_id=0)
     self.assertTrue(payment != None)
     self.assertEqual(payment.user_id, 0)
     self.assertEqual(payment.order_id, 0)
     self.assertEqual(payment.status, PaymentStatus.UNPAID)
     self.assertEqual(payment.method_id, 0)
Beispiel #5
0
 def test_recreate_table(self):
     """A test recreate table"""
     payment = Payment(user_id=0,
                       order_id=0,
                       status=PaymentStatus.UNPAID,
                       method_id=0)
     self.assertTrue(payment != None)
     payment.save()
     self.assertEqual(payment.id, 1)
     # This should be the only payment in the database, sqlite starts primary keys at 1
     p = Payment.find(1)
     self.assertEqual(p, payment)
     Payment.remove_all()
     p = Payment.find(1)
     self.assertNotEqual(p, payment)
Beispiel #6
0
 def test_find_payment_by_order(self):
     """Find a payment by its order ID"""
     # pm = PaymentMethod(method_type=PaymentMethodType.CREDIT)
     Payment(user_id=1,
             order_id=1,
             status=PaymentStatus.UNPAID,
             method_id=1).save()
     second_payment = Payment(user_id=2,
                              order_id=2,
                              status=PaymentStatus.PAID,
                              method_id=1)
     second_payment.save()
     p = Payment.find_by_order(second_payment.order_id).first()
     self.assertIsNot(p, None)
     self.assertEqual(p.id, second_payment.id)
     self.assertEqual(p.user_id, 2)
     self.assertEqual(p.order_id, 2)
     self.assertEqual(p.status, PaymentStatus.PAID)