diff options
author | Lars Wirzenius <liw@liw.fi> | 2017-03-25 12:10:50 +0200 |
---|---|---|
committer | Lars Wirzenius <liw@liw.fi> | 2017-03-25 12:55:18 +0200 |
commit | 3320e6e7132899ffb74478db1f2e9454ccbc0435 (patch) | |
tree | fce0e0ff7a26b039962c4dbce21cbaf329f41ce2 | |
parent | 2ff64cae65415907007b0d474461af38fd41b073 (diff) | |
download | distix-3320e6e7132899ffb74478db1f2e9454ccbc0435.tar.gz |
Add TicketStore.get_message_ids
-rw-r--r-- | distixlib/ticket_store.py | 14 | ||||
-rw-r--r-- | 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) |