def test_add_get_remove(self): collection = RelocateCollection() relocate = Relocate(self.factory) assert_that(calling(collection.get).with_args(relocate.uuid), raises(KeyError).matching(has_callable('__str__', "'{}'".format(relocate.uuid)))) collection.add(relocate) assert_that(collection.get(relocate.uuid), is_(relocate)) collection.remove(relocate) assert_that(calling(collection.get).with_args(relocate.uuid), raises(KeyError).matching(has_callable('__str__', "'{}'".format(relocate.uuid))))
def test_given_another_relocate_when_get_by_channel_then_error(self): collection = RelocateCollection() relocate = Relocate(self.factory) collection.add(relocate) assert_that(calling(collection.get_by_channel).with_args('unknown'), raises(KeyError).matching(has_callable('__str__', "'unknown'")))
def test_given_relocate_when_relocate_ends_then_relocate_removed(self): collection = RelocateCollection() relocate = Relocate(self.factory) collection.add(relocate) assert_that(collection.get(relocate.uuid), is_(relocate)) relocate.events.publish('ended', relocate) assert_that(calling(collection.get).with_args(relocate.uuid), raises(KeyError).matching(has_callable('__str__', "'{}'".format(relocate.uuid))))
def test_role(self): relocate = Relocate(self.factory) relocate.relocated_channel = 'relocated' relocate.initiator_channel = 'initiator' relocate.recipient_channel = 'recipient' assert_that(relocate.role('relocated'), equal_to(RelocateRole.relocated)) assert_that(relocate.role('initiator'), equal_to(RelocateRole.initiator)) assert_that(relocate.role('recipient'), equal_to(RelocateRole.recipient)) assert_that(calling(relocate.role).with_args('unknown'), raises(KeyError).matching(has_callable('__str__', equal_to("'unknown'"))))
def test_given_no_relocates_when_get_by_channel_then_error(self): collection = RelocateCollection() assert_that( calling(collection.get_by_channel).with_args('unknown'), raises(KeyError).matching(has_callable('__str__', "'unknown'")))