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))
def test_datafile_list(): """ Test listing datafile records exposed in a MyTardis REST API """ mock_datafile_list = { "meta": { "limit": 20, "next": None, "offset": 0, "previous": None, "total_count": 1 }, "objects": [{ "id": 1, "created_time": "2016-11-10T13:50:25.258483", "dataset": "/api/v1/dataset/1/", "directory": "subdir", "filename": "testfile1.txt", "md5sum": "bogus", "mimetype": "text/plain", "modification_time": None, "parameter_sets": [], "replicas": [{ "datafile": "/api/v1/dataset_file/1/", "id": 1, "location": "local box at /home/mytardis/var/local", "resource_uri": "/api/v1/replica/1/", "uri": "subdir/testfile1.txt", "verified": True }], "resource_uri": "/api/v1/dataset_file/1/", "size": 32, }] } mock_list_response = json.dumps(mock_datafile_list) with requests_mock.Mocker() as mocker: list_datafiles_url = "%s/api/v1/dataset_file/?format=json&dataset__id=1" % config.url mocker.get(list_datafiles_url, text=mock_list_response) datafiles = DataFile.list(filters="dataset__id=1") assert datafiles.response_dict == mock_datafile_list
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))