Beispiel #1
0
    def test_match(self):
        schemafile = self.add_file('schema.json', '<a schema>')
        self.add_file(
            'UPSTREAM',
            dedent("""\
                upstream:   https://x.y.z/a/b/c/debugProtocol.json
                revision:   <unknown>
                checksum:   e778c3751f9d0bceaf8d5aa81e2c659f
                downloaded: 2018-01-09 13:10:59 (UTC)
                """))
        handler = http.json_file_handler(b'<a schema>')
        with http.Server(handler) as srv:
            upstream = 'http://{}/schema.json'.format(srv.address)
            args = self.args + [
                '--schemafile',
                schemafile,
                '--upstream',
                upstream,
            ]
            res = subprocess.run(args,
                                 stdout=subprocess.PIPE,
                                 stderr=subprocess.PIPE)
        stdout = res.stdout.decode() if res.stdout else ''
        stderr = res.stderr.decode() if res.stderr else ''

        # Check the command result.
        self.assertEqual(res.returncode, 0)
        self.assertEqual(
            stdout,
            dedent("""\
                checking local schema file...
                comparing with upstream schema file...
                schema file okay
                """))
        self.assertEqual(stderr, '')
Beispiel #2
0
    def test_custom_source(self):
        handler = http.json_file_handler(b'<a schema>')
        with http.Server(handler) as srv:
            upstream = 'http://{}/schema.json'.format(srv.address)
            res = _run_subprocess(self.args + ['--source', upstream],
                                  stdout=subprocess.PIPE,
                                  stderr=subprocess.PIPE)
        stdout = res.stdout.decode() if res.stdout else ''
        stderr = res.stderr.decode() if res.stderr else ''

        # Check the command result.
        self.assertEqual(res.returncode, 0)
        self.assertEqual(
            stdout,
            self.get_expected_stdout([
                'downloading the schema file from http://localhost:8000/schema.json...',  # noqa
                '...schema file written to {}.'.format(self.schemafile),
                'saving the schema metadata...',
                '...metadata written to {}.'.format(self.metadata)
            ]))
        self.assertEqual(stderr, '')

        # Check the downloaded files.
        with open(self.schemafile) as schemafile:
            data = schemafile.read()
        with open(self.metadata) as metafile:
            metadata = metafile.read()
        orig = metadata
        metadata = '\n'.join(line for line in metadata.split('\n')
                             if not line.startswith('downloaded: '))
        self.assertEqual(data, '<a schema>')
        self.assertEqual(
            metadata,
            dedent("""\
                upstream:   http://localhost:8000/schema.json
                revision:   <unknown>
                checksum:   e778c3751f9d0bceaf8d5aa81e2c659f
                """))
        self.assertNotEqual(metadata, orig)
Beispiel #3
0
    def test_upstream_mismatch(self):
        schemafile = self.add_file('schema.json', '<a schema>')
        self.add_file(
            'UPSTREAM',
            dedent("""\
                upstream:   https://x.y.z/a/b/c/debugProtocol.json
                revision:   <unknown>
                checksum:   e778c3751f9d0bceaf8d5aa81e2c659f
                downloaded: 2018-01-09 13:10:59 (UTC)
                """))
        handler = http.json_file_handler(b'<other schema>')
        with http.Server(handler) as srv:
            upstream = 'http://{}/schema.json'.format(srv.address)
            args = self.args + [
                '--schemafile',
                schemafile,
                '--upstream',
                upstream,
            ]
            res = _run_subprocess(args,
                                  stdout=subprocess.PIPE,
                                  stderr=subprocess.PIPE)
        stdout = res.stdout.decode() if res.stdout else ''
        stderr = res.stderr.decode() if res.stderr else ''

        # Check the command result.
        self.assertEqual(res.returncode, 1)
        self.assertEqual(
            stdout,
            self.get_expected_stdout([
                'checking local schema file...',
                'comparing with upstream schema file...'
            ]))
        self.assertRegex(stderr.strip(
        ), r"ERROR: local schema file '[^']*schema.json' does not match upstream .*"
                         )  # noqa