예제 #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)