/tests/rackspace/requests/identity/user_tests.rb

https://gitlab.com/debian-ruby/ruby-fog-rackspace · Ruby · 106 lines · 82 code · 21 blank · 3 comment · 1 complexity · e4aa99a3be78e75d218710a99c7618b7 MD5 · raw file

  1. Shindo.tests('Fog::Rackspace::Identity | users', ['rackspace']) do
  2. pending if Fog.mock?
  3. USER_INFO = {
  4. 'id' => String,
  5. 'username' => String,
  6. 'email' => Fog::Nullable::String,
  7. 'enabled' => Fog::Boolean,
  8. 'OS-KSADM:password' => Fog::Nullable::String,
  9. 'created' => Fog::Nullable::String,
  10. 'updated' => Fog::Nullable::String
  11. }
  12. USER_FORMAT = {
  13. 'user' => USER_INFO
  14. }
  15. USERS_FORMAT = {
  16. 'users' => [USER_INFO]
  17. }
  18. CREDENTIAL_FORMAT = {
  19. 'RAX-KSKEY:apiKeyCredentials' => {
  20. 'username' => String,
  21. 'apiKey' => String
  22. }
  23. }
  24. CREDENTIALS_FORMAT = {
  25. 'credentials' => [CREDENTIAL_FORMAT]
  26. }
  27. ROLES_FORMAT = {
  28. 'roles' => [{
  29. 'id' => String,
  30. 'name' => String,
  31. 'description' => String
  32. }]
  33. }
  34. service = Fog::Rackspace::Identity.new
  35. id = nil
  36. username = "fog#{Time.now.to_i.to_s}"
  37. email = 'fog_user@example.com'
  38. enabled = true
  39. password = 'Fog_password1'
  40. tests('success') do
  41. tests('#create_user').formats(USER_FORMAT) do
  42. data = service.create_user(username, email, enabled).body
  43. id = data['user']['id']
  44. data
  45. end
  46. tests('#delete_user').succeeds do
  47. service.delete_user(id)
  48. end
  49. # there appears to be a werid caching issue. It's just easier to create a new username and continue on
  50. username = "fog#{Time.now.to_i.to_s}"
  51. tests('#create_user with password').succeeds do
  52. data = service.create_user(username, email, enabled, :password => password ).body
  53. id = data['user']['id']
  54. data
  55. end
  56. tests('#get_user_by_name').formats(USER_FORMAT) do
  57. data = service.get_user_by_name(username).body
  58. id = data['user']['id']
  59. data
  60. end
  61. tests('#get_user_by_id').formats(USER_FORMAT) do
  62. service.get_user_by_id(id).body
  63. end
  64. tests('#list_users').formats(USERS_FORMAT) do
  65. service.list_users().body
  66. end
  67. tests('#update_user').formats(USER_FORMAT) do
  68. service.update_user(id, username, 'updated_user@example.com', enabled).body
  69. end
  70. tests('#update_user with password').succeeds do
  71. service.update_user(id, username, email, enabled, :password => password).body
  72. end
  73. tests('#list_user_roles').formats(ROLES_FORMAT) do
  74. service.list_user_roles(id).body
  75. end
  76. service.delete_user(id)
  77. # Users are only authorized to request their own credentials,
  78. # so perform credential tests with the ID of the user running tests.
  79. credential_username = Fog.credentials[:rackspace_username]
  80. credential_id = service.get_user_by_name(credential_username).body['user']['id']
  81. tests('#list_credentials').formats(CREDENTIALS_FORMAT) do
  82. service.list_credentials(credential_id).body
  83. end
  84. end
  85. end