Fix image member unit tests occasional failures
Let's try just unrolling the member status tests and not getting too fancy here. Change-Id: I30022ebd2da6d6cf1abba424d7d7fa679285f291
This commit is contained in:
parent
4b2355b3e3
commit
96f3c7e783
@ -829,6 +829,11 @@ class TestImageSet(TestImage):
|
|||||||
|
|
||||||
self.images_mock.get.return_value = self.model(**image_fakes.IMAGE)
|
self.images_mock.get.return_value = self.model(**image_fakes.IMAGE)
|
||||||
self.images_mock.update.return_value = self.model(**image_fakes.IMAGE)
|
self.images_mock.update.return_value = self.model(**image_fakes.IMAGE)
|
||||||
|
|
||||||
|
self.app.client_manager.auth_ref = mock.Mock(
|
||||||
|
project_id=self.project.id,
|
||||||
|
)
|
||||||
|
|
||||||
# Get the command object to test
|
# Get the command object to test
|
||||||
self.cmd = image.SetImage(self.app, None)
|
self.cmd = image.SetImage(self.app, None)
|
||||||
|
|
||||||
@ -847,20 +852,21 @@ class TestImageSet(TestImage):
|
|||||||
|
|
||||||
self.image_members_mock.update.assert_not_called()
|
self.image_members_mock.update.assert_not_called()
|
||||||
|
|
||||||
def test_image_set_membership_option(self):
|
def test_image_set_membership_option_accept(self):
|
||||||
membership = image_fakes.FakeImage.create_one_image_member(
|
membership = image_fakes.FakeImage.create_one_image_member(
|
||||||
attrs={'image_id': image_fakes.image_id,
|
attrs={'image_id': image_fakes.image_id,
|
||||||
'member_id': self.project.id}
|
'member_id': self.project.id}
|
||||||
)
|
)
|
||||||
self.image_members_mock.update.return_value = membership
|
self.image_members_mock.update.return_value = membership
|
||||||
|
|
||||||
for status in ('accept', 'reject', 'pending'):
|
|
||||||
arglist = [
|
arglist = [
|
||||||
'--%s' % status,
|
'--accept',
|
||||||
image_fakes.image_id,
|
image_fakes.image_id,
|
||||||
]
|
]
|
||||||
verifylist = [
|
verifylist = [
|
||||||
(status, True),
|
('accept', True),
|
||||||
|
('reject', False),
|
||||||
|
('pending', False),
|
||||||
('image', image_fakes.image_id)
|
('image', image_fakes.image_id)
|
||||||
]
|
]
|
||||||
|
|
||||||
@ -870,9 +876,70 @@ class TestImageSet(TestImage):
|
|||||||
self.image_members_mock.update.assert_called_once_with(
|
self.image_members_mock.update.assert_called_once_with(
|
||||||
image_fakes.image_id,
|
image_fakes.image_id,
|
||||||
self.app.client_manager.auth_ref.project_id,
|
self.app.client_manager.auth_ref.project_id,
|
||||||
status if status == 'pending' else status + 'ed'
|
'accepted',
|
||||||
|
)
|
||||||
|
|
||||||
|
# Assert that the 'update image" route is also called, in addition to
|
||||||
|
# the 'update membership' route.
|
||||||
|
self.images_mock.update.assert_called_with(image_fakes.image_id)
|
||||||
|
|
||||||
|
def test_image_set_membership_option_reject(self):
|
||||||
|
membership = image_fakes.FakeImage.create_one_image_member(
|
||||||
|
attrs={'image_id': image_fakes.image_id,
|
||||||
|
'member_id': self.project.id}
|
||||||
|
)
|
||||||
|
self.image_members_mock.update.return_value = membership
|
||||||
|
|
||||||
|
arglist = [
|
||||||
|
'--reject',
|
||||||
|
image_fakes.image_id,
|
||||||
|
]
|
||||||
|
verifylist = [
|
||||||
|
('accept', False),
|
||||||
|
('reject', True),
|
||||||
|
('pending', False),
|
||||||
|
('image', image_fakes.image_id)
|
||||||
|
]
|
||||||
|
|
||||||
|
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
|
||||||
|
self.cmd.take_action(parsed_args)
|
||||||
|
|
||||||
|
self.image_members_mock.update.assert_called_once_with(
|
||||||
|
image_fakes.image_id,
|
||||||
|
self.app.client_manager.auth_ref.project_id,
|
||||||
|
'rejected',
|
||||||
|
)
|
||||||
|
|
||||||
|
# Assert that the 'update image" route is also called, in addition to
|
||||||
|
# the 'update membership' route.
|
||||||
|
self.images_mock.update.assert_called_with(image_fakes.image_id)
|
||||||
|
|
||||||
|
def test_image_set_membership_option_pending(self):
|
||||||
|
membership = image_fakes.FakeImage.create_one_image_member(
|
||||||
|
attrs={'image_id': image_fakes.image_id,
|
||||||
|
'member_id': self.project.id}
|
||||||
|
)
|
||||||
|
self.image_members_mock.update.return_value = membership
|
||||||
|
|
||||||
|
arglist = [
|
||||||
|
'--pending',
|
||||||
|
image_fakes.image_id,
|
||||||
|
]
|
||||||
|
verifylist = [
|
||||||
|
('accept', False),
|
||||||
|
('reject', False),
|
||||||
|
('pending', True),
|
||||||
|
('image', image_fakes.image_id)
|
||||||
|
]
|
||||||
|
|
||||||
|
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
|
||||||
|
self.cmd.take_action(parsed_args)
|
||||||
|
|
||||||
|
self.image_members_mock.update.assert_called_once_with(
|
||||||
|
image_fakes.image_id,
|
||||||
|
self.app.client_manager.auth_ref.project_id,
|
||||||
|
'pending',
|
||||||
)
|
)
|
||||||
self.image_members_mock.update.reset_mock()
|
|
||||||
|
|
||||||
# Assert that the 'update image" route is also called, in addition to
|
# Assert that the 'update image" route is also called, in addition to
|
||||||
# the 'update membership' route.
|
# the 'update membership' route.
|
||||||
|
Loading…
Reference in New Issue
Block a user