Beispiel #1
0
    def admin_api_call(self,
                       call,
                       params=None):
        """
        Give the API endpoint (call) and the params. Omit the session
        because it will be added automatically to your params.
        :param call Something like 'system/delPolicy'
        :param params Something like {'name': 'policy1'}
        :return Return json structure with API result
        """

        if(params is None):
            params = {}

        url = self.testcase.http_protocol + \
            "://" + self.testcase.http_host + \
            ":" + self.testcase.http_port + "/"

        params['session'] = helper.get_session(url,
                                               self.testcase.http_username,
                                               self.testcase.http_password)

        auth = requests.auth.HTTPDigestAuth(
            self.testcase.http_username,
            self.testcase.http_password)

        response = requests.post(url + call.strip('/'),
                                 auth=auth,
                                 params=params,
                                 cookies={'admin_session': params['session']},
                                 verify=False)

        response.raise_for_status()

        return response.json()
Beispiel #2
0
 def __init__(self, http_protocol, http_host, http_username, http_password):
     """Initializes the class with the required values to call
        https://.../system/setConfig
     """
     self.auth = HTTPDigestAuth(http_username, http_password)
     self.set_config_url = http_protocol + "://" + http_host + "/system/setConfig?"
     self.session = get_session(http_protocol + "://" + http_host + "/",
                                http_username, http_password)
Beispiel #3
0
 def update(self, file_token, name):
     with get_session() as ss:
         query = ss.query(FileToken).filter(FileToken.file_token==file_token).first()
         query.filename = name
         query.download_counter = 1
         ss.add(query)
         ss.commit()
         return True
Beispiel #4
0
 def __init__(self, area, env):
     assert area in ['small', 'medium', 'large']
     area_turns = {
         'small': 10,
         'medium': 50,
         'large': 120}
     self.total_turns = area_turns[area]
     self.session = get_session(env)
Beispiel #5
0
 def __init__(self, http_protocol, http_host, http_username, http_password):
     """Initializes the class with the required values to call
        https://.../system/setConfig
     """
     self.auth = HTTPDigestAuth(http_username, http_password)
     self.set_config_url = http_protocol + "://" + http_host + "/system/setConfig?"
     self.session = get_session(http_protocol + "://" + http_host + "/",
                                http_username, http_password)
Beispiel #6
0
 def doned_download(self, file_token):
     with get_session() as ss:
         query = ss.query(FileToken).filter(
             FileToken.file_token == file_token,
             FileToken.alive == True
         ).first()
         if query:
             query.alive = False
             ss.add(query)
             ss.commit()
             return True
         return False
Beispiel #7
0
 def get_upload(self, file_token):
     with get_session() as ss:
         query = ss.query(FileToken).filter(
             FileToken.file_token == file_token,
             FileToken.alive == False,
             FileToken.upload_counter > 0
         ).first()
         if not query:
             return False
         query.upload_counter -= 1
         ss.add(query)
         ss.commit()
         return query.dst_ip
Beispiel #8
0
 def create(self, user, dst_ip):
     with get_session() as ss:
         file_token = random_sha()
         file = FileToken(
             user=user,
             dst_ip=dst_ip,
             file_token=file_token,
             upload_counter=1,
             download_counter=-1,
             alive=False,
         )
         ss.add(file)
         ss.commit()
         return file_token
Beispiel #9
0
 def update_counter(self, file_token, download_counter):
     """
     更新计数
     :param file_token:
     :param download_counter:
     :return:
     """
     with get_session() as ss:
         query = ss.query(FileToken).filter(FileToken.file_token==file_token).first()
         if not query:
             return False,'file_token not found!'
         query.download_counter = abs(download_counter)
         ss.add(query)
         ss.commit()
         return True, 'ok'
Beispiel #10
0
 def __init__(self, env):
     self.gg_bot = GGBot()
     self.session = get_session(env)
Beispiel #11
0
 def __init__(self, env):
     self.fb_bot = FBBot()
     self.session = get_session(env)
Beispiel #12
0
 def __init__(self, area, env):
     assert area in ['small', 'medium', 'large']
     area_turns = {'small': 10, 'medium': 50, 'large': 120}
     self.total_turns = area_turns[area]
     self.session = get_session(env)
Beispiel #13
0
 def __init__(self, env, match_type='restaurant'):
     self.gg_bot = GGBot()
     self.session = get_session(env)
     self.match_type = match_type
Beispiel #14
0
 def __init__(self, env):
     self.fb_bot = FBBot()
     self.session = get_session(env)
Beispiel #15
0
 def __init__(self, env, match_type='restaurant'):
     self.gg_bot = GGBot()
     self.session = get_session(env)
     self.match_type = match_type