def test_output_to_file(self, capsys):
     self.prepare_src()
     src_url = self.src_database.url()
     config_tempfile = self.make_config_tempfile()
     dst = NamedTemporaryFile(mode='wb')
     dst.close()
     main([config_tempfile.name, src_url, '-f', dst.name])
     with open(dst.name) as f:
         self.check_statements(f.read())
     out, err = capsys.readouterr()
     self.check_verbosity1_output_for_file(out)
    def test_src_dst_type_mismatch(self, capsys, postgresql):
        config_tempfile = self.make_config_tempfile()
        self.prepare_src(postgresql)
        dst = NamedTemporaryFile(mode='wt', suffix='.sqlite3')
        dst_database = SqliteDatabase(dst.name)

        with pytest.raises(SystemExit):
            main([config_tempfile.name, self.src_database.url(), '-q',
                  '-u', dst_database.url()])
        out, err = capsys.readouterr()
        assert 'src and dst databases must be of the same type' in out
    def test_output_to_file(self, postgresql, postgresql2):
        dst = NamedTemporaryFile(mode='wb')
        dst.close()
        config_tempfile = self.make_config_tempfile()
        self.prepare_src(postgresql)

        main([config_tempfile.name, self.src_database.url(), '-q',
              '-f', dst.name])

        with open(dst.name) as f:
            self.check_statements(postgresql2, f.read())
    def test_output_to_file(self, postgresql, postgresql2):
        dst = NamedTemporaryFile(mode='wb')
        dst.close()
        config_tempfile = self.make_config_tempfile()
        self.prepare_src(postgresql)

        main([
            config_tempfile.name,
            self.src_database.url(), '-q', '-f', dst.name
        ])

        with open(dst.name) as f:
            self.check_statements(postgresql2, f.read())
    def test_src_dst_type_mismatch(self, capsys, postgresql):
        config_tempfile = self.make_config_tempfile()
        self.prepare_src(postgresql)
        dst = NamedTemporaryFile(mode='wt', suffix='.sqlite3')
        dst_database = SqliteDatabase(dst.name)

        with pytest.raises(SystemExit):
            main([
                config_tempfile.name,
                self.src_database.url(), '-q', '-u',
                dst_database.url()
            ])
        out, err = capsys.readouterr()
        assert 'src and dst databases must be of the same type' in out
    def run_with_dst_database(self, src_url, dst_url, dst_database,
                              explain=False, verbosity=1, check=True):
        config_tempfile = self.make_config_tempfile()
        args = [config_tempfile.name, src_url]

        if explain:
            args.append('-e')
        else:
            args.extend(['-u', dst_url])

        if verbosity == 0:
            args.append('-q')
        if verbosity == 2:
            args.append('-v')
        main(args)

        if check:
            self.check_dst_database(dst_database)
    def run_with_dst_database(self,
                              src_url,
                              dst_url,
                              dst_database,
                              explain=False,
                              verbosity=1,
                              check=True):
        config_tempfile = self.make_config_tempfile()
        args = [config_tempfile.name, src_url]

        if explain:
            args.append('-e')
        else:
            args.extend(['-u', dst_url])

        if verbosity == 0:
            args.append('-q')
        if verbosity == 2:
            args.append('-v')
        main(args)

        if check:
            self.check_dst_database(dst_database)
 def test_e_f_and_u_args(self, capsys):
     for arg in ['-u', '-f']:
         with pytest.raises(SystemExit):
             main(['foo', 'bar', '-e', arg, 'foo'])
         out, err = capsys.readouterr()
         assert '%s is meaningless when using -e' % arg in out
 def test_f_and_u_args_mutual_exclusion(self, capsys):
     with pytest.raises(SystemExit):
         main(['foo', 'bar', '-u', 'foo', '-f', 'bar'])
     out, err = capsys.readouterr()
     assert 'Either -u or -f must be passed' in out