0
0
Testing Fundamentalstesting~10 mins

Authorization testing in Testing Fundamentals - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to check if a user has admin rights.

Testing Fundamentals
if user.role == [1]:
    access_granted = True
Drag options to blanks, or click blank then click option'
A"guest"
B"admin"
C"user"
D"anonymous"
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'guest' or 'user' instead of 'admin' will not grant admin access.
2fill in blank
medium

Complete the code to deny access if the user is not authorized.

Testing Fundamentals
if not user.is_authorized():
    [1] = False
Drag options to blanks, or click blank then click option'
Auser_role
Baccess_denied
Caccess_granted
Dpermission_level
Attempts:
3 left
💡 Hint
Common Mistakes
Setting 'access_denied' instead of 'access_granted' may cause confusion in logic.
3fill in blank
hard

Fix the error in the authorization check to correctly verify user permissions.

Testing Fundamentals
if "edit" [1] user.permissions:
    allow_edit = True
Drag options to blanks, or click blank then click option'
Ain
B!=
Cnot in
D==
Attempts:
3 left
💡 Hint
Common Mistakes
Using '==' instead of 'in' causes the check to fail if permissions is a list.
4fill in blank
hard

Fill both blanks to create a test that asserts unauthorized users cannot access admin pages.

Testing Fundamentals
def test_admin_access(user):
    assert user.role [1] "admin"
    assert access_to_admin_page(user) [2] False
Drag options to blanks, or click blank then click option'
A!=
B==
Cis
Dis not
Attempts:
3 left
💡 Hint
Common Mistakes
Using '==' instead of '!=' for role check allows admins only.
5fill in blank
hard

Fill all three blanks to create a dictionary comprehension that maps users to their access status based on role.

Testing Fundamentals
access_map = {user.name: True if user.role [1] "admin" [2] True [3] False for user in users}
Drag options to blanks, or click blank then click option'
A==
Bif
Celse
D!=
Attempts:
3 left
💡 Hint
Common Mistakes
Using '!=' instead of '==' reverses the logic.
Omitting 'else' causes syntax errors.