Skip to content

Commit ff13580

Browse files
committed
add tests, currently 18 cases for apijson_get
1 parent 46f6fd1 commit ff13580

File tree

12 files changed

+519
-0
lines changed

12 files changed

+519
-0
lines changed

Diff for: tests/demo/.gitignore

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
*.pyc
2+
*.bak
3+
local_settings.ini
4+
build
5+
dist
6+
*.egg-info
7+
.idea
8+
_git
9+
data
10+
database.db
11+
sessions

Diff for: tests/demo/apps/__init__.py

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
__version__ = '0.1'
2+
__url__ = ''
3+
__author__ = ''
4+
__email__ = ''

Diff for: tests/demo/apps/apijson_demo/README.md

Whitespace-only changes.

Diff for: tests/demo/apps/apijson_demo/__init__.py

Whitespace-only changes.

Diff for: tests/demo/apps/apijson_demo/dbinit.py

+158
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,158 @@
1+
#coding=utf-8
2+
from uliweb import models
3+
from uliweb.orm import set_dispatch_send
4+
5+
set_dispatch_send(False)
6+
7+
User = models.user
8+
Privacy = models.privacy
9+
Comment = models.comment
10+
Moment = models.moment
11+
PublicNotice = models.publicnotice
12+
13+
user_list = [
14+
{
15+
"username": "admin",
16+
"nickname": "Administrator",
17+
"email": "admin@localhost",
18+
"date_join": "2018-1-1",
19+
},
20+
{
21+
"username": "usera",
22+
"nickname": "User A",
23+
"email": "usera@localhost",
24+
"date_join": "2018-2-2",
25+
},
26+
{
27+
"username": "userb",
28+
"nickname": "User B",
29+
"email": "userb@localhost",
30+
"date_join": "2018-3-3",
31+
},
32+
{
33+
"username": "userc",
34+
"nickname": "User C",
35+
"email": "userc@localhost",
36+
"date_join": "2018-4-4",
37+
},
38+
]
39+
40+
privacy_list = [
41+
{
42+
"username" : "usera",
43+
"certified" : True,
44+
"phone" : "13333333333",
45+
"balance" : 100,
46+
"password" : "hash_of_123",
47+
"paypassword" : "hash_of_sudfy8e7r",
48+
},
49+
{
50+
"username" : "userb",
51+
"certified" : True,
52+
"phone" : "12222222222",
53+
"balance" : 130,
54+
"password" : "hash_of_dfdfd",
55+
"paypassword" : "hash_of_234erere",
56+
},
57+
{
58+
"username" : "userc",
59+
"certified" : True,
60+
"phone" : "14323424234",
61+
"balance" : 600,
62+
"password" : "hash_of_w3erere",
63+
"paypassword" : "hash_of_ghtwertr",
64+
},
65+
]
66+
67+
moment_list = [
68+
{
69+
"username" : "usera",
70+
"date" : "2018-11-1",
71+
"content" : "test moment",
72+
},
73+
{
74+
"username" : "userb",
75+
"date" : "2018-11-2",
76+
"content" : "test moment from b",
77+
},
78+
{
79+
"username" : "userc",
80+
"date" : "2018-11-6",
81+
"content" : "test moment from c",
82+
},
83+
]
84+
85+
comment_list = [
86+
{
87+
"username" : "usera",
88+
"to_username" : "userb",
89+
"moment_id" : 1,
90+
"date" : "2018-12-1",
91+
"content" : "comment haha",
92+
},
93+
{
94+
"username" : "userb",
95+
"to_username" : "usera",
96+
"moment_id" : 2,
97+
"date" : "2018-12-2",
98+
"content" : "comment xixi",
99+
},
100+
{
101+
"username" : "userc",
102+
"to_username" : "usera",
103+
"moment_id" : 3,
104+
"date" : "2018-12-9",
105+
"content" : "comment hoho",
106+
},
107+
]
108+
109+
publicnotice_list = [
110+
{
111+
"date" : "2018-12-9",
112+
"content" : "notice: a",
113+
},
114+
{
115+
"date" : "2018-12-18",
116+
"content" : "notice: b",
117+
},
118+
]
119+
120+
for d in user_list:
121+
if not User.get(User.c.username==d["username"]):
122+
print("create user '%s'"%(d["username"]))
123+
u = User(**d)
124+
u.set_password("123")
125+
if d["username"]=="admin":
126+
u.is_superuser = True
127+
u.save()
128+
129+
for d in privacy_list:
130+
user = User.get(User.c.username==d["username"])
131+
if user:
132+
d["user_id"] = user.id
133+
print("create privacy record for user '%s'"%(d["username"]))
134+
Privacy(**d).save()
135+
else:
136+
print("error: unknown user '%s'"%(d["username"]))
137+
138+
for d in moment_list:
139+
user = User.get(User.c.username==d["username"])
140+
if user:
141+
d["user_id"] = user.id
142+
print("create moment record for user '%s'"%(d["username"]))
143+
Moment(**d).save()
144+
else:
145+
print("error: unknown user '%s'"%(d["username"]))
146+
147+
for d in comment_list:
148+
user = User.get(User.c.username==d["username"])
149+
if user:
150+
d["user_id"] = user.id
151+
d["to_id"] = User.get(User.c.username==d["to_username"]).id
152+
print("create comment record for user '%s'"%(d["username"]))
153+
Comment(**d).save()
154+
else:
155+
print("error: unknown user '%s'"%(d["username"]))
156+
157+
for d in publicnotice_list:
158+
PublicNotice(**d).save()

Diff for: tests/demo/apps/apijson_demo/models.py

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#coding=utf-8
2+
3+
from uliweb.orm import *
4+
5+
class Privacy(Model):
6+
user_id = Reference("user")
7+
certified = Field(bool)
8+
phone = Field(str)
9+
balance = Field(DECIMAL)
10+
password = Field(str)
11+
paypassword = Field(str)
12+
13+
class Moment(Model):
14+
user_id = Reference("user")
15+
date = Field(datetime.datetime, auto_now_add=True)
16+
content = Field(TEXT)
17+
picture_list = Field(JSON, default=[])
18+
19+
class Comment(Model):
20+
user_id = Reference("user")
21+
to_id = Reference("user")
22+
moment_id = Reference("moment")
23+
date = Field(datetime.datetime, auto_now_add=True)
24+
content = Field(TEXT)
25+
26+
class PublicNotice(Model):
27+
date = Field(datetime.datetime, auto_now_add=True)
28+
content = Field(TEXT)

Diff for: tests/demo/apps/apijson_demo/settings.ini

+72
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
[MODELS]
2+
privacy = 'apijson_demo.models.Privacy'
3+
comment = 'apijson_demo.models.Comment'
4+
moment = 'apijson_demo.models.Moment'
5+
publicnotice = 'apijson_demo.models.PublicNotice'
6+
7+
[APIJSON_MODELS]
8+
user = {
9+
"user_id_field" : "id",
10+
"secret_fields" : ["password"],
11+
"GET" : { "roles" : ["LOGIN","ADMIN","OWNER"] },
12+
"HEAD" : { "roles" : ["LOGIN","ADMIN","OWNER"] },
13+
"POST" : { "roles" : ["ADMIN"] },
14+
"PUT" : { "roles" : ["ADMIN","OWNER"] },
15+
"DELETE" : { "roles" : ["ADMIN"] },
16+
}
17+
privacy = {
18+
"user_id_field" : "user_id",
19+
"GET" : { "roles" : ["OWNER","ADMIN"] },
20+
"HEAD" : { "roles" : ["OWNER","ADMIN"] },
21+
"POST" : { "roles" : ["OWNER","ADMIN"] },
22+
"PUT" : { "roles" : ["OWNER","ADMIN"] },
23+
"DELETE" : { "roles" : ["OWNER","ADMIN"] },
24+
}
25+
moment = {
26+
"user_id_field" : "user_id",
27+
"GET" : { "roles" : ["OWNER","LOGIN","ADMIN","UNKNOWN"] },
28+
"HEAD" : { "roles" : ["OWNER","LOGIN","ADMIN"] },
29+
"POST" : { "roles" : ["OWNER","ADMIN"] },
30+
"PUT" : { "roles" : ["OWNER","ADMIN"] },
31+
"DELETE" : { "roles" : ["OWNER","ADMIN"] },
32+
}
33+
comment = {
34+
"user_id_field" : "user_id",
35+
"GET" : { "roles" : ["OWNER","LOGIN","ADMIN","UNKNOWN"] },
36+
"HEAD" : { "roles" : ["OWNER","LOGIN","ADMIN"] },
37+
"POST" : { "roles" : ["OWNER","ADMIN"] },
38+
"PUT" : { "roles" : ["OWNER","ADMIN"] },
39+
"DELETE" : { "roles" : ["OWNER","ADMIN"] },
40+
}
41+
publicnotice = {
42+
"GET" : { "roles" : ["OWNER","LOGIN","ADMIN","UNKNOWN"] },
43+
"HEAD" : { "roles" : ["OWNER","LOGIN","ADMIN","UNKNOWN"] },
44+
"POST" : { "roles" : ["OWNER","ADMIN"] },
45+
"PUT" : { "roles" : ["OWNER","ADMIN"] },
46+
"DELETE" : { "roles" : ["OWNER","ADMIN"] },
47+
}
48+
49+
[APIJSON_REQUESTS]
50+
moment = {
51+
"POST" :{
52+
"ADD":{"@role": "OWNER"},
53+
"DISALLOW" : ["id"],
54+
"NECESSARY" : ["content"],
55+
},
56+
"PUT" :{
57+
"ADD":{"@role": "OWNER"},
58+
"NECESSARY" : ["id","content"],
59+
},
60+
}
61+
62+
comment = {
63+
"POST" :{
64+
"ADD" :{"@role": "OWNER"},
65+
"DISALLOW" : ["id"],
66+
"NECESSARY" : ["content"]
67+
},
68+
"PUT" :{
69+
"ADD":{"@role": "OWNER"},
70+
"NECESSARY" : ["id","content"],
71+
},
72+
}

Diff for: tests/demo/apps/apijson_demo/static/readme.txt

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
This directory is used to store static files.

Diff for: tests/demo/apps/apijson_demo/templates/readme.txt

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
This directory is used to store template files.

Diff for: tests/demo/apps/settings.ini

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
[GLOBAL]
2+
DEBUG = False
3+
DEBUG_CONSOLE = False
4+
DEBUG_TEMPLATE = False
5+
6+
INSTALLED_APPS = [
7+
'uliweb.contrib.orm',
8+
'uliweb.contrib.auth',
9+
'uliweb.contrib.rbac',
10+
'uliweb_apijson.apijson',
11+
'apijson_demo',
12+
]

Diff for: tests/demo/requirements.txt

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
six
2+
SQLAlchemy
3+
uliweb3
4+
uliweb-apijson

0 commit comments

Comments
 (0)