Exemple #1
0
 def token_builder(self, data, function=False):
     if not data.get('success'):
         if function:
             ReportHandler.add_log(
                 function,
                 "Failed to get right response\n__________________________")
             ReportHandler.add_error(
                 function, "Could not get response:\n{0}".format(data))
         else:
             ReportHandler.add_log(
                 "Response",
                 "Failed to get right response\n________________________")
             ReportHandler.add_error(
                 "Response", "Could not get response:\n{0}".format(data))
     else:
         data = data.get('data')
         if function:
             ReportHandler.add_log(function, "\n{0}".format(data))
         else:
             ReportHandler.add_log("Response", "\n{0}".format(data))
         try:
             self.token = data.get('token')
         except AttributeError:
             data = data[0]
             self.token = data.get('token')
Exemple #2
0
 def get_filters(self):
     try:
         with self.__connection:
             self.__cursor.execute("SELECT * FROM filters")
             to_parse = self.__cursor.fetchall()
             return to_parse
     except:
         ReportHandler.add_error("Getting filters", "Failed")
Exemple #3
0
 def approve_adds_with_status_2(self):
     ReportHandler.add_log("Approving ads with DB", "Starting")
     try:
         with self.__connection:
             self.__cursor.execute(api_requests.query_set_status_confirmed)
         ReportHandler.add_log("Approving ads with DB",
                               "Finished successfully")
     except:
         ReportHandler.add_error("Approving ads with DB", "Failed")
Exemple #4
0
 def get_min_and_max_ad_id(self):
     try:
         with self.__connection:
             self.__cursor.execute(api_requests.query_get_ads_min_and_max)
             result = self.__cursor.fetchone()
             config.min_ad_id = result[0]
             config.max_ad_id = result[1]
             print(config.max_ad_id)
     except:
         ReportHandler.add_error("Getting min and max ad ids", "Failed")
Exemple #5
0
 def watch_ad(self, ad_id):
     # trying_to_watch_ad
     ReportHandler.add_log("Watching add",
                           "Trying to watch ad with id {0}".format(ad_id))
     url = config.url + api_requests.watch_ad
     param = {'token': self.token}
     view_ad = requests.get(url + str(ad_id),
                            headers=config.headers_desk,
                            params=param)
     if '"success": true' in view_ad:
         ReportHandler.add_log("Watch add", "successfull")
     else:
         ReportHandler.add_log("Watch add", "failed")
         ReportHandler.add_error("Watch add", str(view_ad.json()))
Exemple #6
0
 def watch_random_ad(self):
     ad_id = random.randint(config.min_ad_id, config.max_ad_id)
     ReportHandler.add_log(
         "Watching random add",
         "Trying to watch random add with id {0}".format(ad_id))
     url = config.url + api_requests.watch_ad
     param = {'token': self.token}
     view_ad = requests.get(url + str(ad_id),
                            headers=config.headers_desk,
                            params=param)
     if view_ad.json().get('success'):
         ReportHandler.add_log("Watch add", "successful")
     else:
         ReportHandler.add_log("Watch add", "failed")
         ReportHandler.add_error("Watch add", str(view_ad))
Exemple #7
0
 def __init__(self):
     ReportHandler.add_log("Connect to DB", "Starting")
     self.login = "******"
     self.password = "******"
     self.url = config.db_url
     self.host = "192.168.2.3"
     self.__cursor = ""
     try:
         self.__connection = psycopg2.connect(dbname=self.url,
                                              user=self.login,
                                              password=self.password,
                                              host=self.host)
         ReportHandler.add_log("Connect to DB", "Connection established")
         self.__cursor = self.__connection.cursor()
     except psycopg2.OperationalError:
         ReportHandler.add_error("Wrong DB setted up", "Failed")
     except:
         ReportHandler.add_error("Connect to DB", "Failed")
Exemple #8
0
 def approve_ads(self):
     for ad_id in config.queue:
         try:
             link = config.admin_url + "items/index/edit/{ad_id}".format(
                 ad_id=ad_id)
             self.browser.get(link)
             time.sleep(0.5)
             confirm_button = self.browser.find_element_by_xpath(
                 "//button[text()='Confirmed            ']")
             save_button = self.browser.find_element_by_css_selector(
                 'input[type="submit"]')
             confirm_button.click()
             save_button.click()
             ReportHandler.add_log("Approving ads",
                                   "Ad with id {} approved".format(ad_id))
             config.queue.remove(ad_id)
         except:
             print("Can't do smth for ad {}".format(ad_id))
             config.queue.remove(ad_id)
             ReportHandler.add_error("Approving add",
                                     "Failed for id {}".format(ad_id))
Exemple #9
0
 def user_upload_image(self):
     ReportHandler.add_log("Upload image", "Trying to upload random image")
     url = config.url + api_requests.upload_image
     with open("venv/Uploads/images.json", "r") as read_file:
         photos = json.load(read_file)
     photo_path = "venv/Uploads/" + photos[0]
     body_upload = {'token': self.token}
     upload_image = requests.post(url,
                                  body_upload,
                                  headers=config.headers_desk,
                                  files={'image': open(photo_path, 'rb')})
     data = upload_image.json()
     img_id = data.get('data')
     if upload_image.json().get('success'):
         ReportHandler.add_log(
             "Upload image",
             "successful, image id {0}".format(str(img_id[0].get('id'))))
     else:
         ReportHandler.add_log("Uploading image", "failed")
         ReportHandler.add_error("Watch add", str(upload_image.json()))
     return upload_image.json()
def init_app(url):
    clear_previous_logs()
    url_builder(url)
    config.headers = config.headers_mobile
    if config.users_count > 1:
        config.email = config.email[:config.email.find(
            '@')] + "{}" + config.email[config.email.find('@'):]
    ReportHandler.add_log("App initialization", "Trying to configure app")
    if set_add_example():
        ReportHandler.add_log("App initialization", "Configured")
    else:
        ReportHandler.add_log(
            "App initialization",
            "Failed to load json configs, will work with default settings")
        ReportHandler.add_error(
            "App initialization",
            "Failed to load json configs, will work with default settings")
    ReportHandler.add_log("Making url",
                          "Configured url with {0}".format(config.url))
    # TODO: обработать вход минимум и максимум айди объяв
    min_ad = 0
    max_ad = 60
Exemple #11
0
 def generate_ads(self):
     i = 0
     email = config.email
     ReportHandler.parse_log("Generating ads", "Starting generation...")
     while i < self.users_count:
         if self.users_count != 1:
             email_number = 100 * int(self.thread_number) + i + 1
             email = config.email.format(str(email_number))
         user = User(email, config.password)
         user.register()
         user.authorize()
         i += 1
         curr_ads = 0
         while curr_ads < self.ads_count:
             self.generate_ad_example()
             temp_id = user.create_ad()
             try:
                 if temp_id:
                     config.queue.append(temp_id)
             except TypeError:
                 ReportHandler.add_error("Appending ad id", "Failed")
             finally:
                 curr_ads += 1