def test_set_username(self):
"""Test set username method."""
# Test unicode converts to ascii J?hn to John
with patch.object(AmazonAccountUtils,
'iam_user_exists',
return_value=False):
self.aws_account._set_username()
self.assertEqual(self.aws_account.username, 'John')
# Test random username generated if iam user exists
with patch.object(AmazonAccountUtils,
'iam_user_exists',
return_value=True):
self.aws_account._set_username()
self.assertNotEqual(self.aws_account.username, 'John')
self.assertEqual(len(self.aws_account.username), 20)
# Test random username is generated when regex invalid
# after conversion. ??? converts to ???.
self.user.username = '???'
self.aws_account._set_username()
self.assertNotEqual(self.aws_account.username, '???')
self.assertEqual(len(self.aws_account.username), 20)
评论列表
文章目录