예제 #1
0
    def test_main_app(self, client_mock):
        collection = 'cfht'
        observation_id = '7000000o'
        ifile = '/tmp/inputobs'

        obs = SimpleObservation(collection, observation_id)

        # test create
        with open(ifile, 'wb') as infile:
            ObservationWriter().write(obs, infile)
        sys.argv = [
            "caom2tools", "create", '--resource-id',
            'ivo://ca.nrc.ca/resource', ifile
        ]
        core.main_app()
        client_mock.return_value.put_observation.assert_called_with(obs)

        # test update
        sys.argv = [
            "caom2tools", "update", '--resource-id',
            'ivo://ca.nrc.ca/resource', ifile
        ]
        core.main_app()
        client_mock.return_value.post_observation.assert_called_with(obs)

        # test read
        sys.argv = [
            "caom2tools", "read", '--resource-id', 'ivo://ca.nrc.ca/resource',
            collection, observation_id
        ]
        client_mock.return_value.get_observation.return_value = obs
        client_mock.return_value.namespace = obs_reader_writer.CAOM24_NAMESPACE
        core.main_app()
        client_mock.return_value.get_observation.\
            assert_called_with(collection, observation_id)
        # repeat with output argument
        sys.argv = [
            "caom2tools", "read", '--resource-id', 'ivo://ca.nrc.ca/resource',
            "--output", ifile, collection, observation_id
        ]
        client_mock.return_value.get_observation.return_value = obs
        core.main_app()
        client_mock.return_value.get_observation.\
            assert_called_with(collection, observation_id)
        os.remove(ifile)

        # test delete
        sys.argv = [
            "caom2tools", "delete", '--resource-id',
            'ivo://ca.nrc.ca/resource', collection, observation_id
        ]
        core.main_app()
        client_mock.return_value.delete_observation.assert_called_with(
            collection=collection, observation_id=observation_id)

        # test visit
        # get the absolute path to be able to run the tests with the
        # astropy frameworks
        plugin_file = THIS_DIR + "/passplugin.py"
        sys.argv = [
            "caom2tools", "visit", '--resource-id', 'ivo://ca.nrc.ca/resource',
            "--plugin", plugin_file, "--start", "2012-01-01T11:22:33", "--end",
            "2013-01-01T11:33:22", collection
        ]
        client_mock.return_value.visit.return_value = ['1'], ['1'], [], []
        with open(plugin_file, 'r') as infile:
            core.main_app()
            client_mock.return_value.visit.assert_called_with(
                ANY,
                collection,
                halt_on_error=False,
                nthreads=None,
                obs_file=None,
                start=core.str2date("2012-01-01T11:22:33"),
                end=core.str2date("2013-01-01T11:33:22"))

        # repeat visit test with halt-on-error
        sys.argv = [
            "caom2tools", "visit", '--resource-id', 'ivo://ca.nrc.ca/resource',
            "--plugin", plugin_file, '--halt-on-error', "--start",
            "2012-01-01T11:22:33", "--end", "2013-01-01T11:33:22", collection
        ]
        client_mock.return_value.visit.return_value = ['1'], ['1'], [], []
        with open(plugin_file, 'r') as infile:
            core.main_app()
            client_mock.return_value.visit.assert_called_with(
                ANY,
                collection,
                halt_on_error=True,
                nthreads=None,
                obs_file=None,
                start=core.str2date("2012-01-01T11:22:33"),
                end=core.str2date("2013-01-01T11:33:22"))
예제 #2
0
    def test_main_app(self, client_mock):
        collection = 'cfht'
        observation_id = '7000000o'
        ifile = '/tmp/inputobs'

        obs = SimpleObservation(collection, observation_id)

        # test create
        with open(ifile, 'wb') as infile:
            ObservationWriter().write(obs, infile)
        sys.argv = ["caom2tools", "create", '--resource-id',
                    'ivo://ca.nrc.ca/resource', ifile]
        core.main_app()
        client_mock.return_value.put_observation.assert_called_with(obs)

        # test update
        sys.argv = ["caom2tools", "update", '--resource-id',
                    'ivo://ca.nrc.ca/resource', ifile]
        core.main_app()
        client_mock.return_value.post_observation.assert_called_with(obs)

        # test read
        sys.argv = ["caom2tools", "read", '--resource-id',
                    'ivo://ca.nrc.ca/resource',
                    collection, observation_id]
        client_mock.return_value.get_observation.return_value = obs
        core.main_app()
        client_mock.return_value.get_observation.\
            assert_called_with(collection, observation_id)
        # repeat with output argument
        sys.argv = ["caom2tools", "read", '--resource-id',
                    'ivo://ca.nrc.ca/resource',
                    "--output", ifile, collection, observation_id]
        client_mock.return_value.get_observation.return_value = obs
        core.main_app()
        client_mock.return_value.get_observation.\
            assert_called_with(collection, observation_id)
        os.remove(ifile)

        # test delete
        sys.argv = ["caom2tools", "delete", '--resource-id',
                    'ivo://ca.nrc.ca/resource',
                    collection, observation_id]
        core.main_app()
        client_mock.return_value.delete_observation.assert_called_with(
            collection=collection,
            observation_id=observation_id)

        # test visit
        # get the absolute path to be able to run the tests with the
        # astropy frameworks
        plugin_file = THIS_DIR + "/passplugin.py"
        sys.argv = ["caom2tools", "visit", '--resource-id',
                    'ivo://ca.nrc.ca/resource',
                    "--plugin", plugin_file, "--start", "2012-01-01T11:22:33",
                    "--end", "2013-01-01T11:33:22", collection]
        client_mock.return_value.visit.return_value = ['1'], ['1'], [], []
        with open(plugin_file, 'r') as infile:
            core.main_app()
            client_mock.return_value.visit.assert_called_with(
                ANY, collection, halt_on_error=False, nthreads=None,
                obs_file=None,
                start=core.str2date("2012-01-01T11:22:33"),
                end=core.str2date("2013-01-01T11:33:22"))

        # repeat visit test with halt-on-error
        sys.argv = ["caom2tools", "visit", '--resource-id',
                    'ivo://ca.nrc.ca/resource',
                    "--plugin", plugin_file, '--halt-on-error',
                    "--start", "2012-01-01T11:22:33",
                    "--end", "2013-01-01T11:33:22", collection]
        client_mock.return_value.visit.return_value = ['1'], ['1'], [], []
        with open(plugin_file, 'r') as infile:
            core.main_app()
            client_mock.return_value.visit.assert_called_with(
                ANY, collection, halt_on_error=True, nthreads=None,
                obs_file=None,
                start=core.str2date("2012-01-01T11:22:33"),
                end=core.str2date("2013-01-01T11:33:22"))