def test_dump_handles_oserror(mocker):
    """
    pgdump.dump returns a reasonable error if pg_dump isn't installed.
    """
    mocker.patch('subprocess.Popen', side_effect=OSError('no such file'))
    with pytest.raises(SystemExit):
        pgdump.dump(url)
예제 #2
0
def test_dump_calls_pg_dump(mocker):
    """
    Test that pgdump exits if pg_dump is not installed
    """
    mocker.patch('subprocess.Popen', side_effect=OSError('no such file'))
    with pytest.raises(SystemExit):
        pgdump.dump(url)
예제 #3
0
def test_dump_handles_oserror(mocker):

    mocker.patch('subprocess.Popen', side_effect=OSError('non such file'))

    with pytest.raises(SystemExit):

        pgdump.dump(url)
예제 #4
0
def test_dump_handles_oserror(mocker):
    """
    pgdump.dump returns reasonable error if pg_dump isn't installed
    """
    mocker.patch('subprocess.Popen', side_effect=OSError('no such file'))
    with pytest.raises(SystemExit):
        pgdump.dump(url)
예제 #5
0
def test_dump_handles_os_error(mocker):
    '''
    If pg_backup not installed on machine, pg_dump will throw FileNotFoundError
    '''

    mocker.patch('subprocess.Popen', side_effect=OSError('No such file'))
    with pytest.raises(SystemExit):
        pgdump.dump(url)
예제 #6
0
def test_dump_handles_oserror(mocker):
    """
    pgdump.dump returns a resonable error if pg_dump isn't installed
    """
    mocker.patch('subprocess.Popen',
                 side_effect=OSError("PosgreSQL client missing"))
    with pytest.raises(SystemExit):
        pgdump.dump(url)
예제 #7
0
def test_dump_handles_oserror(mocker):
    """
	pgdump.dump returns a reasonable error if pg_dump isn't installed
	"""

    mocker.patch('subprocess.Popen', side_effect=OSError("no such file"))
    #the error it should raise is SystemExit, you mistakenly wrote SystemError. I corrected it. So its ok now
    with pytest.raises(SystemExit):
        pgdump.dump(url)
예제 #8
0
def test_dump_calls_pg_dump(mocker):
    """
    Use pg_dump with the db url
    """
    mocker.patch('subprocess.Popen')
    assert pgdump.dump(url)
    subprocess.Popen.assert_called_with(["pg_dump", url], stdout=subprocess.PIPE)
예제 #9
0
def main():
    import time
    import boto3
    from pgbackup import pgdump, storage

    args = create_parser().parse_args()
    dump = pgdump.dump(args.url)

    timestamp = time.strftime("%Y-%m-%dT%H:%M", time.localtime())
    file_name = pgdump.dump_file_name(args.url, timestamp)

    if args.driver == 's3':
        client = boto3.client('s3')    
        print(f"Backing database up to {args.destination} in S3 as {file_name}")
        storage.s3(client,
                dump.stdout,
                args.destination,
                file_name)
    else:
        if args.destination:
            outfile = open(args.destination, 'wb')
        else:
            outfile = open(file_name, 'wb')
        print(f"Backing database up locally to {outfile.name}")
        storage.local(dump.stdout, outfile)
예제 #10
0
def test_dump_calls_pg_dump(mocker):
    """
    Utilize pg_dump with the database URL
    """
    mocker.patch('subprocess.Popen')
    assert pgdump.dump(url)
    subprocess.Popen.assert_called_with(['pg_dump', url], stdout=subprocess.PIPE)
def test_dump_calls_pg_dump(mocker):
    """
    Utilize pg_dump with the database URL
    """
    mocker.patch('subprocess.Popen')
    assert pgdump.dump(url)
    subprocess.Popen.assert_called_with(['pg_dump', url], stdout=subprocess.PIPE)
예제 #12
0
def test_dump_calls_pg_dump(mocker):
    '''
    Utilized pg_dump with db URL
    '''

    mocker.patch('subprocess.Popen')
    assert pgdump.dump(url)
    subprocess.Popen.assert_called_with(['pg_dump',url],stdout=subprocess.PIPE,stderr=subprocess.PIPE)
예제 #13
0
def test_dump_handles_oserror(mocker):
    """
    pgdump.dump returns reponse if pg_dump isn't installed
    """
    mocker.patch('subprocess.Popen', side_effect=OSError('No such file'))
    with pytest.raises(SystemExit):
        assert pgdump.dump(url)
        subprocess.Popen.assert_called_with(['pg_dump', url], stdout=subprocess.PIPE)
def test_dump_calls_pg_dump(mocker):
    """
        Make use of pg_dump with database URL.
        """
    mocker.patch("subprocess.Popen")
    assert pgdump.dump(url)
    subprocess.Popen.assert_called_with(["pg_dump", url],
                                        stdout=subprocess.PIPE)
def main():
    import boto3
    from pgbackup import pgdump, storage

    args = create_parser().parse_args()
    dump = pgdump.dump(args.url)
    if args.driver == 's3':
        client = boto3.client('s3')
예제 #16
0
def test_dump_call_pg_dump(mocker):
    """
    Utilize pg_dump to interact with Database
    """
    proc = mocker.Mock()
    mocker.patch('subprocess.Popen', return_value=proc) # mocker is a fixture like parser
    assert pgdump.dump(url) == proc
    subprocess.Popen.assert_called_with(['pg_dump', url], stdout=subprocess.PIPE) # Popen is a similar command to pg_dump
예제 #17
0
def test_dump_call_pg_dump(mocker):
    """
    Utilize pg_dump to interact with Database.
    """
    proc = mocker.Mock()
    mocker.patch('subprocess.Popen', return_value=proc)
    assert pgdump.dump(url) == proc
    subprocess.Popen.assert_called_with(['pg_dump', url], stdout=subprocess.PIPE)
예제 #18
0
def test_dump_call_pg_dump(mocker):
    """
    use pg_dump to interact with the database
    """
    proc = mocker.Mock()
    mocker.patch("subprocess.Popen", return_value=proc)
    assert pgdump.dump(url) == proc
    subprocess.Popen.assert_called_with(["pg_dump", url],
                                        stdout=subprocess.PIPE)
예제 #19
0
def test_handle_os_errors(mocker):
    """
    pg_dump.dump returns a reasonable error if pg_dump is not installed
    """
    mocker.patch('subprocess.Popen',
                 side_effect=FileNotFoundError('no such file'))

    with pytest.raises(SystemExit):
        assert pgdump.dump(url)
예제 #20
0
def main():
    args = create_parser().parse_args()
    dump = pgdump.dump(args.url)
    if args.driver == 's3':
        client = boto3.client('s3')
        # TODO: create a better name based on the database name and the date
        storage.s3(client, dump.stdout, args.destination, 'example.sql')
    else:
        outfile = open(args.destination, 'wb')
        storage.local(dump.stdout, outfile)
예제 #21
0
def main():
    import boto3
    from pgbackup import pgdump, storage

    args = create_parser().parse_args()
    dump = pgdump.dump(args.url)
    if args.driver == 's3':
        storage.s3(client, dump.stdout, args.destination, 'example.sql')
    else:
        outfile = open(args.destination, 'wb')
        storage.local(dump.stdout, outfile)
예제 #22
0
def test_dump_calls_pg_dump(mocker):
    """
    Utilize pg_dump with the database URL
    """
    # we use Popen instead or subprocess because we want it to happen in the background

    # patching using mock allows us to substitute the implementation of something with something else we can use and call assertions on and prevent it from doing other things the normal implementation would have
    # after this point anytime the subprocess.Popen function is called; it behaves differently; it's being mocked
    # basically we make it into a function that can take any arguments it wants and it's gonna store the number of time this function is called
    mocker.patch('subprocess.Popen')

    assert pgdump.dump(url)
    subprocess.Popen.assert_called_with(['pg_dump', url],
                                        stdout=subprocess.PIPE)
예제 #23
0
def main():
    import time
    import boto3
    from pgbackup import pgdump, storage

    args = create_parser().parse_args()
    dump = pgdump.dump(args.url)
    if args.driver == 's3':
        client = boto3.client('s3')
        timestamp = time.strftime("%Y-%m", time.localtime())
        file_name = pgdump.dump_file_name(args.url, timestamp)
        storage.s3(client, dump.stdout, args.destination, file_name)
    else:
        outfile = open(args.destination, 'wb')
        storage.local(dump.stdout, outfile)
예제 #24
0
파일: cli.py 프로젝트: mattiasgiese/learn
def main():
    import time
    import boto3
    from pgbackup import pgdump, storage
    args = create_parser().parse_args()
    dump = pgdump.dump(args.url)
    if args.driver == 's3':
        client = boto3.client('s3')
        timestamp = time.strftime('%Y-%m-%dT%H:%M:%S')
        filename = pgdump.dump_file_name(args.url, timestamp)
        print(f'Backup up database to S3 as {filename}')
        storage.s3(client, dump.stdout, args.destination, filename)
    else:
        outfile = open(args.destination, 'wb')
        print(f'Backup up database locally to {args.destination}')
        storage.local(dump.stdout, outfile)
예제 #25
0
파일: cli.py 프로젝트: kevgraham7/toolbox
def main():
    import boto3
    import time
    from pgbackup import pgdump, storage

    args = create_parser().parse_args()
    sqldump = pgdump.dump(args.url)
    if args.driver == 's3':
        client = boto3.client('s3')
        timestamp = time.strftime("%Y-%m-%dT%H:%M:%S", time.localtime());
        file_name = pgdump.dump_file_name(args.url, timestamp, )
        storage.s3(client, sqldump.stdout, args.destination, file_name)
        print(f"Backing DB up to {args.destination} in S3 as {file_name}")
    else:
        outfile = open(args.destination, 'wb')
        print(f"Backing DB up to {args.destination} locally")
        storage.local(sqldump.stdout, outfile)
예제 #26
0
def main():
    import boto3
    import time
    from pgbackup import pgdump, storage

    args = create_parser().parse_args()
    dump = pgdump.dump(args.url)
    if args.driver == 's3':
        client = boto3.client('s3')
        timestamp = time.strftime("%Y-%m-%dT%H:%M", time.localtime())
        file_name = pgdump.dump_file_name(args.url, timestamp)
        print("backing database up to %s in S3 as %s" % (args.url, file_name))
        storage.s3(client, dump.stdout, args.destination, file_name)
    else:
        outfile = open(args.destination, 'w')
        print("backing up db locally to %s" % outfile.name)
        storage.local(dump.stdout, outfile)
def main():
    import boto3
    import time
    from pgbackup import pgdump, storage

    args = create_parser().parse_args()
    dump = pgdump.dump(args.url)
    if args.driver == 's3':
        client = boto3.client('s3')
        timestamp = time.strftime("%Y-%m-%dT%H:%M:%S", time.localtime())
        file_name = pgdump.dump_file_name(args.url, timestamp)
        print("Backup database up to " + args.destination + " in s3 as " +
              file_name)
        storage.s3(client, dump.stdout, args.destination, file_name)
    else:
        outfile = open(args.destination, 'wb')
        print("Backup database locally to " + args.destination)
        storage.local(dump.stdout, outfile)
예제 #28
0
def main():
    import boto3
    import time
    from pgbackup import storgae, pgdump

    args = create_parser.parse_arg()
    dump = pgdump.dump(agrs.url)

    if args.driver == 's3':
        client = boto3.client('s3')
        timestamp = time.strftime("%m-%d-%YT%H:%M", time.localtime())
        file_name = pgdump.dump_file_name(args.url, timestamp)
        print(f"Backing database up to {args.destination} in S3 as {file_name}")
        # TODO: create a better name based on the database name and the date
        storage.s3(client, dump.stdout, args.destination, file_name)
    else:
        outfile = open('args.destination', 'wb')
        print(f"Backing database up locally to {outfile.name}")
        storage.local (dump.stdout, outfile )
예제 #29
0
def main():
    import boto3
    from pgbackup import pgdump, storage
    import time

    args = create_parser().parse_args()
    dump = pgdump.dump(args.url)
    if args.driver == 's3':
        client = boto3.client('s3')
        timestamp = time.strftime("%Y-%m-%dT%H:%M", local.localtime())
        file_name = pgdump.dump_file_name(args.url, timestamp)
        print(
            f"Backing up db to {args.destination} in S3 with filename: {file_name}"
        )
        storage.s3(client, dump.stdout, args.destination, file_name)
    else:
        outfile = open(args.destination, 'wb')
        print(f"Backing up db locally with the name: {outfile.namme}")
        storage.local(dump.stdout, outfile)
예제 #30
0
파일: cli.py 프로젝트: TiaIvonne/pgbackup
def main():
    #clase principal que da un orden de ejecucion a los metodos o clases declarados enteriormente
    import time
    import boto3
    from pgbackup import pgdump, storage

    args = create_parser().parse_args()
    dump = pgdump.dump(args.url)
    if args.driver == 's3':
        client = boto3.client('s3', region_name='us-east-1')
        timestamp = time.strftime("%Y-%m-%dT%H:%M", time.localtime())
        file_name = pgdump.dump_file_name(args.url, timestamp)
        print(
            f"Backing database up to {args.destination} in S3 as {file_name}")
        storage.s3(client, dump.stdout, args.destination, file_name)
    else:
        outfile = open(args.destination, 'wb')
        print(f"Backing database up locally to {outfile.name}")
        storage.local(dump.stdout, outfile)
예제 #31
0
def main():
    # import the boto3 dependeency only after the main function is called;
    import boto3
    import time
    from pgbackup import pgdump, storage

    args = create_parser().parse_args()
    dump = pgdump.dump(args.url)

    if args.driver == "s3":
        client = boto3.client("s3")
        timestamp = time.strftime("%Y-%m-%dT%H:%M", time.localtime())
        file_name = pgdump.dump_file_name(args.url, timestamp)
        print("backing up the database to s3 bucket %s as %s" %
              (args.destination, file_name))
        storage.s3(client, dump.stdout, args.destination, "example.sql")
    else:
        outfile = open(args.destination, "w")
        print("backing up the database locally to %s" % outfile.name)
        storage.local(dump.stdout, outfile)
예제 #32
0
def main():
    import time
    from pgbackup import pgdump, storage
    from pgbackup.remotes import aws

    args = create_parser().parse_args()
    dump = pgdump.dump(args.url)

    if args.driver == 's3':
        now = time.strftime("%Y-%m-%dT%H:%M", time.localtime())
        file_name = pgdump.dump_file_name(args.url, timestamp=now)
        s3_client = aws.Remote()
        print(f'Backing database up to AWS S3 as {file_name}...')
        storage.remote(s3_client, dump.stdout, args.destination, file_name)

    else:
        local_file = open(args.destination, 'wb')
        print('Backing database up to local directory')
        storage.local(dump.stdout, local_file)

    print('Done!')
예제 #33
0
def main():
    import boto3
    from pgbackup import pgdump, storage

    args = create_parser().parse_args()
    dump = pgdump.dump(args.url)

    if args.driver == 's3':
        timestamp = time.strftime('%Y-%m-%dT%H-%M', time.localtime())
        file_name = pgdump.dump_file_name(args.url, timestamp)
        session = boto3.Session(
            profile_name='acg')  #get passed from cli options
        client = session.client('s3')
        print(
            f"[I] Backing database up to {args.destination} in S3 as {file_name}"
        )
        storage.s3(client, dump.stdout, args.destination, file_name)
    else:
        outfile = open(args.destination, 'wb')
        print(f"Backing database up locally to {outfile.name}")
        storage.local(dump.stdout, outfile)