diff --git a/ui/fixtures/cmd.basic.json b/ui/fixtures/cmd.basic.json index 601552c..9a6b96b 100644 --- a/ui/fixtures/cmd.basic.json +++ b/ui/fixtures/cmd.basic.json @@ -178,6 +178,9 @@ "exit": 1, "stderr": "ERROR: tag needs to start with a \"+\" (add) or a \"-\" (remove).\n" }, +{ + "special": "iter is unique" +}, { "skip": 1, "title": "dump is correct", diff --git a/ui/medashare/cli.py b/ui/medashare/cli.py index 6049a25..2cb764d 100644 --- a/ui/medashare/cli.py +++ b/ui/medashare/cli.py @@ -476,7 +476,13 @@ class ObjectStore(object): return len(self._uuids) def __iter__(self): - return iter(self._uuids.values()) + seen = set() + for i in self._uuids.values(): + if i['uuid'] in seen: + continue + + yield i + seen.add(i['uuid']) def store(self, fname): '''Write out the objects in the store to the file named @@ -1331,6 +1337,10 @@ class _TestCases(unittest.TestCase): hostidpatch = mock.patch(__name__ + '.hostuuid') hostidpatch.start().return_value = uuid.uuid4() patches.append(hostidpatch) + elif special == 'iter is unique': + objst = ObjectStore.load(storefname) + uniqobjs = len(set((x['uuid'] for x in objst))) + self.assertEqual(len(list(objst)), uniqobjs) else: # pragma: no cover raise ValueError('unhandled special: %s' % repr(special))