blob: 62faf0c5becf8b2580e48d8a9a8551ff3b3fb2c9 [file] [log] [blame]
Jamie Hannaford6e4d7952014-10-29 16:18:29 +01001package users
2
3import (
4 "testing"
5
6 os "github.com/rackspace/gophercloud/openstack/identity/v2/users"
7 "github.com/rackspace/gophercloud/pagination"
8 th "github.com/rackspace/gophercloud/testhelper"
9 "github.com/rackspace/gophercloud/testhelper/client"
10)
11
12func TestList(t *testing.T) {
13 th.SetupHTTP()
14 defer th.TeardownHTTP()
15
16 mockListResponse(t)
17
18 count := 0
19
20 err := List(client.ServiceClient()).EachPage(func(page pagination.Page) (bool, error) {
21 count++
22 users, err := os.ExtractUsers(page)
23
24 th.AssertNoErr(t, err)
25 th.AssertEquals(t, "u1000", users[0].ID)
26 th.AssertEquals(t, "u1001", users[1].ID)
27
28 return true, nil
29 })
30
31 th.AssertNoErr(t, err)
32 th.AssertEquals(t, 1, count)
33}
34
35func TestCreateUser(t *testing.T) {
36 th.SetupHTTP()
37 defer th.TeardownHTTP()
38
39 mockCreateUser(t)
40
41 opts := CreateOpts{
42 Username: "new_user",
43 Enabled: os.Disabled,
44 Email: "new_user@foo.com",
45 Password: "foo",
46 }
47
48 user, err := Create(client.ServiceClient(), opts).Extract()
49
50 th.AssertNoErr(t, err)
51
52 th.AssertEquals(t, "123456", user.ID)
53 th.AssertEquals(t, "5830280", user.DomainID)
54 th.AssertEquals(t, "DFW", user.DefaultRegion)
55}
56
57func TestGetUser(t *testing.T) {
58 th.SetupHTTP()
59 defer th.TeardownHTTP()
60
61 mockGetUser(t)
62
63 user, err := Get(client.ServiceClient(), "new_user").Extract()
64 th.AssertNoErr(t, err)
65
66 th.AssertEquals(t, true, user.Enabled)
Jamie Hannaford14e44c92014-10-30 12:12:54 +010067 th.AssertEquals(t, true, user.MultiFactorEnabled)
Jamie Hannaford6e4d7952014-10-29 16:18:29 +010068}
69
70func TestUpdateUser(t *testing.T) {
71 th.SetupHTTP()
72 defer th.TeardownHTTP()
73
74 mockUpdateUser(t)
75
76 id := "c39e3de9be2d4c779f1dfd6abacc176d"
77
78 opts := UpdateOpts{
79 Enabled: os.Enabled,
80 Email: "new_email@foo.com",
81 }
82
83 user, err := Update(client.ServiceClient(), id, opts).Extract()
84
85 th.AssertNoErr(t, err)
86
87 th.AssertEquals(t, true, user.Enabled)
88 th.AssertEquals(t, "new_email@foo.com", user.Email)
89}
90
91func TestDeleteServer(t *testing.T) {
92 th.SetupHTTP()
93 defer th.TeardownHTTP()
94
Jamie Hannafordb136b182014-10-30 15:20:10 +010095 mockDeleteUser(t)
Jamie Hannaford6e4d7952014-10-29 16:18:29 +010096
97 res := Delete(client.ServiceClient(), "c39e3de9be2d4c779f1dfd6abacc176d")
98 th.AssertNoErr(t, res.Err)
99}
Paul Quernafdc369a2014-10-31 11:50:20 -0700100
101func TestResetAPIKey(t *testing.T) {
102 th.SetupHTTP()
103 defer th.TeardownHTTP()
104
105 mockResetAPIKey(t)
106
107 apiKey, err := ResetAPIKey(client.ServiceClient(), "99").Extract()
108 th.AssertNoErr(t, err)
109 th.AssertEquals(t, "joesmith", apiKey.Username)
110 th.AssertEquals(t, "mooH1eiLahd5ahYood7r", apiKey.APIKey)
111}