Browse Source

add unit tests that test user linking

Natenom/support-murmur-13-1446181288462
Michael Ziegler 15 years ago
parent
commit
26f07f9878
  1. 42
      pyweb/mumble/fixtures/testdb.json
  2. 46
      pyweb/mumble/tests.py

42
pyweb/mumble/fixtures/testdb.json

@ -42,6 +42,28 @@
"server": 1 "server": 1
} }
}, },
{
"pk": 2,
"model": "mumble.mumbleuser",
"fields": {
"owner": null,
"mumbleid": 2,
"password": "",
"name": "nichtadmin",
"server": 1
}
},
{
"pk": 3,
"model": "mumble.mumbleuser",
"fields": {
"owner": null,
"mumbleid": 3,
"password": "",
"name": "dochadmin",
"server": 1
}
},
{ {
"pk": 13, "pk": 13,
"model": "auth.permission", "model": "auth.permission",
@ -430,12 +452,30 @@
"is_active": true, "is_active": true,
"is_superuser": true, "is_superuser": true,
"is_staff": true, "is_staff": true,
"last_login": "2010-08-02 15:56:15",
"last_login": "2010-08-04 22:59:55",
"groups": [], "groups": [],
"user_permissions": [], "user_permissions": [],
"password": "sha1$71bab$1dd52b90d6b63ba95483292dc50ac58ee71ca551", "password": "sha1$71bab$1dd52b90d6b63ba95483292dc50ac58ee71ca551",
"email": "diese-addy@funzt-halt.net", "email": "diese-addy@funzt-halt.net",
"date_joined": "2010-07-23 08:43:57" "date_joined": "2010-07-23 08:43:57"
} }
},
{
"pk": 2,
"model": "auth.user",
"fields": {
"username": "nocheinuser",
"first_name": "",
"last_name": "",
"is_active": true,
"is_superuser": false,
"is_staff": false,
"last_login": "2010-08-04 23:43:38",
"groups": [],
"user_permissions": [],
"password": "sha1$42964$bbadc83a17fb5272a9461b64fd70a12d353614f2",
"email": "",
"date_joined": "2010-08-04 23:43:38"
}
} }
] ]

46
pyweb/mumble/tests.py

@ -78,7 +78,7 @@ class ExtDirectFormTestMixin(object):
return response['result'] return response['result']
class AuthedTestCase( TestCase ):
class AdminAuthedTestCase( TestCase ):
fixtures = ["testdb.json"] fixtures = ["testdb.json"]
def setUp( self ): def setUp( self ):
@ -86,6 +86,15 @@ class AuthedTestCase( TestCase ):
if not self.cl.login( username="svedrin", password="passwort" ): if not self.cl.login( username="svedrin", password="passwort" ):
raise Exception( "Login failed" ) raise Exception( "Login failed" )
class UserAuthedTestCase( TestCase ):
fixtures = ["testdb.json"]
def setUp( self ):
TestCase.setUp( self )
if not self.cl.login( username="nocheinuser", password="passwort" ):
raise Exception( "Login failed" )
class UnauthedMumbleFormTestCase( ExtDirectFormTestMixin, TestCase ): class UnauthedMumbleFormTestCase( ExtDirectFormTestMixin, TestCase ):
api_baseurl = "/mumble/forms" api_baseurl = "/mumble/forms"
formname = "MumbleForm" formname = "MumbleForm"
@ -101,7 +110,7 @@ class UnauthedMumbleFormTestCase( ExtDirectFormTestMixin, TestCase ):
self.assertEquals( result['errors'][''], 'access denied' ) self.assertEquals( result['errors'][''], 'access denied' )
class AuthedMumbleFormTestCase( ExtDirectFormTestMixin, AuthedTestCase ):
class AuthedMumbleFormTestCase( ExtDirectFormTestMixin, AdminAuthedTestCase ):
api_baseurl = "/mumble/forms" api_baseurl = "/mumble/forms"
formname = "MumbleForm" formname = "MumbleForm"
@ -137,7 +146,7 @@ class UnauthedMumbleUserFormTestCase( ExtDirectFormTestMixin, TestCase ):
self.assertEquals( result['success'], False ) self.assertEquals( result['success'], False )
self.assertEquals( result['errors'][''], 'access denied' ) self.assertEquals( result['errors'][''], 'access denied' )
class AuthedMumbleUserFormTestCase( ExtDirectFormTestMixin, AuthedTestCase ):
class AuthedMumbleUserFormTestCase( ExtDirectFormTestMixin, AdminAuthedTestCase ):
api_baseurl = "/mumble/forms" api_baseurl = "/mumble/forms"
formname = "MumbleUserForm" formname = "MumbleUserForm"
@ -168,7 +177,7 @@ class UnauthedMumbleUserLinkFormTestCase( UnauthedMumbleUserFormTestCase ):
self.assertEquals( result['success'], False ) self.assertEquals( result['success'], False )
self.assertEquals( result['errors'][''], 'access denied' ) self.assertEquals( result['errors'][''], 'access denied' )
class AuthedMumbleUserLinkFormTestCase( ExtDirectFormTestMixin, AuthedTestCase ):
class AuthedMumbleUserLinkFormTestCase( ExtDirectFormTestMixin, AdminAuthedTestCase ):
api_baseurl = "/mumble/forms" api_baseurl = "/mumble/forms"
formname = "MumbleUserLinkForm" formname = "MumbleUserLinkForm"
@ -194,6 +203,35 @@ class AuthedMumbleUserLinkFormTestCase( ExtDirectFormTestMixin, AuthedTestCase )
result = self.formPost( {'pk': 1, 'name': "svedrin", 'password': 'passwort', 'serverid': 1, 'linkacc': 'on'} ) result = self.formPost( {'pk': 1, 'name': "svedrin", 'password': 'passwort', 'serverid': 1, 'linkacc': 'on'} )
self.assertEquals( result['success'], False ) self.assertEquals( result['success'], False )
class UserMumbleUserLinkFormTestCase( ExtDirectFormTestMixin, UserAuthedTestCase ):
api_baseurl = "/mumble/forms"
formname = "MumbleUserLinkForm"
def testFormGet( self ):
# Request someone who isn't me
result = self.formGet( [{'pk': 1}] )
self.assertEquals( result['success'], False )
self.assertEquals( result['errors'][''], 'access denied' )
def testFormPostEdit( self ):
# Edit someone who isn't me
result = self.formPost( {'pk': 1, 'name': "svedrin", 'password': 'passwort', 'serverid': 1} )
self.assertEquals( result['success'], False )
self.assertEquals( result['errors'][''], 'access denied' )
def testFormPostEdit( self ):
# Try registering taken account
result = self.formPost( {'pk': -1, 'name': "svedrin", 'password': 'passwort', 'serverid': 1} )
self.assertEquals( result['success'], False )
self.assertEquals( result['errors']['name'], 'Another player already registered that name.' )
def testFormPostLinkingUser( self ):
result = self.formPost( {'pk': -1, 'name': "nichtadmin", 'password': 'nichtadmin', 'serverid': 1, 'linkacc': 'on'} )
self.assertEquals( result['success'], settings.ALLOW_ACCOUNT_LINKING )
def testFormPostLinkingAdmin( self ):
result = self.formPost( {'pk': -1, 'name': "dochadmin", 'password': 'dochadmin', 'serverid': 1, 'linkacc': 'on'} )
self.assertEquals( result['success'], (settings.ALLOW_ACCOUNT_LINKING and settings.ALLOW_ACCOUNT_LINKING_ADMINS) )
class UnauthedFormLoading(TestCase): class UnauthedFormLoading(TestCase):
""" Makes unauthorized requests to forms which require auth, and checks """ Makes unauthorized requests to forms which require auth, and checks

Loading…
Cancel
Save