Exemple #1
0
def update_datastore(id, body):
    """allow a modification to a datastore item """
    if id is None:
        raise ApiError('unknown_id', 'Please provide a valid ID.')

    item = session.query(DataStoreModel).filter_by(id=id).first()
    if item is None:
        raise ApiError('unknown_item',
                       'The item "' + id + '" is not recognized.')

    DataStoreSchema().load(body, instance=item, session=session)
    item.last_updated = datetime.utcnow()
    session.add(item)
    session.commit()
    return DataStoreSchema().dump(item)
 def add_test_study_data(self):
     study_data = DataStoreSchema().dump(self.TEST_STUDY_ITEM)
     rv = self.app.post('/v1.0/datastore',
                        content_type="application/json",
                        headers=self.logged_in_headers(),
                        data=json.dumps(study_data))
     self.assert_success(rv)
     return json.loads(rv.get_data(as_text=True))
    def test_update_datastore(self):
        self.load_example_data()
        new_study = self.add_test_study_data()
        new_study = session.query(DataStoreModel).filter_by(id=new_study["id"]).first()
        new_study.value = 'MyNewValue'
        api_response = self.app.put('/v1.0/datastore/%i' % new_study.id,
                                    data=DataStoreSchema().dumps(new_study),
                                    headers=self.logged_in_headers(), content_type="application/json")
        self.assert_success(api_response)

        api_response = self.app.get('/v1.0/datastore/%i' % new_study.id,
                                    headers=self.logged_in_headers(), content_type="application/json")
        self.assert_success(api_response)
        study_data = DataStoreSchema().loads(api_response.get_data(as_text=True))

        self.assertEqual(study_data.key, self.TEST_STUDY_ITEM['key'])
        self.assertEqual(study_data.value, 'MyNewValue')
        self.assertEqual(study_data.user_id, None)
Exemple #4
0
def study_multi_get(study_id):
    """Get all data_store values for a given study_id study"""
    if study_id is None:
        raise ApiError('unknown_study', 'Please provide a valid Study ID.')

    dsb = DataStoreBase()
    retval = dsb.get_multi_common(study_id, None)
    results = DataStoreSchema(many=True).dump(retval)
    return results
Exemple #5
0
def file_multi_get(file_id):
    """Get all data values in the data store for a file_id"""
    if file_id is None:
        raise ApiError(code='unknown_file',
                       message='Please provide a valid file id.')
    dsb = DataStoreBase()
    retval = dsb.get_multi_common(None, None, file_id=file_id)
    results = DataStoreSchema(many=True).dump(retval)
    return results
Exemple #6
0
def user_multi_get(user_id):
    """Get all data values in the data_store for a userid"""
    if user_id is None:
        raise ApiError('unknown_study', 'Please provide a valid UserID.')

    dsb = DataStoreBase()
    retval = dsb.get_multi_common(None, user_id)
    results = DataStoreSchema(many=True).dump(retval)
    return results
 def add_test_file_data(self, file_id, value):
     file_data = DataStoreSchema().dump(self.TEST_FILE_ITEM)
     file_data['file_id'] = file_id
     file_data['value'] = value
     rv = self.app.post('/v1.0/datastore',
                        content_type="application/json",
                        headers=self.logged_in_headers(),
                        data=json.dumps(file_data))
     self.assert_success(rv)
     return json.loads(rv.get_data(as_text=True))
Exemple #8
0
def add_datastore(body):
    """ add a new datastore item """

    print(body)
    if body.get(id, None):
        raise ApiError('id_specified',
                       'You may not specify an id for a new datastore item')

    if 'key' not in body:
        raise ApiError('no_key',
                       'You need to specify a key to add a datastore item')

    if 'value' not in body:
        raise ApiError('no_value',
                       'You need to specify a value to add a datastore item')

    if ('user_id' not in body) and ('study_id' not in body) and ('file_id'
                                                                 not in body):
        raise ApiError(
            'conflicting_values',
            'A datastore item should have either a study_id, user_id or file_id '
        )

    present = 0
    for field in ['user_id', 'study_id', 'file_id']:
        if field in body:
            present = present + 1
    if present > 1:
        raise ApiError(
            'conflicting_values',
            'A datastore item should have one of a study_id, user_id or a file_id '
            'but not more than one of these')

    item = DataStoreSchema().load(body)
    item.last_updated = datetime.utcnow()
    session.add(item)
    session.commit()
    return DataStoreSchema().dump(item)
    def test_get_study_data(self):
        """Generic test, but pretty detailed, in that the study should return a categorized list of workflows
        This starts with out loading the example data, to show that all the bases are covered from ground 0."""

        """NOTE:  The protocol builder is not enabled or mocked out.  As the master workflow (which is empty),
        and the test workflow do not need it, and it is disabled in the configuration."""
        self.load_example_data()
        new_study = self.add_test_study_data()
        new_study = session.query(DataStoreModel).filter_by(id=new_study["id"]).first()

        api_response = self.app.get('/v1.0/datastore/%i' % new_study.id,
                                    headers=self.logged_in_headers(), content_type="application/json")
        self.assert_success(api_response)
        d = api_response.get_data(as_text=True)
        study_data = DataStoreSchema().loads(d)

        self.assertEqual(study_data.key, self.TEST_STUDY_ITEM['key'])
        self.assertEqual(study_data.value, self.TEST_STUDY_ITEM['value'])
        self.assertEqual(study_data.user_id, None)
Exemple #10
0
def datastore_get(id):
    """retrieve a data store item by a key"""
    item = session.query(DataStoreModel).filter_by(id=id).first()
    results = DataStoreSchema(many=False).dump(item)
    return results