Ejemplo n.º 1
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.º 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 upload_dependency(target):
    s3 = S3()
    s3_bucket = 'gs-lambda-tests'
    s3_folder = 'dinis/lambdas-dependencies/'
    s3_file = 'dinis/lambdas-dependencies/{0}.zip'.format(target)
    path_libs = Files.path_combine('../../../_lambda_dependencies/', target)
    if Files.not_exists(path_libs):
        raise Exception(
            "In Lambda upload_dependency, could not find dependency for: {0}".
            format(target))
    s3.folder_upload(path_libs, s3_bucket, s3_folder)
    return s3.file_exists(s3_bucket, s3_file)
Ejemplo n.º 4
0
def load_dependency(target):
    s3 = S3()
    s3_bucket = 'gs-lambda-tests'
    s3_key = 'dinis/lambdas-dependencies/{0}.zip'.format(target)
    tmp_dir = Files.path_combine('/tmp/lambdas-dependencies', target)

    if s3.file_exists(s3_bucket, s3_key) is False:
        raise Exception(
            "In Lambda load_dependency, could not find dependency for: {0}".
            format(target))

    if Files.not_exists(
            tmp_dir
    ):  # if the tmp folder doesn't exist it means that we are loading this for the first time (on a new Lambda execution environment)
        zip_file = s3.file_download(
            s3_bucket, s3_key, False)  # download zip file with dependencies
        shutil.unpack_archive(zip_file, extract_dir=tmp_dir)  # unpack them
        sys.path.append(
            tmp_dir
        )  # add tmp_dir to the path that python uses to check for dependencies
    return Files.not_exists(tmp_dir)
Ejemplo n.º 5
0
 def start(self):
     if Files.not_exists(self.web_root):  Files.folder_create(self.web_root)     # make sure root folder exists
     self.server_proc = subprocess.Popen(["python3", "-m", "http.server", str(self.port)], cwd=self.web_root)
     self.wait_for_server_started()
     return self