Commits

Mikhail Korobov committed 1e2a1f3

Simple test for permissions

  • Participants
  • Parent commits 14d16e2

Comments (0)

Files changed (4)

 .settings
 
 syntax: regexp
-test_proj/_coverage/(?!noremove)
+^test_proj/_coverage/(?!noremove)
+^test_proj/testdb.sqlite$

test_proj/settings.py

 MEDIA_ROOT = os.path.join(PROJECT_PATH, 'static')
 MEDIA_URL = '/static/'
 DATABASE_ENGINE = 'sqlite3'
-DATABASE_NAME = ':memory:'
+DATABASE_NAME = 'testdb.sqlite'
 SITE_ID = 1
 
 TEMPLATE_LOADERS = (

test_proj/test_app/fixtures/initial_data.json

         "pk": 1,
         "model": "auth.user",
         "fields": {
-            "username": "user",
+            "username": "superuser",
             "first_name": "",
             "last_name": "",
-            "is_active": 1,
-            "is_superuser": 1,
-            "is_staff": 1,
+            "is_active": true,
+            "is_superuser": true,
+            "is_staff": true,
+            "last_login": "2010-04-25 17:32:13",
             "groups": [],
             "user_permissions": [],
             "password": "sha1$9efbf$da0bd72857bce1d486bd263b36482fa2fc82336d",
             "email": "example@example.com",
             "date_joined": "2009-10-30 03:17:26"
         }
+    },
+    {
+        "pk": 2,
+        "model": "auth.user",
+        "fields": {
+            "username": "staff",
+            "first_name": "",
+            "last_name": "",
+            "is_active": true,
+            "is_superuser": false,
+            "is_staff": true,
+            "last_login": "2010-04-25 17:33:01",
+            "groups": [],
+            "user_permissions": [
+                31,
+                32,
+                33
+            ],
+            "password": "sha1$a7681$6721778bb4a3aff4c7b0b47c20c72afc1adf493d",
+            "email": "",
+            "date_joined": "2010-04-25 17:33:01"
+        }
     }
 ]

test_proj/test_app/tests.py

 
 class AdminBasicTest(TestCase):
     def test_admin_loads(self):
-        self.assertTrue(self.client.login(username='user', password='123'))
+        self.assertTrue(self.client.login(username='staff', password='123'))
         res = self.client.get('/admin/')
         self.assertEqual(res.status_code, 200)
+
+    def test_permissions(self):
+        self.assertTrue(self.client.login(username='staff', password='123'))
+        res = self.client.get('/admin/')
+        self.assertContains(res, 'My models')
+        self.assertNotContains(res, 'Users')
+
+        self.assertTrue(self.client.login(username='superuser', password='123'))
+        self.assertContains(self.client.get('/admin/'), 'Users')