示例#1
0
 def test_find(self):
     ns = Namespace(name='test', database='test')
     ns.save()
     # negative case.
     a = ApiKey.find('test', 'blah')
     self.assertTrue(a is None)
     # positive case.
     a = ApiKey.create(ns)
     a.save()
     key = str(a)
     self.assertTrue(ApiKey.find('test', key) is not None)
示例#2
0
 def test_create(self):
     ns = Namespace(name='test', database='test')
     ns.save()
     # Create default, read-only.
     a = ApiKey.create(ns)
     self.assertTrue(a.has_read)
     self.assertFalse(a.has_write)
     # Create a read-writable.
     a = ApiKey.create(ns, 'rw')
     self.assertTrue(a.has_read)
     self.assertTrue(a.has_write)
示例#3
0
 def test_apikeys(self):
     ns = Namespace(name='blah', database='blah')
     ns.save()
     apikeys = []
     for _ in range(10):
         a = ApiKey.create(ns)
         a.save()
         apikeys.append(a)
     self.assertEquals(len(ns.apikeys), 10)
     self.assertEquals(set(apikeys), set(ns.apikeys))
示例#4
0
 def setUp(self):
     mongoengine.connect('test')
     Namespace.drop_collection()
     ApiKey.drop_collection()
示例#5
0
 def test_has_write(self):
     a = ApiKey()
     a.access = 'w'
     self.assertTrue(a.has_write)
     a.access = 'r'
     self.assertFalse(a.has_write)
示例#6
0
 def test_has_read(self):
     a = ApiKey()
     a.access = 'r'
     self.assertTrue(a.has_read)
     a.access = 'w'
     self.assertFalse(a.has_read)