##// END OF EJS Templates
DEV: Tweaks from PR feedback....
Scott Sanderson -
Show More
@@ -34,16 +34,15 b' def validate_model(model, expect_content):'
34 and 'format'.
34 and 'format'.
35 """
35 """
36 required_keys = {
36 required_keys = {
37 "name"
37 "name",
38 , "path"
38 "path",
39 , "type"
39 "type",
40 , "writable"
40 "writable",
41 , "created"
41 "created",
42 # Note: This key is specified as just 'modified' in IPEP-27
42 "last_modified",
43 , "last_modified"
43 "mimetype",
44 , "mimetype"
44 "content",
45 , "content"
45 "format",
46 , "format"
47 }
46 }
48 missing = required_keys - set(model.keys())
47 missing = required_keys - set(model.keys())
49 if missing:
48 if missing:
@@ -52,8 +51,10 b' def validate_model(model, expect_content):'
52 u"Missing Model Keys: {missing}".format(missing=missing),
51 u"Missing Model Keys: {missing}".format(missing=missing),
53 )
52 )
54
53
55 # Note: Per IPEP-27, 'mimetype' should be present in this list.
56 maybe_none_keys = ['content', 'format']
54 maybe_none_keys = ['content', 'format']
55 if model['type'] == 'file':
56 # mimetype should be populated only for file models
57 maybe_none_keys.append('mimetype')
57 if expect_content:
58 if expect_content:
58 errors = [key for key in maybe_none_keys if model[key] is None]
59 errors = [key for key in maybe_none_keys if model[key] is None]
59 if errors:
60 if errors:
@@ -61,9 +62,12 b' def validate_model(model, expect_content):'
61 500,
62 500,
62 u"Keys unexpectedly None: {keys}".format(keys=errors),
63 u"Keys unexpectedly None: {keys}".format(keys=errors),
63 )
64 )
64
65 else:
65 else:
66 errors = [key for key in maybe_none_keys if model[key] is not None]
66 errors = {
67 key: model[key]
68 for key in maybe_none_keys
69 if model[key] is not None
70 }
67 if errors:
71 if errors:
68 raise web.HTTPError(
72 raise web.HTTPError(
69 500,
73 500,
General Comments 0
You need to be logged in to leave comments. Login now