Ejemplo n.º 1
0
    def report_activity(self, url):
        try:
            headers = {
                'Authorization': self.Authorization,
                'Content-Type': 'application/x-www-form-urlencoded'
            }
            response = requests.post(self.domain + url,
                                     data=contants.REPORT_DATA,
                                     headers=headers)
        except RequestException as e:
            self.deal_request(self.request_err_file, url, e)
        else:
            try:
                r_dict = response.json()
            except ValueError as e:
                self.deal_json(self.json_err_file, url, e,
                               response.status_code)
            else:
                code = r_dict.get('code')
                compare_content = {
                    'url': url,
                    '状态码': response.status_code,
                    'pass': False
                }
                if code != compare_contants.COMMON_CODE:
                    compare_content['code'] = code

                if len(r_dict) < compare_contants.REPORT_DATA_LENGTH:
                    self.deal_lack(self.lack_response_err_file, url,
                                   len(r_dict), response.status_code)
                elif len(compare_content) < compare_contants.LACK_NUM:
                    self.response_err_file.write(str(compare_content) + '\n')
                else:
                    utils.correct_response(url, response, r_dict, self.file)
Ejemplo n.º 2
0
 def user_identity(self, url):
     try:
         payload = {'sn': contants.SN}
         headers = {'Authorization': self.Authorization}
         response = requests.post(self.domain + url,
                                  data=payload,
                                  headers=headers)
         print(response.json())
     except RequestException as e:
         self.deal_request(self.request_err_file, url, e)
     else:
         try:
             r_dict = response.json()
         except ValueError as e:
             self.deal_json(self.json_err_file, url, e,
                            response.status_code)
         else:
             code = r_dict.get('code')
             compare_content = {
                 'url': url,
                 '状态码': response.status_code,
                 'pass': False
             }
             if code != compare_contants.COMMON_CODE:
                 compare_content['code'] = code
             if len(r_dict) < compare_contants.CAMERIST_INVITE_LENGTH:
                 self.deal_lack(self.lack_response_err_file, url,
                                len(r_dict), response.status_code)
             elif len(compare_content) > compare_contants.LACK_NUM:
                 self.response_err_file.write(str(compare_content) + '\n')
             else:
                 utils.correct_response(url, response, r_dict, self.file)
Ejemplo n.º 3
0
    def editVisiting_card(self, url):
        try:
            headers = {'Authorization': self.Authorization}
            response = requests.post(self.domain + url, headers=headers)
        except RequestException as e:
            self.deal_request(self.request_err_file, url, e)
        else:
            try:
                r_dict = response.json()
            except ValueError as e:
                self.deal_json(self.json_err_file, url, e,
                               response.status_code)
            else:
                code = r_dict.get('code')
                compare_content = {
                    'url': url,
                    '状态码': response.status_code,
                    'pass': False
                }
                if code != compare_contants.COMMON_CODE:
                    compare_content['code'] = code

                if len(r_dict.get(
                        'data')) < compare_contants.EDITVISCARD_DATA_LENGTH:
                    self.deal_lack(self.lack_response_err_file, url,
                                   len(r_dict.get('data')),
                                   response.status_code)
                elif len(compare_content) < compare_contants.LACK_NUM:
                    self.response_err_file.write(str(compare_content) + '\n')
                else:
                    utils.correct_response(url, response, r_dict, self.file)
Ejemplo n.º 4
0
 def home_page(self, url):
     try:
         payload = {'page': contants.HOME_PAGE, 'num': contants.HOME_NUM}
         headers = {
             'Authorization': self.Authorization,
             'Content-Type': 'application/x-www-form-urlencoded'
         }
         response = requests.post(self.domain + url,
                                  data=payload,
                                  headers=headers)
     except RequestException as e:
         self.deal_request(self.request_err_file, url, e)
     else:
         try:
             r_dict = response.json()
         except ValueError as e:
             self.deal_json(self.json_err_file, url, e,
                            response.status_code)
         else:
             code = r_dict.get('code')
             data_length = len(r_dict.get('data'))
             content_length = len(r_dict.get('data').get('content'))
             compare_content = {
                 'url': url,
                 '状态码': response.status_code,
                 'pass': False
             }
             if code != compare_contants.COMMON_CODE:
                 compare_content['code'] = code
             elif data_length != compare_contants.HOME_DATA_LENGTH:
                 compare_content['data_length'] = data_length
             elif content_length != compare_contants.HOME_CONTENT_LENGTH:
                 compare_content['content_length'] = content_length
             if content_length < compare_contants.HOME_CONTENT_LENGTH:
                 self.deal_lack(self.lack_response_err_file, url,
                                len(r_dict.get('data')),
                                response.status_code)
             elif len(compare_content) > compare_contants.LACK_NUM:
                 self.response_err_file.write(str(compare_content) + '\n')
             else:
                 utils.correct_response(url, response, r_dict, self.file)
Ejemplo n.º 5
0
    def activity_create(self, url):
        try:
            payload = {
                'title': contants.CREATE_TITLE,
                'activity_time': contants.CREATE_TIME
            }
            headers = {
                'Authorization': self.Authorization,
                'Content-Type': 'application/x-www-form-urlencoded'
            }
            response = requests.post(self.domain + url,
                                     data=payload,
                                     headers=headers)
            self.create_delete_id = response.json().get('data').get('id')
        except RequestException as e:
            self.deal_request(self.request_err_file, url, e)
        else:
            try:
                r_dict = response.json()
            except ValueError as e:
                self.deal_json(self.json_err_file, url, e,
                               response.status_code)
            else:
                code = r_dict.get('code')
                compare_content = {
                    'url': url,
                    '状态码': response.status_code,
                    'pass': False
                }
                if code != compare_contants.COMMON_CODE:
                    compare_content['code'] = code

                if len(r_dict.get(
                        'data')) < compare_contants.CREATE_DATA_LENGTH:
                    self.deal_lack(self.lack_response_err_file, url,
                                   len(r_dict.get('data')),
                                   response.status_code)
                elif len(compare_content) < compare_contants.LACK_NUM:
                    self.response_err_file.write(str(compare_content) + '\n')
                else:
                    utils.correct_response(url, response, r_dict, self.file)