Esempio n. 1
0
    def test_replace_postgres_local_file_source(self, mock_check_call):
        command = Command(self.parser.parse_args(['-f', 'db.sql', '-n', 'destdb']))

        command.replace_postgres_db(None)

        expected_calls = [call(['dropdb', '--if-exists', 'destdb']),
                          call(['createdb', 'destdb']),
                          call(['pg_restore', '--no-acl', '--no-owner', '--dbname=destdb',
                                'db.sql'])]
        self.assertEqual(expected_calls, mock_check_call.call_args_list)
Esempio n. 2
0
    def test_replace_postgres_db_url_file_source(self, mock_check_call, mock_urlopen):
        mock_urlopen.return_value = tempfile.NamedTemporaryFile()
        command = Command(self.parser.parse_args(['-u', 'http://www.example.com/', '-n', 'destdb']))

        command.replace_postgres_db('http://www.example.com/')

        expected_calls = [call(['dropdb', '--if-exists', 'destdb']),
                          call(['createdb', 'destdb']),
                          call(['pg_restore', '--no-acl', '--no-owner', '--dbname=destdb',
                                StringStartsWith('www_example_com-backup-')])]
        self.assertEqual(expected_calls, mock_check_call.call_args_list)
Esempio n. 3
0
    def test_replace_postgres_db_source(self, mock_check_call, mock_urlopen):
        mock_urlopen.return_value = tempfile.NamedTemporaryFile()
        command = Command(self.parser.parse_args(['-b', 'sourcedb', '-n', 'destdb']))

        command.replace_postgres_db(None)

        expected_calls = [call(['pg_dump', '-Fc', '--no-acl', '--no-owner', '--dbname=sourcedb',
                                StringStartsWith('--file=sourcedb-backup-')]),
                          call(['dropdb', '--if-exists', 'destdb']),
                          call(['createdb', 'destdb']),
                          call(['pg_restore', '--no-acl', '--no-owner', '--dbname=destdb',
                                StringStartsWith('sourcedb-backup-')])]
        self.assertEqual(expected_calls, mock_check_call.call_args_list)