def test__using_with_valid_zip_and_target_folder(self):
     test_zip = Files.current_folder()
     target_folder = '/tmp/unzip_test'
     with Zip_Folder(test_zip) as (zip_file):
         with Unzip_File(zip_file, target_folder, True) as temp_folder:
             assert Files.exists(temp_folder) is True
     assert Files.exists(temp_folder) is False
Ejemplo n.º 2
0
    def test__using_with__no_params(self):
        with Temp_File() as temp:
            assert Files.file_extension(temp.file_path) == '.tmp'
            assert Files.exists(temp.file_path)
            assert Files.contents(temp.file_path) == '...'
        assert Files.not_exists(temp.file_path)

        with Temp_File('abc', 'txt') as temp:
            assert Files.file_extension(temp.file_path) == '.txt'
            assert Files.exists(temp.file_path)
            assert Files.contents(temp.file_path) == 'abc'
        assert Files.not_exists(temp.file_path)
Ejemplo n.º 3
0
 def test__init__(self):
     temp_file = Temp_File()
     assert Files.exists(temp_file.tmp_folder)
     assert Files.not_exists(temp_file.tmp_file)
     assert Files.not_exists(temp_file.file_path)
     assert temp_file.tmp_folder in temp_file.file_path
     assert '/' == temp_file.file_path.replace(temp_file.tmp_folder,
                                               '').replace(
                                                   temp_file.tmp_file, '')
Ejemplo n.º 4
0
    def get_oauth_token(self, desired_scope):
        secret_data = json.loads(Secrets(self.gsuite_secret_id).value()
                                 )  # load secret from AWS Secrets store
        token_file = '/tmp/gmail_credential_{0}.json'.format(
            desired_scope
        )  # this is the tmp file with the token value for the desired scope

        if not Files.exists(token_file):  # if the file does not exist
            if os.getenv('AWS_REGION') is not None or os.getenv(
                    'SYNC_SERVER'
            ):  # check if we are running in AWS or in the sync server
                Files.write(
                    token_file, secret_data['token.json']
                )  # if we are, use the token.json value from the AWS secret_data
            else:
                secret_data = json.loads(Secrets(
                    'gsuite_token').value())  # BUG, need to refactor this
                credentials_file = '/tmp/gsuite_credentials.json'  # file to hold the credentials.json value
                Files.write(credentials_file, secret_data['credentials.json']
                            )  # save value received from AWS into file

                store = file.Storage(
                    token_file)  # create a gsuite Storage object
                scopes = 'https://www.googleapis.com/auth/{0}'.format(
                    desired_scope
                )  # full qualified name for the desired scopes

                flow = client.flow_from_clientsecrets(
                    credentials_file, scopes)  # create a gsuite flow object
                flags = argparser.parse_args(
                    '--auth_host_name localhost --logging_level INFO'.split()
                )  # configure the use of a localhost server to received the oauth response
                run_flow(
                    flow, store, flags
                )  # open browser and prompt user to follow the OAuth flow

                Files.delete(
                    credentials_file
                )  # delete main gsuite credentials file (since we don't want it hanging around)

        return token_file  # return file with token credentials
 def test__using_with_valid_zip_no_target_folder(self):
     test_zip = Files.current_folder()
     with Zip_Folder(test_zip) as (zip_file):
         with Unzip_File(zip_file, None, True) as temp_folder:
             assert Files.exists(temp_folder) is True
     assert Files.exists(temp_folder) is False
Ejemplo n.º 6
0
 def get_last_chrome_session(self):
     if Files.exists(self.file_tmp_last_chrome_session):
         return Json.load_json(self.file_tmp_last_chrome_session)
     return {}
Ejemplo n.º 7
0
 def __exit__(self, type, value, traceback):
     if Files.exists(self.zip_file) and self.delete_zip_file:
         Files.delete(self.zip_file)
Ejemplo n.º 8
0
 def __enter__(self):
     if Files.exists(self.target_folder):
         self.zip_file = Files.zip_folder(self.target_folder)
     return self.zip_file
Ejemplo n.º 9
0
 async def test_screenshot(self):
     await self.api.open('https://news.bbc.co.uk')
     file = await self.api.screenshot()
     assert Files.exists(file)
Ejemplo n.º 10
0
 def test_exists(self):
     assert Files.exists(Files.current_folder()) is True
     assert Files.exists('aaaa_bbb_ccc') is False
     assert Files.exists(None) is False
Ejemplo n.º 11
0
 def test__using_with_params(self):
     target_folder = Files.current_folder()
     with Zip_Folder(target_folder) as (zip_file):
         assert Files.exists(zip_file) is True
     assert Files.exists(zip_file) is False
 def test_screenshot_file(self):
     with Temp_File(self.html, 'html') as temp_file:
         tmp_img = '/tmp/test_screenshot_html.png'
         clip = {'x': 1, 'y': 1, 'width': 180, 'height': 30}
         img_file = self.render_page.screenshot_file(temp_file.file_path,tmp_img,clip=clip)
         assert Files.exists(img_file)
 def test_screenshot_html(self):
     tmp_img = '/tmp/test_screenshot_html.png'
     img_file = self.render_page.screenshot_html(self.html,tmp_img)
     assert Files.exists(img_file)