From 3320e6e7132899ffb74478db1f2e9454ccbc0435 Mon Sep 17 00:00:00 2001 From: Lars Wirzenius Date: Sat, 25 Mar 2017 12:10:50 +0200 Subject: Add TicketStore.get_message_ids --- distixlib/ticket_store.py | 14 +++++++++----- distixlib/ticket_store_tests.py | 4 +++- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/distixlib/ticket_store.py b/distixlib/ticket_store.py index a174b02..8f38084 100644 --- a/distixlib/ticket_store.py +++ b/distixlib/ticket_store.py @@ -69,6 +69,11 @@ class TicketStore(object): ticket.make_clean() self._dirty = False + def get_ticket_ids(self): + if os.path.exists(self._dirname): + return os.listdir(self._dirname) + return [] + def get_ticket(self, ticket_id_or_prefix): '''Return a distixlib.Ticket for an existing ticket in the store.''' @@ -107,11 +112,10 @@ class TicketStore(object): return self._load_tickets_from_ticket_cache(ticket_ids) def _find_ticket_dirs(self): - if os.path.exists(self._dirname): - return [ - os.path.join(self._dirname, x) - for x in os.listdir(self._dirname)] - return [] + return [ + os.path.join(self._dirname, ticket_id) + for ticket_id in self.get_ticket_ids() + ] def _cache_tickets(self, tickets): for ticket in tickets: diff --git a/distixlib/ticket_store_tests.py b/distixlib/ticket_store_tests.py index 9e47479..feba6d7 100644 --- a/distixlib/ticket_store_tests.py +++ b/distixlib/ticket_store_tests.py @@ -37,6 +37,7 @@ class TicketStoreTests(unittest.TestCase): shutil.rmtree(self.tempdir) def test_is_empty_initially(self): + self.assertListEqual(self.ticket_store.get_ticket_ids(), []) self.assertListEqual(self.ticket_store.get_tickets(), []) def test_is_empty_even_when_directory_doesnt_exist(self): @@ -54,7 +55,8 @@ class TicketStoreTests(unittest.TestCase): self.ticket.set_ticket_id('foo-id') filenames = self.ticket_store.add_ticket(self.ticket) tickets = self.ticket_store.get_tickets() - ticket_ids = [t.get_ticket_id() for t in tickets] + ticket_ids = self.ticket_store.get_ticket_ids() + self.assertListEqual(ticket_ids, [t.get_ticket_id() for t in tickets]) self.assertListEqual(ticket_ids, ['foo-id']) self.assertGreater(len(filenames), 0) -- cgit v1.2.1