コード例 #1
0
 def get(self, args, render_format):
     """
     Display dataset record.
     """
     # pylint: disable=no-self-use
     dataset = Dataset.objects.get(
         id=args.dataset_id, include_metadata=args.metadata)
     print(render(dataset, render_format))
     if render_format == 'table':
         from mtclient.models.datafile import DataFile
         datafiles = DataFile.list("dataset__id=%s" % args.dataset_id)
         if datafiles:
             print(render(datafiles, render_format))
コード例 #2
0
 def get(self, args, render_format):
     """
     Display experiment record.
     """
     # pylint: disable=no-self-use
     experiment = Experiment.objects.get(id=args.experiment_id,
                                         include_metadata=args.metadata)
     print(render(experiment, render_format))
     if render_format == 'table':
         datasets = Dataset.list(filters="experiments__id=%s" %
                                 args.experiment_id)
         if datasets:
             print(render(datasets, render_format, display_heading=False))
コード例 #3
0
ファイル: instrument.py プロジェクト: mytardis/mytardisclient
 def get(self, args, render_format):
     """
     Display instrument record.
     """
     # pylint: disable=no-self-use
     instrument = Instrument.objects.get(id=args.instrument_id)
     print(render(instrument, render_format))
コード例 #4
0
ファイル: api.py プロジェクト: mytardis/mytardisclient
 def list(self, _args, render_format):
     """
     Display list of API endpoints.
     """
     # pylint: disable=no-self-use
     api_endpoints = ApiEndpoint.list()
     print(render(api_endpoints, render_format))
コード例 #5
0
ファイル: api.py プロジェクト: mytardis/mytardisclient
 def get(self, args, render_format):
     """
     Display schema for a model's API endpoint.
     """
     # pylint: disable=no-self-use
     api_schema = ApiSchema.get(args.api_model)
     print(render(api_schema, render_format))
コード例 #6
0
ファイル: datafile.py プロジェクト: mytardis/mytardisclient
 def get(self, args, render_format):
     """
     Display datafile record.
     """
     # pylint: disable=no-self-use
     datafile = DataFile.objects.get(id=args.datafile_id,
                                     include_metadata=args.metadata)
     print(render(datafile, render_format))
コード例 #7
0
 def list(self, args, render_format):
     """
     Display list of experiment records.
     """
     # pylint: disable=no-self-use
     experiments = Experiment.list(args.filter, args.limit, args.offset,
                                   args.order_by)
     print(render(experiments, render_format))
コード例 #8
0
 def update(self, args, render_format):
     """
     Update dataset record.
     """
     # pylint: disable=no-self-use
     dataset = Dataset.update(args.dataset_id, args.description)
     print(render(dataset, render_format))
     print("Dataset updated successfully.")
コード例 #9
0
ファイル: datafile.py プロジェクト: mytardis/mytardisclient
 def update(self, args, render_format):
     """
     Update datafile record.
     """
     # pylint: disable=no-self-use
     datafile = DataFile.update(args.datafile_id, args.md5sum)
     print(render(datafile, render_format))
     print("DataFile updated successfully.")
コード例 #10
0
ファイル: instrument.py プロジェクト: mytardis/mytardisclient
 def update(self, args, render_format):
     """
     Update instrument record.
     """
     # pylint: disable=no-self-use
     instrument = Instrument.update(args.instrument_id, args.name)
     print(render(instrument, render_format))
     print("Instrument updated successfully.")
コード例 #11
0
 def create(self, args, render_format):
     """
     Create dataset record.
     """
     # pylint: disable=no-self-use
     dataset = Dataset.create(
         args.experiment_id, args.description, args.instrument, args.params)
     print(render(dataset, render_format))
     print("Dataset created successfully.")
コード例 #12
0
 def update(self, args, render_format):
     """
     Update experiment record.
     """
     # pylint: disable=no-self-use
     experiment = Experiment.update(args.experiment_id, args.title,
                                    args.description)
     print(render(experiment, render_format))
     print("Experiment updated successfully.")
コード例 #13
0
 def create(self, args, render_format):
     """
     Create experiment record.
     """
     # pylint: disable=no-self-use
     experiment = Experiment.create(args.title, args.description,
                                    args.institution, args.params)
     print(render(experiment, render_format))
     print("Experiment created successfully.")
コード例 #14
0
ファイル: facility.py プロジェクト: mytardis/mytardisclient
 def get(self, args, render_format):
     """
     Display facility record
     """
     super(FacilityController, self).get(args, render_format)
     if render_format == 'table':
         instruments = Instrument.list(filters="facility__id=%s" %
                                       args.facility_id)
         print(render(instruments, render_format))
コード例 #15
0
ファイル: instrument.py プロジェクト: mytardis/mytardisclient
 def create(self, args, render_format):
     """
     Create instrument record.
     """
     # pylint: disable=no-self-use
     facility_id = getattr(args, "facility_id",
                           getattr(args, "facility", None))
     instrument = Instrument.create(facility_id, args.name)
     print(render(instrument, render_format))
     print("Instrument created successfully.")
コード例 #16
0
def test_render_instrument():
    """
    Test rendering a view of an instrument record
    """
    mock_facility = {
        "id": 1,
        "manager_group": {
            "id": 1,
            "name": "test-facility-managers",
            "resource_uri": "/api/v1/group/1/"
        },
        "name": "Test Facility",
        "resource_uri": "/api/v1/facility/1/"
    }
    mock_facility_get_response = json.dumps(mock_facility)
    mock_instrument = {
        "created_time": None,
        "facility": {
            "created_time": None,
            "id": 1,
            "manager_group": {
                "id": 1,
                "name": "test-facility-managers",
                "resource_uri": "/api/v1/group/1/"
            },
            "modified_time": None,
            "name": "Test Facility",
            "resource_uri": "/api/v1/facility/1/"
        },
        "id": 1,
        "modified_time": None,
        "name": "Test Instrument",
        "resource_uri": "/api/v1/instrument/1/"
    }
    mock_instrument_get_response = json.dumps(mock_instrument)
    expected = textwrap.dedent("""
        +------------------+---------------------------+
        | Instrument field |           Value           |
        +==================+===========================+
        | ID               | 1                         |
        +------------------+---------------------------+
        | Name             | Test Instrument           |
        +------------------+---------------------------+
        | Facility         | <Facility: Test Facility> |
        +------------------+---------------------------+
    """)
    with requests_mock.Mocker() as mocker:
        get_facility_url = "%s/api/v1/facility/1/?format=json" % config.url
        mocker.get(get_facility_url, text=mock_facility_get_response)
        get_instrument_url = "%s/api/v1/instrument/1/?format=json" % config.url
        mocker.get(get_instrument_url, text=mock_instrument_get_response)

        instrument = Instrument.objects.get(id=1)

        assert render(instrument).strip() == expected.strip()
コード例 #17
0
ファイル: instrument.py プロジェクト: mytardis/mytardisclient
 def list(self, args, render_format):
     """
     Display list of instrument records.
     """
     # pylint: disable=no-self-use
     facility_id = getattr(args, "facility_id",
                           getattr(args, "facility", None))
     filters = ""
     if facility_id:
         filters = "facility__id=%s" % facility_id
     instruments = Instrument.list(filters, args.limit, args.offset,
                                   args.order_by)
     print(render(instruments, render_format))
コード例 #18
0
 def list(self, args, render_format):
     """
     Display list of dataset records.
     """
     # pylint: disable=no-self-use
     if args.exp:
         filters = "experiments__id=%s" % args.exp
     else:
         filters = ""
     if args.filter:
         filters += "&%s" % args.filter
     datasets = Dataset.list(
         filters, args.limit, args.offset, args.order_by)
     print(render(datasets, render_format))
コード例 #19
0
ファイル: datafile.py プロジェクト: mytardis/mytardisclient
 def create(self, args, render_format):
     """
     Create datafile record(s) for an existing file or for all files
     within a directory.
     """
     # pylint: disable=no-self-use
     if os.path.isdir(args.path):
         num_created = DataFile.create_datafiles(args.dataset_id,
                                                 args.storagebox,
                                                 args.dataset_path,
                                                 args.path)
         print("%s datafiles created." % num_created)
     else:
         datafile = DataFile.create_datafile(args.dataset_id,
                                             args.storagebox,
                                             args.dataset_path, args.path)
         print(render(datafile, render_format))
         print("DataFile created successfully.")
コード例 #20
0
ファイル: datafile.py プロジェクト: mytardis/mytardisclient
 def list(self, args, render_format):
     """
     Display list of datafile records.
     """
     # pylint: disable=no-self-use
     if args.dataset:
         filters = "dataset__id=%s" % args.dataset
     else:
         filters = ""
     if args.directory:
         filters += "&directory=%s" % args.directory
     if args.filename:
         filters += "&filename=%s" % args.filename
     if args.filter:
         filters += "&%s" % args.filter
     datafiles = DataFile.list(filters, args.limit, args.offset,
                               args.order_by)
     print(render(datafiles, render_format))