Example #1
0
    def test_check_diff_moved(self):
        def create_regression_files(*args, **kwargs):
            cwd = kwargs['cwd']
            open(os.path.join(cwd, 'regression.out'), 'w').close()
            open(os.path.join(cwd, 'regression.diffs'), 'w').close()
            return Mock()

        self.mock_popen.side_effect = create_regression_files
        self.mock_popen.return_value.returncode = 1

        self.assert_(not os.path.exists('regression.out'),
            "Please remove temp file 'regression.out' from current dir")
        self.assert_(not os.path.exists('regression.diffs'),
            "Please remove temp file 'regression.diffs' from current dir")

        from pgxnclient.cli import main

        try:
            self.assertRaises(PgxnClientException, main, ['check', 'foobar'])
            self.assertEquals(self.mock_popen.call_count, 1)
            self.assert_(os.path.exists('regression.out'))
            self.assert_(os.path.exists('regression.diffs'))
        finally:
            ifunlink('regression.out')
            ifunlink('regression.diffs')
Example #2
0
    def test_check_diff_moved(self):
        def create_regression_files(*args, **kwargs):
            cwd = kwargs['cwd']
            open(os.path.join(cwd, 'regression.out'), 'w').close()
            open(os.path.join(cwd, 'regression.diffs'), 'w').close()
            return Mock()

        self.mock_popen.side_effect = create_regression_files
        self.mock_popen.return_value.returncode = 1

        self.assert_(
            not os.path.exists('regression.out'),
            "Please remove temp file 'regression.out' from current dir")
        self.assert_(
            not os.path.exists('regression.diffs'),
            "Please remove temp file 'regression.diffs' from current dir")

        from pgxnclient.cli import main

        try:
            self.assertRaises(PgxnClientException, main, ['check', 'foobar'])
            self.assertEquals(self.mock_popen.call_count, 1)
            self.assert_(os.path.exists('regression.out'))
            self.assert_(os.path.exists('regression.diffs'))
        finally:
            ifunlink('regression.out')
            ifunlink('regression.diffs')
Example #3
0
    def test_download_ext(self, mock):
        mock.side_effect = fake_get_file

        fn = 'pg_amqp-0.3.0.zip'
        self.assert_(not os.path.exists(fn))

        from pgxnclient.cli import main
        try:
            main(['download', 'amqp'])
            self.assert_(os.path.exists(fn))
        finally:
            ifunlink(fn)
Example #4
0
    def test_download_testing(self, mock):
        mock.side_effect = fake_get_file

        fn = 'foobar-0.43.2b1.zip'
        self.assert_(not os.path.exists(fn))

        from pgxnclient.cli import main
        try:
            main(['download', '--testing', 'foobar'])
            self.assert_(os.path.exists(fn))
        finally:
            ifunlink(fn)
Example #5
0
    def test_download_ext(self, mock):
        mock.side_effect = fake_get_file

        fn = 'pg_amqp-0.3.0.zip'
        self.assert_(not os.path.exists(fn))

        from pgxnclient.cli import main
        try:
            main(['download', 'amqp'])
            self.assert_(os.path.exists(fn))
        finally:
            ifunlink(fn)
Example #6
0
    def test_download_url(self, mock):
        mock.side_effect = fake_get_file

        fn = 'foobar-0.43.2b1.zip'
        self.assert_(not os.path.exists(fn))

        from pgxnclient.cli import main
        try:
            main(['download', 'http://api.pgxn.org/dist/foobar/0.43.2b1/foobar-0.43.2b1.zip'])
            self.assert_(os.path.exists(fn))
        finally:
            ifunlink(fn)
Example #7
0
    def test_download_testing(self, mock):
        mock.side_effect = fake_get_file

        fn = 'foobar-0.43.2b1.zip'
        self.assert_(not os.path.exists(fn))

        from pgxnclient.cli import main
        try:
            main(['download', '--testing', 'foobar'])
            self.assert_(os.path.exists(fn))
        finally:
            ifunlink(fn)
Example #8
0
    def test_download_latest(self, mock):
        mock.side_effect = fake_get_file

        fn = "foobar-0.42.1.zip"
        self.assert_(not os.path.exists(fn))

        from pgxnclient.cli import main

        try:
            main(["download", "foobar"])
            self.assert_(os.path.exists(fn))
        finally:
            ifunlink(fn)
Example #9
0
    def test_download_url(self, mock):
        mock.side_effect = fake_get_file

        fn = 'foobar-0.43.2b1.zip'
        self.assert_(not os.path.exists(fn))

        from pgxnclient.cli import main
        try:
            main([
                'download',
                'http://api.pgxn.org/dist/foobar/0.43.2b1/foobar-0.43.2b1.zip'
            ])
            self.assert_(os.path.exists(fn))
        finally:
            ifunlink(fn)
Example #10
0
    def test_download_case_insensitive(self, mock):
        mock.side_effect = fake_get_file

        fn = 'pyrseas-0.4.1.zip'
        self.assert_(not os.path.exists(fn))

        from pgxnclient.cli import main
        try:
            main(['download', 'pyrseas'])
            self.assert_(os.path.exists(fn))
        finally:
            ifunlink(fn)

        try:
            main(['download', 'Pyrseas'])
            self.assert_(os.path.exists(fn))
        finally:
            ifunlink(fn)
Example #11
0
    def test_download_case_insensitive(self, mock):
        mock.side_effect = fake_get_file

        fn = 'pyrseas-0.4.1.zip'
        self.assert_(not os.path.exists(fn))

        from pgxnclient.cli import main
        try:
            main(['download', 'pyrseas'])
            self.assert_(os.path.exists(fn))
        finally:
            ifunlink(fn)

        try:
            main(['download', 'Pyrseas'])
            self.assert_(os.path.exists(fn))
        finally:
            ifunlink(fn)
Example #12
0
    def test_download_bad_sha1(self, mock):
        def fakefake(url):
            return fake_get_file(url, urlmap = {
                'http://api.pgxn.org/dist/foobar/0.42.1/META.json':
                'http://api.pgxn.org/dist/foobar/0.42.1/META-badsha1.json'})

        mock.side_effect = fakefake

        fn = 'foobar-0.42.1.zip'
        self.assert_(not os.path.exists(fn))

        try:
            from pgxnclient.cli import main
            from pgxnclient.errors import BadChecksum
            e = self.assertRaises(BadChecksum,
                main, ['download', 'foobar'])

            self.assert_(not os.path.exists(fn))

        finally:
            ifunlink(fn)
Example #13
0
    def test_download_rename(self, mock):
        mock.side_effect = fake_get_file

        fn = 'foobar-0.42.1.zip'
        fn1 = 'foobar-0.42.1-1.zip'
        fn2 = 'foobar-0.42.1-2.zip'

        for tmp in (fn, fn1, fn2):
            self.assert_(not os.path.exists(tmp))

        try:
            f = open(fn, "w")
            f.write('test')
            f.close()

            from pgxnclient.cli import main
            main(['download', 'foobar'])
            self.assert_(os.path.exists(fn1))
            self.assert_(not os.path.exists(fn2))

            main(['download', 'foobar'])
            self.assert_(os.path.exists(fn2))

            f = open(fn)
            self.assertEquals(f.read(), 'test')
            f.close()

        finally:
            ifunlink(fn)
            ifunlink(fn1)
            ifunlink(fn2)
Example #14
0
    def test_download_rename(self, mock):
        mock.side_effect = fake_get_file

        fn = 'foobar-0.42.1.zip'
        fn1= 'foobar-0.42.1-1.zip'
        fn2= 'foobar-0.42.1-2.zip'

        for tmp in (fn, fn1, fn2):
            self.assert_(not os.path.exists(tmp))

        try:
            f = open(fn, "w")
            f.write('test')
            f.close()

            from pgxnclient.cli import main
            main(['download', 'foobar'])
            self.assert_(os.path.exists(fn1))
            self.assert_(not os.path.exists(fn2))

            main(['download', 'foobar'])
            self.assert_(os.path.exists(fn2))

            f = open(fn)
            self.assertEquals(f.read(), 'test')
            f.close()

        finally:
            ifunlink(fn)
            ifunlink(fn1)
            ifunlink(fn2)
Example #15
0
    def test_download_bad_sha1(self, mock):
        def fakefake(url):
            return fake_get_file(
                url,
                urlmap={
                    'http://api.pgxn.org/dist/foobar/0.42.1/META.json':
                    'http://api.pgxn.org/dist/foobar/0.42.1/META-badsha1.json'
                })

        mock.side_effect = fakefake

        fn = 'foobar-0.42.1.zip'
        self.assert_(not os.path.exists(fn))

        try:
            from pgxnclient.cli import main
            from pgxnclient.errors import BadChecksum
            e = self.assertRaises(BadChecksum, main, ['download', 'foobar'])

            self.assert_(not os.path.exists(fn))

        finally:
            ifunlink(fn)