Beispiel #1
0
 def test_deserialize_bad_data2(self, bad_mock):
     """ Test deserialization of bad data """
     data = "this is not a dictionary"
     bad_mock.side_effect = TypeError()
     data = {"id": 1, "name": "materials", "category": "widget2", "available": True, "count":1,"condition":"new"}
     inventory = Inventory()
     inventory.deserialize(data)
Beispiel #2
0
def create_inventory():
    """
    Creates Inventory
    This endpoint will create Inventory based the data in the body that is posted
    """
    data = {}
    # Check for form submission data
    if request.headers.get(
            'Content-Type') == 'application/x-www-form-urlencoded':
        app.logger.info('Getting data from form submit')
        data = {
            'name': request.form['name'],
            'category': request.form['category'],
            'available': request.form['available'] == True,
            'condition': request.form['condition'],
            'count': request.form['count']
        }
    else:
        app.logger.info('Getting data from API call')
        data = request.get_json()
    app.logger.info(data)
    inventory = Inventory()
    inventory.deserialize(data)
    inventory.save()
    message = inventory.serialize()
    location_url = url_for('get_inventory',
                           inventory_id=inventory.id,
                           _external=True)
    return make_response(jsonify(message), status.HTTP_201_CREATED,
                         {'Location': location_url})
Beispiel #3
0
 def test_deserialize_a_inventory(self):
     """ Test deserialization of a Inventory """
     data = {"id": 1, "name": "materials", "category": "widget2", "available": True, "count":1,"condition":"new"}
     inventory = Inventory()
     inventory.deserialize(data)
     self.assertNotEqual(inventory, None)
     self.assertEqual(inventory.id, None)
     self.assertEqual(inventory.name, "materials")
     self.assertEqual(inventory.category, "widget2")
     self.assertEqual(inventory.available, True)