Пример #1
0
    def setUp(self):
        """
        所有单元测试前的 基础设置,注册用户、创建项目
        by:王健 at:2015-1-10
        增加了smsdebug 参数,方便测试
        by:王健 at:2015-1-15
        修改个人信息返回值
        by:王健 at:2015-1-20
        :return:
        """
        # 注册新用户
        newuserdata = {"password": '******', 'tel': username,
                       'name': truename, 'smsdebug': 'sdf' }
        response = self.client.post('/ns/reg_user', newuserdata)

        self.assertEqual(200, response.status_code, u'注册新用户报错')
        user = get_user_model().objects.get(tel=username)
        self.assertJSONEqual(response.content, getTestResult(True, u'注册成功', user.get_user_map(True)), u'注册新用户,返回结果有变化,需要确认,或修改单元测试')

        # 创建项目
        newuserdata = {"name": u'测试项目1', 'total_name': u'单元测试创建的项目',  'jzmj': 300, 'jglx': u'钢结构',
                       'jzcs': 3, 'htzj': 340000, 'kg_date': '2015-12-01', 'days': 50, 'address': 1,
                       'jsdw': u'水水水水是建设六局',  'jsdw_fzr': u'小刘', 'jsdw_fzr_tel': '18632234548',
                       'kcdw': u'勘察第一分院', 'kcdw_fzr': u'喜洋洋', 'kcdw_fzr_tel': '321313',
                       'sjdw': u'设计第二院', 'sjdw_fzr': u'灰太狼', 'sjdw_fzr_tel': '5455',
                       'sgdw': u'施工第三局', 'sgdw_fzr': u'美羊羊', 'sgdw_fzr_tel': '741165',
                       'jldw': u'监理第二单位', 'jldw_fzr': u'村长', 'jldw_fzr_tel': '7881131',
        }
        response = self.client.post('/ns/reg_project', newuserdata)


        self.assertEqual(200, response.status_code, u'注册新用户报错')
        project = Project.objects.filter(manager=user)[0]
        self.assertJSONEqual(response.content, getTestResult(True, u'成功创建:%s' % project.total_name, MyEncoder.default(project)), u'创建项目,返回结果有变化,需要确认,或修改单元测试')
Пример #2
0
 def update_company_column(self, company_id, name, columntype, index_num, is_active, father_id, flag, company_column_id):
     """
     修改公司栏目
     by:尚宗凯 at:2015-06-11
     """
     resonse = self.client.post('/cp/update_company_column', {"company_id":company_id, "name":name, "columntype":columntype, "index_num":index_num, "is_active":is_active, "father_id":father_id, "flag":flag, "company_column_id":company_column_id})
     if company_column_id:
         if CompanyColumn.objects.filter(pk=company_column_id).exists():
             cc = CompanyColumn.objects.get(pk=company_column_id)
             if company_id:
                 cc.company_id = company_id
             if name:
                 cc.name = name
             if columntype:
                 cc.columntype = columntype
             if index_num:
                 cc.index_num = index_num
             if is_active == "False":
                 cc.is_active = False
             if is_active == "True":
                 cc.is_active = True
             if father_id:
                 cc.father_id = father_id
             if flag:
                 cc.flag = father_id
             cc.timeline = timezone.now()
             cc.save()
             self.assertJSONEqual(resonse.content, getTestResult(True, u'修改公司栏目成功'),
                      u'错误')
Пример #3
0
 def create_zhgl_company_news(self, company_id, type_flag, flag, user_id):
     """
     测试
     by:尚宗凯 at:2015-07-02
     """
     resonse = self.client.post('/cp/%s/create_zhgl_company_news'%str(company_id), {"type_flag":type_flag, "flag":flag})
     company_column_id = CompanyColumn.objects.get(company_id=company_id, flag=flag).pk
     sn = CompanyNews()
     sn.company_id = company_id
     sn.company_column_id = company_column_id
     sn.author_id = user_id
     sn.pre_title = ""
     # if type_flag not in ("files", "images"):
     #     sn.pre_content = ""
     # else:
     #     fileids = [x for x in request.REQUEST.get('fileid', '').strip(',').split(',') if x]
     #     for fid in fileids:
     #         sn.append_file(fid)
     sn.title = sn.pre_title
     sn.content = sn.pre_content
     sn.is_active = True
     if type_flag:
         sn.type_flag = type_flag
     try:
         sn.save()
         self.assertJSONEqual(resonse.content["message"], getTestResult(True, u'创建公司新闻成功'),
                          u'错误')
     except Exception:
         pass
Пример #4
0
 def get_child_comapny_column_list(self, company_id, flag):
     """
     单元测试
     by:尚宗凯 at:2015-07-02
     """
     resonse = self.client.post('/cp/%s/get_child_comapny_column_list' % str(company_id), {"flag":flag})
     columns = [x.toJSON() for x in CompanyColumn.objects.filter(company_id=company_id, father__flag=flag, is_active=True).order_by('index_num')]
     self.assertJSONEqual(resonse.content, getTestResult(True, u"success", columns),
                          u'错误')
Пример #5
0
 def get_company_column_by_flag(self, company_id, flag="GONGSIJIANJIE"):
     """
     单元测试
     by:尚宗凯 at:2015-07-03
     """
     resonse = self.client.post('/cp/%s/get_company_column_by_flag' % str(company_id), {"flag":flag})
     if CompanyColumn.objects.filter(company_id=company_id, flag=flag):
         cc = CompanyColumn.objects.get(company_id=company_id, flag=flag)
     self.assertJSONEqual(resonse.content, getTestResult(True, u"获取公司企业动态信息成功", {"company_column_id":cc.pk}),
                          u'错误')
Пример #6
0
    def get_company_detail_by_id(self, company_id):
        """
        单元测试
        by:尚宗凯 at:2015-07-02
        """
        resonse = self.client.post('/cp/%s/get_company_detail_by_id' % str(company_id))
        if Company.objects.filter(pk=company_id).exists():
            c = Company.objects.get(pk=company_id)

        self.assertJSONEqual(resonse.content, getTestResult(True, u"success", c.toJSON()),
                             u'错误')
Пример #7
0
 def query_company_by_bigcompnay(self):
     """
     单元测试
     by:尚宗凯 at:2015-07-02
     """
     resonse = self.client.post('/cp/query_company_by_bigcompnay')
     c = Company.objects.all()
     c = MyEncoder.default(c)
     self.assertEqual(200, resonse.status_code, u'错误')
     self.assertJSONEqual(resonse.content, getTestResult(True, u"success", c),
                          u'错误')
Пример #8
0
 def get_sys_column_by_column_id(self, sys_column_id):
     """
     单元测试
     by:尚宗凯 at:2015-07-02
     """
     resonse = self.client.post('/cp/get_sys_column_by_column_id', {"sys_column_id":sys_column_id})
     if SysColumn.objects.filter(pk=sys_column_id).exists():
         query = SysColumn.objects.get(pk=sys_column_id)
     self.assertEqual(200, resonse.status_code, u'错误')
     self.assertJSONEqual(resonse.content, getTestResult(True, u'', query.toJSON()),
                          u'错误')
Пример #9
0
 def get_qn_upload_files_url(self, project_id):
     """
     七牛,获取附件上传的url
     by:范俊伟 at:2015-4-8
     :return:
     """
     response = self.client.post('/nf/%s/get_qn_upload_files_url' % project_id, {'filename': u'沙发上地方的说法', 'size': 30*1024, 'filetype': 'image'})
     self.assertEqual(200, response.status_code, u'获取附件上传的url 错误')
     fileobj = File.objects.all()[1]
     self.assertJSONEqual(response.content, getTestResult(True, u'', {'fileid': fileobj.pk, 'posturl': fileobj.get_qn_post_url(), 'params': fileobj.get_qn_params()}),
                          u'七牛,获取附件上传的url,返回结果有变化,需要确认,或修改单元测试')
Пример #10
0
 def get_permission(self, company_id):
     """
     单元测试
     by:尚宗凯 at:2015-07-02
     """
     resonse = self.client.post('/cp/%s/get_permission' % str(company_id))
     p = Permission.objects.filter(company_id=company_id)
     result = []
     for i in p:
         result.append( str(CompanyColumn.objects.get(pk=i.column_id).flag)+"*"+str(i.group_flag)+"*"+str(i.perm))
     self.assertJSONEqual(resonse.content, getTestResult(True, u"success", result),
                          u'错误')
Пример #11
0
 def get_all_big_company(self):
     """
     测试
     by:尚宗凯 at:2015-06-11
     """
     resonse = self.client.post('/cp/get_all_big_company', {})
     bc = BigCompany.objects.all()
     result = []
     for i in bc:
         result.append(i.toJSON())
     self.assertJSONEqual(resonse.content, getTestResult(True, u'获取默认展示的集团成功', result),
                          u'错误')
Пример #12
0
 def get_default_sys_news(self):
     """
     测试
     by:尚宗凯 at:2015-06-11
     """
     resonse = self.client.post('/cp/get_default_sys_news', {})
     sn = SysNews.objects.all()
     result = []
     for i in sn:
         result.append(i.toJSON())
     self.assertJSONEqual(resonse.content, getTestResult(True, u'默认展示的行业资讯成功', result),
                          u'错误')
Пример #13
0
 def get_url_by_file(self, project_id, fileid):
     """
     获取文件下载url 测试
     by:王健 at:2015-1-12
     :return:
     """
     # 我关注的项目列表
     login_response = self.client.post('/nf/%s/get_url_by_file' % project_id, {'fileid': fileid})
     self.assertEqual(200, login_response.status_code, u'获取文件下载url 错误')
     fileobj = File.objects.get(pk=fileid)
     self.assertJSONEqual(login_response.content, getTestResult(True, u'', {'id': fileobj.id, 'geturl': fileobj.get_url(), 'name': fileobj.name, 'filetype': fileobj.filetype, 'size': fileobj.size, 'img_size':fileobj.img_size}),
                          u'获取文件下载url,返回结果有变化,需要确认,或修改单元测试')
Пример #14
0
 def get_my_save_news(self, user_id):
     """
     测试
     by:尚宗凯 at:2015-06-11
     """
     resonse = self.client.post('/cp/get_my_save_news')
     news = SaveNews.objects.filter(user_id=user_id)
     result = []
     for i in news:
         result.append(i.toJSON())
     self.assertJSONEqual(resonse.content, getTestResult(True, u'获取我的收藏成功', result),
                          u'错误')
Пример #15
0
 def query_company_by_name(self):
     """
     测试
     by:尚宗凯 at:2015-07-02
     """
     resonse = self.client.post('/cp/query_company_by_name')
     l = Company.objects.all()
     l = l.order_by('-create_time')[0:20]
     l = MyEncoder.default(l)
     self.assertEqual(200, resonse.status_code, u'错误')
     self.assertJSONEqual(resonse.content, getTestResult(True, u"success", l),
                          u'错误')
Пример #16
0
 def query_company_project(self, company_id, key="123"):
     """
     单元测试
     by:尚宗凯 at:2015-07-03
     """
     resonse = self.client.post('/cp/%s/query_company_project' % str(company_id))
     projects = Project.objects.filter(company_id=company_id).filter(Q(name__icontains=key) | Q(total_name__icontains=key))
     result = []
     for i in projects[0:20]:
         result.append(i.toJSON())
     self.assertJSONEqual(resonse.content, getTestResult(True, u"success", result),
                          u'错误')
Пример #17
0
 def cancel_release_sys_news(self, sys_news_id):
     """
     客服取消发布新闻
     by:尚宗凯 at:2015-06-11
     """
     resonse = self.client.post('/cp/cancel_release_sys_news', {"sys_news_id":sys_news_id})
     if sys_news_id and SysNews.objects.filter(pk=sys_news_id).exists():
         sys_news = SysNews.objects.get(pk=sys_news_id)
         sys_news.is_active = False
         sys_news.save()
     self.assertJSONEqual(resonse.content, getTestResult(True, u'客服取消发布新闻成功'),
                          u'错误')
Пример #18
0
 def show_zhgl_list(self, company_id, column_id):
     """
     单元测试
     by:尚宗凯 at:2015-07-03
     """
     resonse = self.client.post('/cp/zhgl/%s/%s'% (str(company_id), str(column_id)))
     page_start = 0
     newsquery = CompanyNews.objects.filter(company_id=company_id, company_column_id=column_id, is_active=True).order_by('-publish_time')
     l = []
     for n in newsquery[page_start:page_start+20]:
         l.append(n.toJSON2())
     self.assertJSONEqual(resonse.content, getTestResult(True, u'',l),
                          u'错误')
Пример #19
0
 def add_user_to_company(self, user_id_list ,company_id):
     """
     测试
     by:尚宗凯 at:2015-07-02
     """
     response = self.client.post('/cp/add_user_to_company', {"id":user_id_list,"company_id":company_id})
     user_ids = [int(x) for x in user_id_list]
     ids = [x[0] for x in CompanyPerson.objects.filter(user_id__in=user_ids, company_id=company_id).values_list('user_id')]
     for user in get_user_model().objects.filter(pk__in=set(user_ids)-set(ids)):
         cp,created = CompanyPerson.objects.get_or_create(user=user, company_id=company_id)
     self.assertEqual(200, response.status_code, u'错误')
     self.assertJSONEqual(response.content, getTestResult(True, u'添加成员成功'),
                      u'错误')
Пример #20
0
 def cancel_follow_company(self, user_id, company_id):
     """
     测试
     by:尚宗凯 at:2015-06-11
     """
     resonse = self.client.post('/cp/cancel_follow_company', {"company_id":company_id})
     if company_id != "":
         if FollowCompany.objects.filter(company_id=company_id, user_id=user_id).exists():
             fc = FollowCompany.objects.filter(company_id=company_id, user_id=user_id)
             for i in fc:
                 i.delete()
     self.assertJSONEqual(resonse.content, getTestResult(True, u'取消关注企业成功'),
                          u'错误')
Пример #21
0
 def get_company_column_by_company(self, company_id):
     """
     单元测试
     by:尚宗凯 at:2015-07-03
     """
     resonse = self.client.post('/cp/%s/get_company_column_by_company' % str(company_id))
     father_cc = CompanyColumn.objects.get(company_id=company_id, flag='ZONGHEGUANLI')
     cc = CompanyColumn.objects.filter(father_id=father_cc.pk)
     result = []
     for i in cc:
         result.append(i.toJSON())
     self.assertJSONEqual(resonse.content, getTestResult(True, u"success", result),
                          u'错误')
Пример #22
0
 def check_file_upload_status(self, project_id, fileid):
     """
     根据fileid 检查文件是否已在bcs上
     by:王健 at:2015-1-12
     修改判断条件
     by:王健 at:2015-1-27
     :return:
     """
     # 我关注的项目列表
     login_response = self.client.post('/nf/%s/check_file_upload_status' % project_id, {'fileid': fileid})
     self.assertEqual(200, login_response.status_code, u'获取文件下载url 错误')
     self.assertJSONEqual(login_response.content, getTestResult(True, u'', False),
                          u'获取文件下载url,返回结果有变化,需要确认,或修改单元测试')
Пример #23
0
 def release_sys_news(self, sys_news_id):
     """
     测试
     by:尚宗凯 at:2015-06-11
     """
     resonse = self.client.post('/cp/release_sys_news', {"sys_news_id":sys_news_id})
     if sys_news_id and SysNews.objects.filter(pk=sys_news_id).exists():
         sys_news = SysNews.objects.get(pk=sys_news_id)
         sys_news.is_active = True
         sys_news.publish_time = timezone.now()
         sys_news.save()
     self.assertJSONEqual(resonse.content, getTestResult(True, u'客服发布新闻成功'),
                          u'错误')
Пример #24
0
 def set_follow_company(self, user_id, company_id):
     """
     测试
     by:尚宗凯 at:2015-06-11
     """
     resonse = self.client.post('/cp/set_follow_company', {"company_id":company_id})
     if company_id != "":
         fc = FollowCompany()
         fc.user_id = user_id
         fc.company_id = int(company_id)
         fc.create_time = timezone.now()
         fc.save()
     self.assertJSONEqual(resonse.content, getTestResult(True, u'设置关注企业成功'),
                          u'错误')
Пример #25
0
    def get_project_by_company(self, company_id):
        """
        测试
        by:尚宗凯 at:2015-06-11
        """
        resonse = self.client.post('/cp/get_project_by_company',{"company_id":company_id})

        if company_id:
            projects = Project.objects.filter(company_id=company_id)
            result = []
            for i in projects:
                result.append(i.toJSON())
        self.assertJSONEqual(resonse.content, getTestResult(True, u'获取公司的项目成功', result),
                             u'错误')
Пример #26
0
 def confirm_upload_files(self, project_id, fileid):
     """
     设置文件为上传成功状态 测试
     by:王健 at:2015-1-10
     增加图片原始图片大小参数
     by: 范俊伟 at:2015-04-09
     :return:
     """
     # 我关注的项目列表
     login_response = self.client.post('/nf/%s/confirm_upload_files' % project_id, {'fileid': fileid})
     self.assertEqual(200, login_response.status_code, u'设置文件为上传成功状态 错误')
     fileobj = File.objects.get(pk=fileid)
     self.assertJSONEqual(login_response.content, getTestResult(True, u'上传文件成功', {'geturl': fileobj.get_url()}),
                          u'设置文件为上传成功状态,返回结果有变化,需要确认,或修改单元测试')
Пример #27
0
 def cancel_delete_project(self, project_id):
     """
     单元测试
     by:尚宗凯 at:2015-07-03
     """
     resonse = self.client.post('/cp/cancel_delete_project',{"project_id":project_id})
     if Project.objects.filter(id=project_id).exists():
         p = Project.objects.get(id=project_id)
         p.status = 0
         p.delete_project_time = None
         p.save()
         p = MyEncoder.default(p)
     self.assertJSONEqual(resonse.content, getTestResult(True, u'成功恢复项目'),
                          u'错误')
Пример #28
0
 def update_sys_column(self, sys_column_id, name):
     """
     测试
     by:尚宗凯 at:2015-07-02
     """
     resonse = self.client.post('/cp/update_sys_column', {"sys_column_id":sys_column_id, "name":name})
     if sys_column_id:
         if SysColumn.objects.filter(pk=sys_column_id).exists():
             sc = SysColumn.objects.get(pk=sys_column_id)
             if name:
                 sc.name = name
             sc.save()
     self.assertJSONEqual(resonse.content, getTestResult(True, u'修改系统栏目成功'),
                          u'错误')
Пример #29
0
 def close_project(self, project_id):
     """
     单元测试
     by:尚宗凯 at:2015-07-03
     """
     resonse = self.client.post('/cp/close_project', {"project_id":project_id})
     if Project.objects.filter(id=project_id).exists():
         p = Project.objects.get(id=project_id)
         p.status = 2
         p.save()
         receiver_user_ids = [i.pk for i in p.group_set.filter(is_active=True)]
         # NeedMessage.create_multiple_sys_message(receiver_user_ids, "title", SYS_MESSAGE['project_close'] % (p.total_name))
         p = MyEncoder.default(p)
     self.assertJSONEqual(resonse.content, getTestResult(True, u"成功关闭项目"),
                          u'错误')
Пример #30
0
    def delete_company_user(self, company_id, user_id):
        """
        单元测试
        by:尚宗凯 at:2015-07-02
        """
        resonse = self.client.post('/cp/%s/delete_company_user' % str(company_id), {"user_id":user_id})

        if CompanyPerson.objects.filter(user_id=user_id, company_id=company_id):
            try:
                cp = CompanyPerson.objects.filter(user_id=user_id, company_id=company_id)[0]
                cp.delete()
            except:
                pass
        self.assertJSONEqual(resonse.content, getTestResult(False, u"用户不存在"),
                             u'错误')
Пример #31
0
 def get_upload_files_url(self, project_id):
     """
     获取附件上传的url
     by:王健 at:2015-1-10
     获取上传文件的url,结果校验
     by:王健 at:2015-1-12
     优化了获取文件上传url签名的接口
     by:王健 at:2015-1-14
     :return:
     """
     # 登录组织
     login_response = self.client.post('/nf/%s/get_upload_files_url' % project_id, {'filename': u'沙发上地方的说法', 'size': 30*1024, 'filetype': 'image'})
     self.assertEqual(200, login_response.status_code, u'获取附件上传的url 错误')
     fileobj = File.objects.all()[0]
     self.assertJSONEqual(login_response.content, getTestResult(True, u'', {'fileid': fileobj.pk, 'posturl': fileobj.get_post_url(), 'puturl': fileobj.get_put_url()}),
                          u'获取附件上传的url,返回结果有变化,需要确认,或修改单元测试')
Пример #32
0
    def login(self, username, password):
        """
        登录 接口测试
        by:王健 at:2015-1-5
        username 改为tel字段
        by:王健 at:2015-1-8
        返回值 修改
        by:王健 at:2015-1-16
        修改个人信息返回值
        by:王健 at:2015-1-20
        """
        # 登录
        login_response = self.client.post('/ns/login', {'tel': username, 'password': password})
        self.assertEqual(200, login_response.status_code, u'用户登录报错')
        user = get_user_model().objects.get(tel=username)

        self.assertJSONEqual(login_response.content,
                             getTestResult(True, u'登录成功', user.get_user_map(True)),
                             u'用户登录,返回结果有变化,需要确认,或修改单元测试')