-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest1.py
More file actions
78 lines (66 loc) · 2.03 KB
/
test1.py
File metadata and controls
78 lines (66 loc) · 2.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
from app import app
def validBookObject(bookObject):
if ("name" in bookObject and "price" in bookObject and "isbn" in bookObject):
return True
else:
return False
valid_object = {
'name': 'N',
'price': 11.99,
'isbn': "1111111111111"
}
missing_name = {
'price': 11.99,
'isbn': "1111111111111"
}
missing_price = {
'name': 'N',
'isbn': "1111111111111"
}
missing_isbn = {
'name': 'N',
'price': 11.99
}
empty_dictionary = {}
bookz = [valid_object, missing_name,
missing_price, missing_isbn, empty_dictionary]
# def validateObjects(objects_list):
# for object in objects_list:
# print(object)
# try:
# if not validBookObject(object):
# objects_list.pop(objects_list.index(object))
# except ValueError:
# print(
# f"Object {objects_list.index(object)}: {object} is invalid. BookObject has to have name, price and isbn.")
# return objects_list
# def validateObjects(objects_list):
# books = []
# invalid = 0
# for object in objects_list:
# print(object)
# if validBookObject(object):
# books.extend(object.items())
# else:
# invalid += 1
# print("Object invalid. BookObject has to have name, price and isbn.")
# for book in books:
# book1 = dict(book[0]=book[1])
# print(book1)
# books.extend(book1)
# print(books)
# try:
# if invalid > 0:
# raise ValueError(
# f"Valid BookObject has to have name, price and isbn. Stopped {invalid} invalid objects from posting.")
# return books
# except ValueError:
# print(
# f"BookObject has to have name, price and isbn. Stopped {invalid} invalid objects from posting.")
# finally:
# return books
@app.route('/books/isbn=<isbn>', methods=['PUT'])
def replace_book_by(isbn):
request_data = request.get_json()
print(request_data)
return json.jsonify(request.get_json())