Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitff13580

Browse files
committed
add tests, currently 18 cases for apijson_get
1 parent46f6fd1 commitff13580

File tree

12 files changed

+519
-0
lines changed

12 files changed

+519
-0
lines changed

‎tests/demo/.gitignore

Lines changed: 11 additions & 0 deletions
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

‎tests/demo/apps/__init__.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
__version__='0.1'
2+
__url__=''
3+
__author__=''
4+
__email__=''

‎tests/demo/apps/apijson_demo/README.md

Whitespace-only changes.

‎tests/demo/apps/apijson_demo/__init__.py

Whitespace-only changes.
Lines changed: 158 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,158 @@
1+
#coding=utf-8
2+
fromuliwebimportmodels
3+
fromuliweb.ormimportset_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+
fordinuser_list:
121+
ifnotUser.get(User.c.username==d["username"]):
122+
print("create user '%s'"%(d["username"]))
123+
u=User(**d)
124+
u.set_password("123")
125+
ifd["username"]=="admin":
126+
u.is_superuser=True
127+
u.save()
128+
129+
fordinprivacy_list:
130+
user=User.get(User.c.username==d["username"])
131+
ifuser:
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+
fordinmoment_list:
139+
user=User.get(User.c.username==d["username"])
140+
ifuser:
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+
fordincomment_list:
148+
user=User.get(User.c.username==d["username"])
149+
ifuser:
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+
fordinpublicnotice_list:
158+
PublicNotice(**d).save()
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#coding=utf-8
2+
3+
fromuliweb.ormimport*
4+
5+
classPrivacy(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+
classMoment(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+
classComment(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+
classPublicNotice(Model):
27+
date=Field(datetime.datetime,auto_now_add=True)
28+
content=Field(TEXT)
Lines changed: 72 additions & 0 deletions
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+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
This directory is used to store static files.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
This directory is used to store template files.

‎tests/demo/apps/settings.ini

Lines changed: 12 additions & 0 deletions
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+
]

‎tests/demo/requirements.txt

Lines changed: 4 additions & 0 deletions
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)

[8]ページ先頭

©2009-2025 Movatter.jp