def create_specific_query_with_baton_json_representation() -> Tuple[SpecificQuery, Dict]:
    """
    Creates a specific query and returns it along with the JSON representation of it given by baton.

    Uses baton to get the JSON representation on the first use: the JSON is retrieved from a cache in subsequent uses.
    :return: a tuple where the first element is the created specific query and the second is its JSON representation
    according to baton
    """
    global _specific_query, _specific_query_as_json

    # Starting baton is expensive - get view of baton JSON and cache
    if _specific_query is None:
        test_with_baton = TestWithBaton()
        test_with_baton.setup()

        baton_runner = BatonRunner(test_with_baton.baton_location, test_with_baton.irods_server.users[0].zone)

        baton_query = baton_runner.run_baton_query(BatonBinary.BATON, ["-s", IRODS_SPECIFIC_QUERY_FIND_QUERY_BY_ALIAS,
                                                                       "-b", IRODS_SPECIFIC_QUERY_FIND_QUERY_BY_ALIAS])
        _specific_query_as_json = baton_runner.run_baton_query(
                BatonBinary.BATON_SPECIFIC_QUERY, input_data=baton_query)[0]

        _specific_query = SpecificQuery(
            IRODS_SPECIFIC_QUERY_FIND_QUERY_BY_ALIAS, _specific_query_as_json[0][BATON_SPECIFIC_QUERY_SQL_PROPERTY])

    return deepcopy(_specific_query), deepcopy(_specific_query_as_json)
def create_collection_with_baton_json_representation() -> Tuple[Collection, Dict]:
    """
    Creates a collection and returns it along with the JSON representation of it given by baton.

    Uses baton to get the JSON representation on the first use: the JSON is retrieved from a cache in subsequent uses.
    :return: a tuple where the first element is the created collection and the second is its JSON representation
    according to baton
    """
    global _collection, _collection_as_json

    # Starting baton is expensive - get view of baton JSON and cache
    if _collection is None:
        test_with_baton = TestWithBaton()
        test_with_baton.setup()

        metadata = IrodsMetadata({"attribute_a": {"value_1", "value_2"}, "attribute_b": {"value_3"}})
        _collection = create_collection(test_with_baton, "collection_1", metadata)

        baton_query = {
            BATON_COLLECTION_PROPERTY: _collection.path
        }
        baton_runner = BatonRunner(test_with_baton.baton_location, test_with_baton.irods_server.users[0].zone)

        _collection_as_json = baton_runner.run_baton_query(
                BatonBinary.BATON_LIST, ["--acl", "--avu"], input_data=baton_query)[0]

    return deepcopy(_collection), deepcopy(_collection_as_json)
Пример #3
0
def synchronise_collection_timestamps(test_with_baton: TestWithBaton, collection: Collection):
    """
    Synchronises the timestamps of the given data object to align with the timestamps recorded on iRODS.
    :param test_with_baton: framework to allow testing with baton
    :param data_object: data object to synchronise timestamps for
    """
    baton_runner = BatonRunner(test_with_baton.baton_location)
    query_input = CollectionJSONEncoder().default(collection)
    query_return = baton_runner.run_baton_query(BatonBinary.BATON_LIST, ["--timestamp"], query_input)
    date_parser = parser()
    for timestamp_as_json in query_return[0]["timestamps"]:
        if "created" in timestamp_as_json:
            collection.created = date_parser.parse(timestamp_as_json["created"])
        else:
            collection.last_modified = date_parser.parse(timestamp_as_json["modified"])
Пример #4
0
def synchronise_data_object_timestamps(test_with_baton: TestWithBaton, data_object: DataObject):
    """
    Synchronises the timestamps of the given data object to align with the timestamps recorded on iRODS.
    :param test_with_baton: framework to allow testing with baton
    :param data_object: data object to synchronise timestamps for
    """
    baton_runner = BatonRunner(test_with_baton.baton_location)
    query_input = DataObjectJSONEncoder().default(data_object)
    query_return = baton_runner.run_baton_query(BatonBinary.BATON_LIST, ["--timestamp"], query_input)
    date_parser = parser()
    for timestamp_as_json in query_return[0]["timestamps"]:
        replica_number = timestamp_as_json["replicates"]
        replica = data_object.replicas.get_by_number(replica_number)
        if "created" in timestamp_as_json:
            replica.created = date_parser.parse(timestamp_as_json["created"])
        else:
            replica.last_modified = date_parser.parse(timestamp_as_json["modified"])
 def test_validate_baton_binaries_location_with_binaries_location(self):
     self.test_with_baton.setup()
     self.assertIsNone(BatonRunner.validate_baton_binaries_location(self.test_with_baton.baton_location))
 def test_validate_baton_binaries_location_with_non_binaries_location(self):
     self.assertIsInstance(BatonRunner.validate_baton_binaries_location("."), ValueError)