def test_apikey_generates_key(self):
stderr = StringIO()
stdout = StringIO()
user = factory.make_User()
num_keys = len(user.userprofile.get_authorisation_tokens())
call_command(
'apikey', username=user.username, generate=True, stderr=stderr,
stdout=stdout)
self.assertThat(stderr, IsEmpty)
keys_after = user.userprofile.get_authorisation_tokens()
expected_num_keys = num_keys + 1
self.assertEqual(expected_num_keys, len(keys_after))
expected_token = user.userprofile.get_authorisation_tokens()[1]
expected_string = convert_tuple_to_string(
get_creds_tuple(expected_token)) + '\n'
self.assertEqual(expected_string, stdout.getvalue())
评论列表
文章目录