-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtests_int.py
141 lines (120 loc) · 3.22 KB
/
tests_int.py
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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
__author__ = 'izaac'
import validictory
import json
import requests
# Validator following the http://json-schema.org guidelines using the python validictory library
# This is for integration and acceptance test
schema_following = {
"type": "object",
"properties": {
"user_is_following": {
"type": "array",
"items": [
{"type": "object",
"properties": {
"username": {"type": "string"},
"id": {"type": "integer"}
}
}
]
}
}
}
schema_followers = {
"type": "object",
"properties": {
"its_followers": {
"type": "array",
"items": [
{"type": "object",
"properties": {
"username": {"type": "string"},
"id": {"type": "integer"}
}
}
]
}
}
}
schema_message = {
"type": "object",
"properties": {
"message": {"type": "string"}
}
}
# Known validictory module issue about the _data is not of type object
# https://github.com/sunlightlabs/validictory/issues/49
# TODO: Follow up bug for validation/regression
schema_twitt = {
"type": "object",
"properties": {
"messages": {
"type": "array",
"items": [
{"type": "object",
"properties": {
"text": {"type": "string"},
"pub_date": {
"type": "array",
"items": [
{"type": "string"},
{"type": "string"}
]
}
}
}
]
}
}
}
def validate_json():
headers = {'content-type': 'application/json'}
#test following
r = requests.get('http://127.0.0.1:5000/user/user1/following?key=d5ef19c2b1714f87e0042e4f822bf722b30239f7',
headers=headers)
try:
validictory.validate(r.content, schema_following)
except ValueError, error:
print error
########################################################
# /user/<username>/following
# {
# "its_followers": [
# {
# "username": "user8",
# "id": 8
# }
# ]
# }
#json_followers = json.loads('{"its_followers": [{"username": "user8", "id": 8}]}')
########################################################
# Generic json message
# {
# "message": "<String>"
# }
#json_message = json.loads('{"message": "You can\'t follow user2"}')
########################################################
# /user/<username>
# {
# "messages": [
# {
# "text": "example message",
# "pub_date": [
# "2013-05-08",
# "07:59:13"
# ],
# "message_id": 98,
# "user_id": 3
# }
# }
#
# dump_twitt = json.dumps('{"messages": [ { "text": "example text", \
# "pub_date": ["2013-05-08", "07:59:13" ], \
# "message_id": 98, "user_id": 3 }}')
# json_twitt = json.loads(dump_twitt)
#
#
# try:
# validictory.validate(json_twitt, schema_twitt)
# except ValueError, error:
# print errro