Exemplo n.º 1
0
 def add_w_h(self):
     self.add_user()
     self.add_wiki()
     post_data = MWiki.get_by_uid(self.wiki_uid)
     userinfo = MUser.get_by_uid(self.user_uid)
     aa = MWikiHist.create_wiki_history(post_data, userinfo)
     self.uid = aa
Exemplo n.º 2
0
 def show_info(self):
     '''
     show the user info
     '''
     rec = MUser.get_by_uid(self.userinfo.uid)
     self.render(self.wrap_tmpl('user/{sig}user_info.html'),
                 userinfo=self.userinfo, extinfo=rec.extinfo)
Exemplo n.º 3
0
    def __to_show_info__(self):
        '''
        show the user info
        '''
        rec = MUser.get_by_uid(self.userinfo.uid)
        kwd = {}

        self.render(self.wrap_tmpl('user/{sig}user_info.html'),
                    userinfo=self.userinfo,
                    extinfo=rec.extinfo,
                    kwd=kwd)
Exemplo n.º 4
0
    def __to_show_info__(self):
        '''
        show the user info
        '''
        rec = MUser.get_by_uid(self.userinfo.uid)

        MLog.insert_data(self.userinfo.uid, 'userinfo', 'userinfo')

        self.render(self.wrap_tmpl('user/{sig}user_info.html'),
                    userinfo=self.userinfo,
                    extinfo=rec.extinfo)
Exemplo n.º 5
0
    def render(self, *args, **kwargs):
        user_id = args[0]
        rec = MUser.get_by_uid(user_id)

        return self.render_string('modules/post/user_name.html', rec=rec)
Exemplo n.º 6
0
    def render(self, user_id):
        rec = MUser.get_by_uid(user_id)

        return self.render_string('modules/post/user_name.html', rec=rec)
Exemplo n.º 7
0
class TestMUser():
    def setup(self):
        print('setup 方法执行于本类中每条用例之前')
        self.uu = MUser()
        self.username = '******'
        self.uid = ''

    def test_create_user(self):
        post_data = {
            'user_name': self.username,
            'user_pass': '******',
            'user_email': '*****@*****.**',
        }

        tt = self.uu.create_user(post_data)

        assert tt['success'] == True
        self.tearDown()

    def add_mess(self, **kwargs):
        name = kwargs.get('user_name', self.username)
        post_data = {
            'user_name':
            name,
            'user_pass':
            kwargs.get('user_pass', 'g131322'),
            'user_email':
            kwargs.get('user_email',
                       '{}@kljhqq.com'.format(random.randint(1, 1000000))),
        }

        self.uu.create_user(post_data)
        aa = self.uu.get_by_name(name)
        self.uid = aa.uid

    def test_create_user2(self):
        post_data = {
            'user_name': '',
            'user_pass': '******',
            'user_email': '*****@*****.**',
        }

        tt = self.uu.create_user(post_data)
        assert tt['success'] == False

        post_data = {
            'user_name': '天',
            'user_pass': '******',
            'user_email': '*****@*****.**',
        }

        tt = self.uu.create_user(post_data)
        assert tt['success'] == False

        post_data = {
            'user_name': '/sdfadf',
            'user_pass': '******',
            'user_email': '*****@*****.**',
        }

        tt = self.uu.create_user(post_data)
        assert tt['success'] == False
        self.tearDown()

    def test_update_info(self):
        post_data = {'user_email': '*****@*****.**'}
        self.add_mess()
        user_info = self.uu.get_by_name(self.username)
        tt = self.uu.update_info(user_info.uid, post_data['user_email'])
        assert tt['success'] == True
        self.tearDown()

    def test_update_pass(self):
        self.add_mess()
        post_data = {'user_pass': '******'}
        self.uu.update_pass(self.uid, post_data['user_pass'])
        tt = self.uu.get_by_uid(self.uid)
        assert tt.user_pass == tools.md5(post_data['user_pass'])
        self.tearDown()

    def test_update_role(self):
        self.add_mess()
        post_data = {'role': '1111'}
        self.uu.update_role(self.username, post_data['role'])
        tt = self.uu.get_by_uid(self.uid)
        assert tt.role == post_data['role']
        self.tearDown()

    def test_total_number(self):
        a = self.uu.total_number()
        self.add_mess()
        b = self.uu.total_number()
        assert a + 1 <= b
        self.tearDown()

    def test_query_pager_by_slug(self):
        self.add_mess()
        a = self.uu.total_number()
        x = int(a / 10)
        tf = False
        for i in range(x + 2):

            aa = self.uu.query_pager_by_slug(current_page_num=i)
            for y in aa:
                if y.uid == self.uid:
                    tf = True
        self.tearDown()
        assert tf

    def test_count_of_certain(self):
        a = self.uu.count_of_certain()
        self.add_mess()
        b = self.uu.count_of_certain()
        assert a + 1 <= b
        self.tearDown()

    def test_delete(self):
        user_info = self.uu.get_by_name(self.username)
        self.add_mess()
        user_info2 = self.uu.get_by_name(self.username)
        aa = self.uu.delete(self.uid)
        user_info3 = self.uu.get_by_name(self.username)
        assert aa == True
        assert user_info == user_info3
        assert user_info == None
        assert user_info2.uid == self.uid
        self.tearDown()

    def test_delete_by_user_name(self):
        user_info = self.uu.get_by_name(self.username)
        self.add_mess()
        user_info2 = self.uu.get_by_name(self.username)
        aa = self.uu.delete_by_user_name(self.username)
        user_info3 = self.uu.get_by_name(self.username)
        assert aa == True
        assert user_info == user_info3
        assert user_info == None
        assert user_info2.uid == self.uid
        self.tearDown()

    def test_get_by_keyword(self):
        self.add_mess()
        aa = self.uu.get_by_keyword('me')
        tf = False
        for i in aa:
            if i.uid == self.uid:
                tf = True
        self.tearDown()
        assert tf

    def test_update_time_login(self):
        self.add_mess()
        user_info = self.uu.get_by_name(self.username)
        time.sleep(2)
        self.uu.update_time_login(self.username)
        aa = self.uu.get_by_name(self.username)
        assert user_info.time_login != aa.time_login
        self.tearDown()

    def test_update_time_reset_passwd(self):
        self.add_mess()
        time_r = 11111111
        aa = self.uu.update_time_reset_passwd(self.username, time_r)
        assert aa == True
        aa = self.uu.get_by_name(self.username)
        assert aa.time_reset_passwd == time_r
        self.tearDown()

    def test_query_nologin(self):
        aa = self.uu.query_nologin()
        self.add_mess()
        bb = self.uu.query_nologin()
        assert aa.count() == bb.count()
        self.tearDown()

    def test_check_user_by_email(self):
        post_data = {'user_email': '*****@*****.**', 'user_pass': '******'}
        self.add_mess(**post_data)
        aa = self.uu.check_user_by_email(post_data['user_email'],
                                         post_data['user_pass'])
        assert aa == 1
        self.tearDown()

    def test_check_user_by_name(self):
        post_data = {'user_pass': '******'}
        self.add_mess(**post_data)
        aa = self.uu.check_user_by_name(self.username, post_data['user_pass'])
        assert aa == 1
        self.tearDown()

    def test_check_user(self):
        post_data = {'user_pass': '******'}
        self.add_mess(**post_data)
        aa = self.uu.check_user(self.uid, post_data['user_pass'])
        assert aa == 1
        self.tearDown()

    def test_get_by_email(self):
        post_data = {'user_email': '*****@*****.**'}
        self.add_mess(**post_data)
        aa = self.uu.get_by_email(post_data['user_email'])
        assert aa.uid == self.uid
        self.tearDown()

    def test_set_sendemail_time(self):
        self.add_mess()
        bb = self.uu.get_by_uid(self.uid)

        time.sleep(2)
        self.uu.set_sendemail_time(self.uid)
        aa = self.uu.get_by_uid(self.uid)
        assert bb.time_email <= aa.time_email
        self.tearDown()

    def test_get_by_name(self):
        self.add_mess()
        aa = self.uu.get_by_name(self.username)
        assert aa.uid == self.uid
        self.tearDown()

    def test_get_by_uid(self):
        self.add_mess()
        aa = self.uu.get_by_uid(self.uid)
        assert aa.user_name == self.username
        self.tearDown()

    def test_query_all(self):
        aa = self.uu.query_all()
        tf = True
        for i in aa:
            if i.user_name == self.username:
                tf = False
        assert tf
        self.add_mess()
        aa = self.uu.query_all()
        tf = False
        for i in aa:
            if i.user_name == self.username:
                tf = True
        assert tf
        self.tearDown()

    def test_db_email(self):
        self.tearDown()
        pdata = {
            'user_name': 'asdfdsf',
            'user_pass': '******',
            'user_email': '*****@*****.**',
        }
        MUser.create_user(pdata)
        bb = MUser.create_user(pdata)
        assert bb == {'code': '31', 'success': False}
        self.uu.delete_by_user_name(pdata['user_name'])

    def tearDown(self):
        print("function teardown")
        tt = self.uu.get_by_uid(self.uid)
        if tt:
            self.uu.delete(tt.uid)
        self.uu.delete_by_user_name(self.username)
Exemplo n.º 8
0
class TestMUser():
    def setup(self):
        print('setup 方法执行于本类中每条用例之前')
        self.uu = MUser()
        self.username = '******'
        self.uid = ''

    def test_create_user(self):
        post_data = {
            'user_name': self.username,
            'user_pass': '******',
            'user_email': '*****@*****.**',
        }

        tt = self.uu.create_user(post_data)

        assert tt['success'] == True
        self.tearDown()

    def add_mess(self, **kwargs):
        name = kwargs.get('user_name', self.username)
        post_data = {
            'user_name': name,
            'user_pass': kwargs.get('user_pass', 'g131322'),
            'user_email': kwargs.get('user_email', '*****@*****.**'),
        }

        self.uu.create_user(post_data)
        aa = self.uu.get_by_name(name)
        self.uid = aa.uid

    def test_create_user2(self):
        post_data = {
            'user_name': '',
            'user_pass': '******',
            'user_email': '*****@*****.**',
        }

        tt = self.uu.create_user(post_data)
        assert tt['success'] == False

        post_data = {
            'user_name': '天',
            'user_pass': '******',
            'user_email': '*****@*****.**',
        }

        tt = self.uu.create_user(post_data)
        assert tt['success'] == False

        post_data = {
            'user_name': '/sdfadf',
            'user_pass': '******',
            'user_email': '*****@*****.**',
        }

        tt = self.uu.create_user(post_data)
        assert tt['success'] == False
        self.tearDown()

    def test_update_info(self):
        post_data = {'user_email': '*****@*****.**'}
        self.add_mess()
        user_info = self.uu.get_by_name(self.username)
        tt = self.uu.update_info(user_info.uid, post_data['user_email'])
        assert tt['success'] == True
        self.tearDown()

    def test_update_pass(self):
        self.add_mess()
        post_data = {'user_pass': '******'}
        self.uu.update_pass(self.uid, post_data['user_pass'])
        tt = self.uu.get_by_uid(self.uid)
        assert tt.user_pass == tools.md5(post_data['user_pass'])
        self.tearDown()

    def test_update_role(self):
        post_data = {'role': '1111'}
        tt = self.uu.update_role(self.username, post_data['role'])
        assert tt == True
        self.tearDown()

    # def test_total_number(self):
    #     self.uu.total_number()
    #
    #
    # def test_query_pager_by_slug(self):
    #     self.uu.query_pager_by_slug()
    #
    # def test_count_of_certain(self):
    #     self.uu.count_of_certain()
    #
    # def test_delete(self):
    #     self.uu.delete()
    #
    # def test_delete_by_user_name(self):
    #     self.uu.delete_by_user_name()
    #
    # def test_get_by_keyword(self):
    #     self.uu.get_by_keyword()
    #
    # def test_update_time_login(self):
    #     self.uu.update_time_login()
    #
    # def test_update_time_reset_passwd(self):
    #     self.uu.update_time_reset_passwd()
    #
    # def test_query_nologin(self):
    #     self.uu.query_nologin()
    #
    # def test_check_user_by_email(self):
    #     self.uu.check_user_by_email()
    #
    # def test_check_user_by_name(self):
    #     self.uu.check_user_by_name()
    #
    # def test_check_user(self):
    #     self.uu.check_user()
    #
    # def test_get_by_email(self):
    #     self.uu.get_by_email()

    def test_set_sendemail_time(self):
        self.add_mess()
        bb = self.uu.get_by_uid(self.uid)

        time.sleep(2)
        aa = self.uu.set_sendemail_time(self.uid)
        aa = self.uu.get_by_uid(self.uid)
        assert bb.time_email <= aa.time_email
        self.tearDown()

    def test_get_by_name(self):
        self.add_mess()
        aa = self.uu.get_by_name(self.username)
        assert aa.uid == self.uid
        self.tearDown()

    def test_get_by_uid(self):
        self.add_mess()
        aa = self.uu.get_by_uid(self.uid)
        assert aa.user_name == self.username
        self.tearDown()

    def test_query_all(self):
        aa = self.uu.query_all()
        tf = True
        for i in aa:
            if i.user_name == self.username:
                tf = False
        assert tf
        self.add_mess()
        aa = self.uu.query_all()
        tf = False
        for i in aa:
            if i.user_name == self.username:
                tf = True
        assert tf
        self.tearDown()

    def tearDown(self):
        print("function teardown")
        tt = self.uu.get_by_uid(self.uid)
        if tt:
            self.uu.delete(tt.uid)
        self.uu.delete_by_user_name(self.username)
Exemplo n.º 9
0
class TestMReply():
    def setup(self):
        print('setup 方法执行于本类中每条用例之前')
        self.post = MPost()
        self.user = MUser()
        self.reply = MReply()
        self.r2u = MReply2User()

        self.post_title = 'fwwgccc'
        self.username = '******'
        self.user_uid = ''
        self.reply_uid = ''
        self.post_uid = '998h'
        self.password = '******'

    def add_user(self, **kwargs):
        name = kwargs.get('user_name', self.username)
        post_data = {
            'user_name': name,
            'user_pass': kwargs.get('user_pass', self.password),
            'user_email': kwargs.get('user_email', '*****@*****.**'),
        }

        self.user.create_user(post_data)
        aa = self.user.get_by_name(name)
        self.user_uid = aa.uid

    def add_post(self, **kwargs):
        p_d = {
            'title': kwargs.get('title', self.post_title),
            'cnt_md': kwargs.get('cnt_md', 'grgr'),
            'time_create': kwargs.get('time_create', '1992'),
            'time_update': kwargs.get('time_update', '1996070600'),
            'user_name': self.username,
            'view_count': kwargs.get('view_count', 1),
            'logo': kwargs.get('logo', 'prprprprpr'),
            'memo': kwargs.get('memo', ''),
            'order': kwargs.get('order', '1'),
            'keywords': kwargs.get('keywords', 'sd,as'),
            'extinfo': kwargs.get('extinfo', {}),
            'kind': kwargs.get('kind', '1'),
            'valid': kwargs.get('valid', 1),
        }

        MPost.create_post(self.post_uid, p_d)

    def test_insert_post(self):
        # raw_count = self.post.get_counts()

        self.add_post()
        tt = self.post.get_by_uid(self.post_uid)
        assert tt.title == self.post_title
        self.tearDown()

    def test_insert_user(self):

        self.add_user()
        tt = self.user.get_by_uid(self.user_uid)
        assert tt.user_name == self.username
        self.tearDown()

    def add_reply(self, **kwargs):
        p_d = {
            'post_id': self.post_uid,
            'user_name': self.username,
            'user_id': self.user_uid,
            'category': '0',
            'cnt_reply': kwargs.get('cnt_reply', 'f4klkj进口国海关好姐姐4'),
        }
        uid = self.reply.create_reply(p_d)
        self.reply_uid = uid
        self.r2u.create_reply(self.user_uid, uid)

    def test_insert_reply(self):

        self.add_user()
        self.add_post()
        self.add_reply()
        aa = self.reply.get_by_uid(self.reply_uid)
        assert aa.user_name == self.username
        assert aa.post_id == self.post_uid
        assert aa.user_id == self.user_uid
        self.tearDown()

    def test_update_vote(self):
        self.add_user()
        self.add_post()
        self.add_reply()
        before = self.reply.get_by_uid(self.reply_uid)
        self.reply.update_vote(self.reply_uid, 10)
        after = self.reply.get_by_uid(self.reply_uid)
        assert after.vote == 10
        assert before.vote < after.vote
        self.tearDown()

    def test_delete_by_uid(self):
        self.add_user()
        self.add_post()
        self.add_reply()
        yesrep = self.reply.get_by_uid(self.reply_uid)
        assert yesrep.post_id == self.post_uid
        aa = self.reply.delete_by_uid(self.reply_uid)
        assert aa
        nosrep = self.reply.get_by_uid(self.reply_uid)
        assert nosrep == None
        self.tearDown()

    def test_modify_by_uid(self):
        self.add_user()
        self.add_post()
        self.add_reply()
        p_d = {
            'user_name': self.username,
            'user_id': self.user_uid,
            'category': '1',
            'cnt_reply': '一二三四',
        }
        aa = self.reply.modify_by_uid(self.reply_uid, p_d)
        assert aa == self.reply_uid
        tt = self.reply.get_by_uid(self.reply_uid)
        assert tt.category == p_d['category']
        assert tt.cnt_md == p_d['cnt_reply']
        self.tearDown()

    def test_query_pager(self):
        self.add_user()
        self.add_post()
        self.add_reply()
        aa = self.reply.total_number()
        a = int(aa / 10)
        tf = False
        for i in range(a + 3):

            list = self.reply.query_pager(current_page_num=i)
            for x in list:
                if x.uid == self.reply_uid:
                    tf = True
                    break
        self.tearDown()
        assert tf

    def test_total_number(self):
        aa = self.reply.total_number()
        self.add_user()
        self.add_post()
        self.add_reply()
        bb = self.reply.total_number()
        assert aa + 1 <= bb
        self.tearDown()

    def test_count_of_certain(self):
        aa = self.reply.count_of_certain()
        self.add_user()
        self.add_post()
        self.add_reply()
        bb = self.reply.count_of_certain()
        assert aa + 1 <= bb
        self.tearDown()

    # def test_delete(self):
    #     self.tearDown()
    #     bb = self.reply.count_of_certain()
    #     print(bb)
    #     self.add_user()
    #     self.add_post()
    #     self.add_reply()
    #     bb = self.reply.count_of_certain()
    #     print(bb)
    #     aa=self.reply.get_by_uid(self.reply_uid)
    #     assert aa.post_id==self.post_uid
    #     aa = self.reply.query_by_post(self.post_uid)
    #     tf = False
    #     for i in aa:
    #         if i.uid == self.reply_uid:
    #             tf = True
    #             break
    #     assert tf
    #     vv=self.reply.delete(self.post_uid)
    #     print('LLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLl')
    #     print(vv)
    #     s = self.reply.count_of_certain()
    #     print(s)
    #     # assert vv
    #     aa = self.reply.get_by_uid(self.reply_uid)
    #     self.tearDown()
    #     assert aa==None

    def test_query_all(self):
        self.tearDown()

        aa = self.reply.query_all()
        tf = True
        for i in aa:
            if i.uid == self.reply_uid:
                tf = False
                break
        assert tf
        self.add_user()
        self.add_post()
        self.add_reply()
        bb = self.reply.query_all()
        tf = False
        for i in bb:
            if i.uid == self.reply_uid:
                tf = True
                assert i.post_id == self.post_uid
                break
        assert tf
        self.tearDown()

    def test_get_by_zan(self):

        self.add_user()
        self.add_post()
        self.add_reply()
        aa = self.reply.get_by_zan(self.reply_uid)
        assert aa >= 1
        self.tearDown()

    def test_query_by_post(self):
        self.add_user()
        self.add_post()
        self.add_reply()
        aa = self.reply.query_by_post(self.post_uid)
        tf = False
        for i in aa:
            if i.uid == self.reply_uid:
                tf = True
                break
        assert tf
        self.tearDown()

    def test_get_by_uid(self):
        self.add_user()
        self.add_post()
        self.add_reply()
        aa = self.reply.get_by_uid(self.reply_uid)
        assert aa.user_id == self.user_uid
        self.tearDown()

    def tearDown(self):
        print("function teardown")
        tt = self.post.get_by_uid(self.post_uid)
        if tt:
            self.post.delete(tt.uid)
        self.user.delete_by_user_name(self.username)
        tt = self.user.get_by_uid(self.user_uid)
        if tt:
            self.user.delete(tt.uid)
        tt = self.reply.get_by_uid(self.reply_uid)
        if tt:
            self.reply.delete_by_uid(tt.uid)
        self.r2u.delete(self.reply_uid)
Exemplo n.º 10
0
class TestMReply2User():
    def setup(self):
        print('setup 方法执行于本类中每条用例之前')
        self.user = MUser()
        self.reply = MReply()
        self.r2u = MReply2User()
        self.username = '******'
        self.password = '******'

        self.user_uid = '12345'
        self.reply_uid = '65412'

    def add_user(self, **kwargs):
        name = kwargs.get('user_name', self.username)
        post_data = {
            'user_name': name,
            'user_pass': kwargs.get('user_pass', self.password),
            'user_email': kwargs.get('user_email', '*****@*****.**'),
        }

        self.user.create_user(post_data)
        aa = self.user.get_by_name(name)
        self.user_uid = aa.uid

    def add_reply(self, **kwargs):
        p_d = {
            'post_id': 'gtyu',
            'user_name': self.username,
            'user_id': self.user_uid,
            'category': '0',
            'cnt_reply': kwargs.get('cnt_reply', 'kfjd速度很快很低'),
        }
        uid = self.reply.create_reply(p_d)
        self.reply_uid = uid
        self.r2u.create_reply(self.user_uid, uid)

    def test_create_reply(self):
        self.add_user()
        self.add_reply()
        self.r2u.create_reply(self.user_uid, self.reply_uid)
        aa = self.r2u.get_voter_count(self.reply_uid)
        assert aa >= 1
        self.tearDown()

    #
    # def test_update(self):
    #     self.r2u.update()

    def test_delete(self):
        self.add_user()
        self.add_reply()
        self.r2u.create_reply(self.user_uid, self.reply_uid)
        aa = self.r2u.get_voter_count(self.reply_uid)
        assert aa >= 1
        self.r2u.delete(self.reply_uid)
        aa = self.r2u.get_voter_count(self.reply_uid)
        assert aa == 0
        self.tearDown()

    def test_get_voter_count(self):
        self.add_user()
        self.add_reply()
        self.r2u.create_reply(self.user_uid, self.reply_uid)
        aa = self.r2u.get_voter_count(self.reply_uid)
        assert aa >= 1
        self.tearDown()

    def tearDown(self):
        print("function teardown")
        tt = self.user.get_by_uid(self.user_uid)
        if tt:
            self.user.delete(tt.uid)
        tt = self.reply.get_by_uid(self.reply_uid)
        if tt:
            self.reply.delete_by_uid(tt.uid)
        self.r2u.delete(self.reply_uid)