forked from argomaintainer/argon
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_model.py
executable file
·124 lines (101 loc) · 3.41 KB
/
test_model.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
#!/usr/bin/env python
# -*- coding: utf-8 -*-
__metaclass__ = type
import model
from datetime import datetime
import sys,inspect
"""
Uint test for db_orm
"""
class Holder:
### TODO
def init_database(self):
u'''
初始化数据库。
'''
print
print 'Init Database will kill all data. Are you sure?'
print
print 'Type INIT_YES to continue.',
if raw_input() == 'INIT_YES' :
print 'Init Database start ...'
model.init_database()
print 'Init Database DONE.'
print 'All DONE.'
def get_all_section(self):
u'''
输出全部的讨论区。
'''
secs = model.Section.get_all()
print '\r\n'.join(map(str,secs))
def add_section(self,sectionname,description):
u'''
增加一个讨论区。
'''
print 'Add Section : [%s] %s' % (sectionname,description)
s = model.Section(sectionname=sectionname,description=description)
s.save()
print 'All DONE.'
def del_section(self,sectionname):
u'''
删除一个讨论区。
'''
print 'Del Section : [%s] ' % sectionname
s = model.Section.get_by_sectionname(sectionname)
if s is None :
print 'No such Section.'
else:
s.delete()
print 'All DONE.'
def add_board(self,boardname,sectionname,description):
u'''
增加一个讨论区。
'''
b = model.Board(boardname=boardname,
sid=model.Section.get_sid_by_name(sectionname),
description=description)
b.save()
print 'Add board %s to %s DONE. ' % (boardname,sectionname)
# def get_section_board(self,sectionname):
# res = model.Board.all(sid = model.Section.get_sid_by_name(sectionname))
# print '\r\n'.join(map(str,res))
# def add_post(self,boardname,title,owner,content,fromhost):
# p = model.Post(bid = model.Board.get_id_by_name(boardname),
# title = title,owner=owner,content=content,fromhost=fromhost)
# p.save()
# print "Add post %s to %s DONE." % (title,boardname)
# def get_board_post(self,boardname):
# b = db_orm.get_board(boardname)
# da = b.get_post(0)
# for post in da :
# print post.dict
# def add_user(self,userid,passwd):
# db_orm.add_user(userid,passwd,{'firstlogin':datetime.now()})
# print 'Add user %s DONE.' % userid
# def get_user(self, userid = 'Jia'):
# u = db_orm.get_user(userid)
# print u.dump_attr()
# def login(self, name, passwd):
# u = db_orm.login(name, passwd)
# if u == None:
# print 'login error'
# return
# print 'online: ' , db_orm.get_online_users()
# print u.dump_attr()
# def online_users(self):
# users = db_orm.get_online_users()
# print users
def help(self,command):
foo = getattr(self,command)
print
print command + ' [' + ' '.join(inspect.getargspec(foo)[0][1:]) +']\n'
print getattr(self,command).__doc__
def usage(self):
print '\r\n'.join(filter(lambda x : not x.endswith('__'),dir(self)))
def run(self):
while True:
input()
t = Holder()
if len(sys.argv) < 2: t.usage()
else:
getattr(t, sys.argv[1])(*sys.argv[2:])