From: jlaine Date: Mon, 31 May 2010 15:31:14 +0000 (+0000) Subject: improve unit tests X-Git-Url: https://git.stderr.nl/gitweb?a=commitdiff_plain;h=de6f78f7a31674ccb7e7f223f3272e4970cdb757;p=matthijs%2Fupstream%2Fdjango-ldapdb.git improve unit tests git-svn-id: https://svn.bolloretelecom.eu/opensource/django-ldapdb/trunk@890 e071eeec-0327-468d-9b6a-08194a12b294 --- diff --git a/examples/tests.py b/examples/tests.py index dd3312f..6d2f8c5 100644 --- a/examples/tests.py +++ b/examples/tests.py @@ -44,23 +44,62 @@ class BaseTestCase(TestCase): cursor.connection.delete_s(dn) class GroupTestCase(BaseTestCase): - def test_create(self): + def setUp(self): + super(GroupTestCase, self).setUp() + g = LdapGroup() g.name = "foogroup" g.gid = 1000 g.usernames = ['foouser', 'baruser'] g.save() - def test_get(self): - self.test_create() + g = LdapGroup() + g.name = "bargroup" + g.gid = 1001 + g.usernames = ['zoouser', 'baruser'] + g.save() + + def test_filter(self): + qs = LdapGroup.objects.none() + self.assertEquals(len(qs), 0) + qs = LdapGroup.objects.all() + self.assertEquals(len(qs), 2) + + qs = LdapGroup.objects.filter(name='foogroup') + self.assertEquals(len(qs), 1) + + qs = LdapGroup.objects.filter(name='does_not_exist') + self.assertEquals(len(qs), 0) + + def test_get(self): g = LdapGroup.objects.get(name='foogroup') + self.assertEquals(g.dn, 'cn=foogroup,ou=groups,dc=nodomain') self.assertEquals(g.name, 'foogroup') self.assertEquals(g.gid, 1000) self.assertEquals(g.usernames, ['foouser', 'baruser']) - + + self.assertRaises(LdapGroup.DoesNotExist, LdapGroup.objects.get, name='does_not_exist') + + def test_update(self): + g = LdapGroup.objects.get(name='foogroup') + g.name = 'foogroup2' + g.save() + + # make sure DN gets updated + self.assertEquals(g.dn, 'cn=foogroup2,ou=groups,dc=nodomain') + + def test_delete(self): + g = LdapGroup.objects.get(name='foogroup') + g.delete() + + qs = LdapGroup.objects.all() + self.assertEquals(len(qs), 1) + class UserTestCase(BaseTestCase): - def test_create(self): + def setUp(self): + super(UserTestCase, self).setUp() + u = LdapUser() u.first_name = "Foo" u.last_name = "User" @@ -74,8 +113,6 @@ class UserTestCase(BaseTestCase): u.save() def test_get(self): - self.test_create() - u = LdapUser.objects.get(username='foouser') self.assertEquals(u.first_name, 'Foo') self.assertEquals(u.last_name, 'User') @@ -87,6 +124,8 @@ class UserTestCase(BaseTestCase): self.assertEquals(u.username, 'foouser') self.assertEquals(u.photo, '\xff\xd8\xff\xe0\x00\x10JFIF\x00\x01\x01\x01\x00H\x00H\x00\x00\xff\xfe\x00\x1cCreated with GIMP on a Mac\xff\xdb\x00C\x00\x05\x03\x04\x04\x04\x03\x05\x04\x04\x04\x05\x05\x05\x06\x07\x0c\x08\x07\x07\x07\x07\x0f\x0b\x0b\t\x0c\x11\x0f\x12\x12\x11\x0f\x11\x11\x13\x16\x1c\x17\x13\x14\x1a\x15\x11\x11\x18!\x18\x1a\x1d\x1d\x1f\x1f\x1f\x13\x17"$"\x1e$\x1c\x1e\x1f\x1e\xff\xdb\x00C\x01\x05\x05\x05\x07\x06\x07\x0e\x08\x08\x0e\x1e\x14\x11\x14\x1e\x1e\x1e\x1e\x1e\x1e\x1e\x1e\x1e\x1e\x1e\x1e\x1e\x1e\x1e\x1e\x1e\x1e\x1e\x1e\x1e\x1e\x1e\x1e\x1e\x1e\x1e\x1e\x1e\x1e\x1e\x1e\x1e\x1e\x1e\x1e\x1e\x1e\x1e\x1e\x1e\x1e\x1e\x1e\x1e\x1e\x1e\x1e\x1e\x1e\xff\xc0\x00\x11\x08\x00\x08\x00\x08\x03\x01"\x00\x02\x11\x01\x03\x11\x01\xff\xc4\x00\x15\x00\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x08\xff\xc4\x00\x19\x10\x00\x03\x01\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01\x02\x06\x11A\xff\xc4\x00\x14\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xff\xc4\x00\x14\x11\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xff\xda\x00\x0c\x03\x01\x00\x02\x11\x03\x11\x00?\x00\x9d\xf29wU5Q\xd6\xfd\x00\x01\xff\xd9') + self.assertRaises(LdapUser.DoesNotExist, LdapUser.objects.get, username='does_not_exist') + class AdminTestCase(BaseTestCase): fixtures = ['test_users.json']