Page Menu
Home
Search
Configure Global Search
Log In
Files
F13103032
test_service_badger.py
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Size
2 KB
Subscribers
None
test_service_badger.py
View Options
"""Test badger service."""
from
common_test_class
import
AbstractPillarTest
,
TEST_EMAIL_ADDRESS
class
BadgerServiceTest
(
AbstractPillarTest
):
def
setUp
(
self
,
**
kwargs
):
AbstractPillarTest
.
setUp
(
self
,
**
kwargs
)
from
application.modules
import
service
with
self
.
app
.
test_request_context
():
self
.
badger
,
token_doc
=
service
.
create_service_account
(
'serviceaccount@example.com'
,
[
u'badger'
],
{
u'badger'
:
[
u'succubus'
]}
)
self
.
badger_token
=
token_doc
[
'token'
]
self
.
user_id
=
self
.
create_user
()
self
.
user_email
=
TEST_EMAIL_ADDRESS
def
_post
(
self
,
data
):
from
application.utils
import
dumps
return
self
.
client
.
post
(
'/service/badger'
,
data
=
dumps
(
data
),
headers
=
{
'Authorization'
:
self
.
make_header
(
self
.
badger_token
),
'Content-Type'
:
'application/json'
})
def
test_grant_revoke_badge
(
self
):
# Grant the badge
resp
=
self
.
_post
({
'action'
:
'grant'
,
'user_email'
:
self
.
user_email
,
'role'
:
'succubus'
})
self
.
assertEqual
(
204
,
resp
.
status_code
)
with
self
.
app
.
test_request_context
():
user
=
self
.
app
.
data
.
driver
.
db
[
'users'
]
.
find_one
(
self
.
user_id
)
self
.
assertIn
(
u'succubus'
,
user
[
'roles'
])
# Aaaahhhw it's gone again
resp
=
self
.
_post
({
'action'
:
'revoke'
,
'user_email'
:
self
.
user_email
,
'role'
:
'succubus'
})
self
.
assertEqual
(
204
,
resp
.
status_code
)
with
self
.
app
.
test_request_context
():
user
=
self
.
app
.
data
.
driver
.
db
[
'users'
]
.
find_one
(
self
.
user_id
)
self
.
assertNotIn
(
u'succubus'
,
user
[
'roles'
])
def
test_grant_not_allowed_badge
(
self
):
resp
=
self
.
_post
({
'action'
:
'grant'
,
'user_email'
:
self
.
user_email
,
'role'
:
'admin'
})
self
.
assertEqual
(
403
,
resp
.
status_code
)
with
self
.
app
.
test_request_context
():
user
=
self
.
app
.
data
.
driver
.
db
[
'users'
]
.
find_one
(
self
.
user_id
)
self
.
assertNotIn
(
u'admin'
,
user
[
'roles'
])
File Metadata
Details
Attached
Mime Type
text/x-python
Expires
Thu, May 26, 5:09 PM (2 d)
Storage Engine
local-disk
Storage Format
Raw Data
Storage Handle
a5/19/d0568869a5b4f56f5c87b6a428fc
Attached To
rPS Pillar
Event Timeline
Log In to Comment