Skip to content

Commit 89de6d6

Browse files
committed
fix.
1 parent 9cdce3d commit 89de6d6

File tree

14 files changed

+92
-85
lines changed

14 files changed

+92
-85
lines changed

admin_torcms/tests.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,6 @@
22

33
# Create your tests here.
44

5+
56
def test_foo():
6-
assert 1 == 1
7+
assert 1 == 1

application.py

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55

66
from pathlib import Path
7+
78
import router as app_router
89
import torcms.core.router
910
import torcms.core.uifunction as uifuncs

config.py

+4
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
"""
44
Config for the website.
55
"""
6+
from pathlib import Path
7+
68
import tornado.web
79

810
from torcms.core.tools import get_cfg
@@ -14,6 +16,8 @@
1416

1517
DB_CON, SMTP_CFG, SITE_CFG, ROLE_CFG, REDIS_CFG = get_cfg()
1618

19+
BaseDir = Path(__file__).resolve().parent
20+
1721
CMS_CFG = {
1822
"list_num": 10,
1923
"redis_kw": "lsadfkj",

script_faker.py

+42-49
Original file line numberDiff line numberDiff line change
@@ -3,21 +3,20 @@
33
'''
44

55
import os
6-
import bs4
6+
import pathlib
77
import re
8-
import django
9-
import os
108
import sys
11-
import pathlib
12-
from torcms.model.category_model import MCategory
13-
from torcms.model.post_model import MPost
14-
from torcms.handlers.post_handler import update_category
15-
from torcms.model.wiki_model import MWiki
169

10+
import bs4
11+
import django
1712
from faker import Faker
1813

1914
from config import post_cfg
2015
from torcms.core.tools import get_uu4d, get_uuid
16+
from torcms.handlers.post_handler import update_category
17+
from torcms.model.category_model import MCategory
18+
from torcms.model.post_model import MPost
19+
from torcms.model.wiki_model import MWiki
2120

2221
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "administor.settings")
2322
django.setup()
@@ -37,6 +36,8 @@
3736
rest_regs = [
3837
'\<img.+?\/\>',
3938
]
39+
40+
4041
def update_label(post_id, post_data):
4142
'''
4243
Update the label when updating.
@@ -69,18 +70,23 @@ def update_label(post_id, post_data):
6970
else:
7071
MPost2Label.remove_relation(post_id, cur_info.tag_id)
7172

73+
7274
def gen_post(tag_uid):
7375
dt = datetime.now()
7476
post_uid = f'{key}{get_uu4d()}'
7577
extinfo = {}
7678
# 增加地图缺少的信息
7779
if key == 'm':
7880
extinfo = {
79-
'ext_lon':fak.pyfloat(left_digits=3, right_digits=3,min_value=0,max_value=180),
80-
'ext_lat':fak.pyfloat(left_digits=2, right_digits=3,min_value=0,max_value=90),
81-
'ext_zoom_current':'4',
82-
'ext_zoom_max':'7',
83-
'ext_zoom_min':'1',
81+
'ext_lon': fak.pyfloat(
82+
left_digits=3, right_digits=3, min_value=0, max_value=180
83+
),
84+
'ext_lat': fak.pyfloat(
85+
left_digits=2, right_digits=3, min_value=0, max_value=90
86+
),
87+
'ext_zoom_current': '4',
88+
'ext_zoom_max': '7',
89+
'ext_zoom_min': '1',
8490
}
8591
dict_info = {
8692
'uid': post_uid,
@@ -91,13 +97,19 @@ def gen_post(tag_uid):
9197
'time_create': dt.timestamp(),
9298
'time_update': dt.timestamp(),
9399
'kind': key,
94-
'extinfo':extinfo
100+
'extinfo': extinfo,
95101
}
96102
uu = TabPost.objects.get_or_create(uid=post_uid, defaults=dict_info)
97103
return post_uid
98-
def gen_label(post_uid,kind):
99-
post_data = {'tags': '{},{}'.format(fak.text(max_nb_chars=5), fak.text(max_nb_chars=5))}
104+
105+
106+
def gen_label(post_uid, kind):
107+
post_data = {
108+
'tags': '{},{}'.format(fak.text(max_nb_chars=5), fak.text(max_nb_chars=5))
109+
}
100110
update_label(post_uid, post_data)
111+
112+
101113
pwd = os.getcwd()
102114

103115

@@ -133,7 +145,7 @@ def filter_reg_text(inws, out_reg_arr):
133145
img_path = pathlib.Path(inws)
134146
for wfile in img_path.rglob('*'):
135147
if img == wfile.name:
136-
img = str(wfile.resolve())[len(pwd):]
148+
img = str(wfile.resolve())[len(pwd) :]
137149
tt.append('src="{}"'.format(img))
138150
else:
139151
tt.append(bb)
@@ -142,8 +154,6 @@ def filter_reg_text(inws, out_reg_arr):
142154
return outarr
143155

144156

145-
146-
147157
def do_for_chapter(cat_id, ch_path):
148158
file_path = []
149159
idx = 1
@@ -174,7 +184,6 @@ def do_for_chapter(cat_id, ch_path):
174184

175185
def do_for_page(cat_id, ch_path, filename, idx):
176186
for x in ch_path.rglob('*.html'):
177-
178187
if x.name.startswith(filename):
179188
pass
180189
else:
@@ -188,7 +197,6 @@ def do_for_page(cat_id, ch_path, filename, idx):
188197

189198

190199
def get_page_meta(catid, the_file, idx):
191-
192200
print(the_file.name)
193201
File = open(str(the_file.resolve()))
194202
Soup = bs4.BeautifulSoup(File.read(), features="html.parser")
@@ -208,7 +216,6 @@ def get_page_meta(catid, the_file, idx):
208216

209217

210218
def get_meta(catid, sig, the_file, idx):
211-
212219
File = open(str(the_file.resolve()))
213220
Soup = bs4.BeautifulSoup(File.read(), features="html.parser")
214221
title = Soup.select('h1')[0].getText()
@@ -219,7 +226,6 @@ def get_meta(catid, sig, the_file, idx):
219226
result[1::2] = vv
220227
content = ' '.join(result)
221228

222-
223229
pp_data = {}
224230
pp_data['uid'] = sig
225231
pp_data['title'] = str(title)[:-1]
@@ -240,7 +246,6 @@ def get_meta(catid, sig, the_file, idx):
240246

241247
def get_catname(ch_path, filename):
242248
for x in ch_path.rglob('*.html'):
243-
244249
if x.name.startswith(filename):
245250
pass
246251
else:
@@ -271,7 +276,6 @@ def bianli(inws):
271276
idx = max_order + 1
272277

273278
for wdir in wdirs:
274-
275279
if wdir.startswith('ch') and len(wdir.split('_')) > 2:
276280
pass
277281
else:
@@ -298,41 +302,29 @@ def bianli(inws):
298302
else:
299303
cat_name = cat_slug
300304

301-
post_data = {'name': cat_name,
302-
'slug': cat_slug.lower(),
303-
'order': idx,
304-
'kind': 'k',
305-
'pid': pid}
305+
post_data = {
306+
'name': cat_name,
307+
'slug': cat_slug.lower(),
308+
'order': idx,
309+
'kind': 'k',
310+
'pid': pid,
311+
}
306312

307313
try:
308314
MCategory.add_or_update(cat_id, post_data)
309315
except Exception:
310316
pass
311317

312-
do_for_chapter(
313-
cat_id,
314-
pathlib.Path(os.path.join(wroot, wdir))
315-
)
318+
do_for_chapter(cat_id, pathlib.Path(os.path.join(wroot, wdir)))
316319

317320
# 将 chapter.html 内容存入数据库, page/catid 形式访问
318-
do_for_page(
319-
cat_id,
320-
pathlib.Path(os.path.join(wroot, wdir)),
321-
'chapter',
322-
idx
323-
)
321+
do_for_page(cat_id, pathlib.Path(os.path.join(wroot, wdir)), 'chapter', idx)
324322
# 将 index.html 内容存入数据库, page/catid 形式访问
325-
do_for_page(
326-
pid,
327-
pathlib.Path(os.path.join(wroot)),
328-
'index',
329-
idx
330-
)
323+
do_for_page(pid, pathlib.Path(os.path.join(wroot)), 'index', idx)
331324

332325
idx = idx + 1
333326

334327

335-
336328
if __name__ == '__main__':
337329
# gen()
338330

@@ -354,10 +346,12 @@ def bianli(inws):
354346
else:
355347
tag_recs = TabTag.objects.filter(kind=key).all()
356348
for tag_rec in tag_recs:
349+
if tag_rec.uid.endswith('00'):
350+
continue
357351
for ii in range(10):
358352
post_uid = gen_post(tag_rec.uid)
359353
print(post_uid)
360-
gen_label(post_uid,key)
354+
gen_label(post_uid, key)
361355
post2tag = TabPost2Tag(
362356
uid=get_uuid(),
363357
par_id=f'{tag_rec.uid[:2]}00',
@@ -367,7 +361,6 @@ def bianli(inws):
367361
)
368362
post2tag.save()
369363

370-
371364
#
372365
# recs = TabPost.objects.filter().all()
373366
# for rec in recs:

tests/test_http/test_db_postinfo.py

+12-11
Original file line numberDiff line numberDiff line change
@@ -7,20 +7,19 @@
77
'''
88

99
import os
10+
from datetime import datetime
11+
1012
import requests
13+
from faker import Faker
1114
from tornado.testing import AsyncHTTPSTestCase
15+
16+
from cfg import SITE_CFG
17+
from config import post_cfg
1218
from server import APP
19+
from torcms.core.tools import get_uu4d, get_uuid
1320
from torcms.model.category_model import MCategory
1421
from torcms.model.post_model import MPost
1522

16-
from faker import Faker
17-
from datetime import datetime
18-
from torcms.core.tools import get_uu4d, get_uuid
19-
20-
from config import post_cfg
21-
from cfg import SITE_CFG
22-
23-
2423
fak = Faker('zh_CN')
2524
domain = SITE_CFG['site_url']
2625

@@ -31,13 +30,15 @@ def get_app(self):
3130

3231
def test_posthandler_view_edit_delete(self):
3332
for key in post_cfg:
34-
if key != '2':
33+
if key not in ['2', 's']:
3534
postinfos = MPost.query_all(kind=key)
3635
for post in postinfos:
3736
pass
3837
# # Todo:app类型数据报错信息tornado.general:web.py:3118 Could not open static file '/gitee/TorCMS/static/f2elib/bootstrap-star-rating-master/css/star-rating.css'
39-
print('/{0}/{1}'.format(post_cfg[key]['router'],post.uid))
40-
response = self.fetch('/{0}/{1}'.format(post_cfg[key]['router'],post.uid))
38+
print('/{0}/{1}'.format(post_cfg[key]['router'], post.uid))
39+
response = self.fetch(
40+
'/{0}/{1}'.format(post_cfg[key]['router'], post.uid)
41+
)
4142
self.assertEqual(response.code, 200)
4243
# response_edit = self.fetch('/{0}/_edit/{1}'.format(post_cfg[key]['router'],post.uid))
4344
# self.assertEqual(response_edit.code, 200)

tests/test_http/test_reply.py

-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
from tornado.testing import AsyncHTTPTestCase
55

66
from server import APP
7-
87
from torcms.model.reply_model import MReply
98

109
reply_list = MReply.query_all()

tests/test_http/test_tags.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,10 @@
22
import unittest
33

44
from tornado.testing import AsyncHTTPTestCase
5-
from torcms.model.category_model import MCategory
6-
from server import APP
5+
76
from config import post_cfg
7+
from server import APP
8+
from torcms.model.category_model import MCategory
89

910
tags = MCategory.query_all()
1011

tests/test_http/test_wiki.py

-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
from tornado.testing import AsyncHTTPTestCase
55

66
from server import APP
7-
87
from torcms.model.wiki_model import MWiki
98

109
wiki_list = MWiki.query_all(limit=None)

tests/test_requests/test_post.py

+18-12
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,22 @@
1-
21
import os
2+
from datetime import datetime
3+
34
import requests
5+
from faker import Faker
46
from tornado.testing import AsyncHTTPSTestCase
7+
8+
from cfg import SITE_CFG
9+
from config import post_cfg
510
from server import APP
11+
from torcms.core.tools import get_uu4d, get_uuid
612
from torcms.model.category_model import MCategory
713
from torcms.model.post_model import MPost
814

9-
from faker import Faker
10-
from datetime import datetime
11-
from torcms.core.tools import get_uu4d, get_uuid
12-
13-
from config import post_cfg
14-
from cfg import SITE_CFG
15-
16-
1715
fak = Faker('zh_CN')
1816

1917
domain = SITE_CFG['site_url']
2018

19+
2120
class TestPostHandler(AsyncHTTPSTestCase):
2221
def get_app(self):
2322
return APP
@@ -28,16 +27,23 @@ def test_posthandler_view_edit_delete(self):
2827
print(key)
2928
postinfos = MPost.query_all(kind=key)
3029
for post in postinfos:
31-
response = requests.get(os.path.join(domain,'{0}/{1}'.format(post_cfg[key]['router'], post.uid)))
30+
response = requests.get(
31+
os.path.join(
32+
domain, '{0}/{1}'.format(post_cfg[key]['router'], post.uid)
33+
)
34+
)
3235
self.assertEqual(response.status_code, 200)
3336

34-
3537
def test_posthandler_add(self):
3638
for k in post_cfg:
3739
for ii in range(3):
3840
postuid = f'{k}{get_uu4d()}'
3941
while MPost.get_by_uid(postuid):
4042
postuid = f'{k}{get_uu4d()}'
4143

42-
response = requests.get(os.path.join(domain,'{0}/_add/{1}'.format(post_cfg[k]['router'], postuid)))
44+
response = requests.get(
45+
os.path.join(
46+
domain, '{0}/_add/{1}'.format(post_cfg[k]['router'], postuid)
47+
)
48+
)
4349
self.assertEqual(response.status_code, 200)

0 commit comments

Comments
 (0)