def test_serialize_a_cart(self): """ Test serialization of a Cart """ shopcart = ShoppingCart(state="deactivated", userId=10) data = shopcart.serialize() self.assertNotEqual(data, None) self.assertIn('id', data) self.assertEqual(data['id'], None) self.assertIn('state', data) self.assertEqual(data['state'], "deactivated") self.assertIn('userId', data) self.assertEqual(data['userId'], 10)
def create_carts(): """ Create a new Cart """ app.logger.info('Create Cart requested') check_content_type('application/json') cart = ShoppingCart(None) cart.deserialize(request.get_json()) cart.save() app.logger.info('Created Cart with id: {}'.format(cart.id)) return make_response( jsonify(cart.serialize()), status.HTTP_201_CREATED, {'Location': url_for('get_carts', cart_id=cart.id, _external=True)})