from tests import base


def setUpModule():
    base.enabledPlugins.append('autojoin')
    base.startServer()


def tearDownModule():
    base.stopServer()


class AutoJoinTest(base.TestCase):

    def setUp(self):
        base.TestCase.setUp(self)

@@ -1,8 +1,48 @@
+from girder.constants import AccessType%0A
 from tes
@@ -56,16 +56,28 @@
 rt base%0A
+import json%0A
 %0A%0Adef se
@@ -260,16 +260,16 @@
 (self):%0A
-
         
@@ -294,8 +294,2246 @@
 p(self)%0A
+%0A        self.users = %5Bself.model('user').createUser(%0A            'usr%25s' %25 num, 'passwd', 'tst', 'usr', 'u%25s@u.com' %25 num)%0A            for num in %5B0, 1%5D%5D%0A%0A    def testCuration(self):%0A        admin, user = self.users%0A%0A        # create some groups%0A        g1 = self.model('group').createGroup('g1', admin)%0A        g2 = self.model('group').createGroup('g2', admin)%0A        g3 = self.model('group').createGroup('g3', admin)%0A%0A        # set auto join rules%0A        rules = %5B%0A            %7B%0A                'pattern': '@kitware.com',%0A                'groupId': str(g1%5B'_id'%5D),%0A                'level': AccessType.ADMIN%0A            %7D,%0A            %7B%0A                'pattern': '@example.com',%0A                'groupId': str(g2%5B'_id'%5D),%0A                'level': AccessType.READ%0A            %7D,%0A            %7B%0A                'pattern': '@example.com',%0A                'groupId': str(g3%5B'_id'%5D),%0A                'level': AccessType.WRITE%0A            %7D,%0A        %5D%0A        params = %7B%0A            'list': json.dumps(%5B%7B'key': 'autojoin', 'value': rules%7D%5D)%0A        %7D%0A        resp = self.request(%0A            '/system/setting', user=admin, method='PUT', params=params)%0A        self.assertStatusOk(resp)%0A%0A        # create users%0A        user1 = self.model('user').createUser(%0A            'user1', 'password', 'John', 'Doe', 'user1@example.com')%0A        user2 = self.model('user').createUser(%0A            'user2', 'password', 'John', 'Doe', 'user2@kitware.com')%0A        user3 = self.model('user').createUser(%0A            'user3', 'password', 'John', 'Doe', 'user3@kitware.co')%0A%0A        # check correct groups were joined%0A        self.assertEqual(user1%5B'groups'%5D, %5Bg2%5B'_id'%5D, g3%5B'_id'%5D%5D)%0A        self.assertEqual(user2%5B'groups'%5D, %5Bg1%5B'_id'%5D%5D)%0A        self.assertEqual(user3%5B'groups'%5D, %5B%5D)%0A%0A        # check correct access levels%0A        g1 = self.model('group').load(g1%5B'_id'%5D, force=True)%0A        g2 = self.model('group').load(g2%5B'_id'%5D, force=True)%0A        g3 = self.model('group').load(g3%5B'_id'%5D, force=True)%0A        self.assertTrue(%0A            %7Bu'id': user2%5B'_id'%5D, u'level': AccessType.ADMIN%7D in%0A            g1%5B'access'%5D%5B'users'%5D)%0A        self.assertTrue(%0A            %7Bu'id': user1%5B'_id'%5D, u'level': AccessType.WRITE%7D in%0A            g3%5B'access'%5D%5B'users'%5D)%0A

Add server tests for auto join plugin