class TestBatonInstalledSpecificQueryMapper(unittest.TestCase): """ Tests for `BatonSpecificQueryMapper`. """ def setUp(self): self.test_with_baton = TestWithBaton(baton_setup=BATON_SETUP) self.test_with_baton.setup() self.setup_helper = SetupHelper(self.test_with_baton.icommands_location) self.mapper = BatonSpecificQueryMapper(self.test_with_baton.baton_location) def test_get_all(self): iquest_ls_response = self.setup_helper.run_icommand(["iquest", "--sql", "ls"]) expected = TestBatonInstalledSpecificQueryMapper._parse_iquest_ls(iquest_ls_response) specific_queries = self.mapper.get_all() self.assertCountEqual(specific_queries, expected) @staticmethod def _parse_iquest_ls(iquest_ls_response: str) -> Sequence[SpecificQuery]: """ Gets the installed specific queries by parsing the output returned by "iquest --sql ls". :param iquest_ls_response: the response returned by the iquest command :return: the specific queries installed on the iRODS server """ iquest_ls_response_lines = iquest_ls_response.split('\n') assert (len(iquest_ls_response_lines) + 1) % 3 == 0 specific_queries = [] for i in range(int((len(iquest_ls_response_lines) + 1) / 3)): i3 = int(3 * i) alias = iquest_ls_response_lines[i3] sql = iquest_ls_response_lines[i3 + 1] specific_queries.append(SpecificQuery(alias, sql)) return specific_queries
def setUp(self): self.test_with_baton = TestWithBaton(baton_setup=BATON_SETUP) self.test_with_baton.setup() self.setup_helper = SetupHelper(self.test_with_baton.icommands_location) self.mapper = BatonSpecificQueryMapper(self.test_with_baton.baton_location)