def testLogin(self): """Makes sure that authentication works correctly for FluidDB """ db = FluidDB(TEST_INSTANCE) db.login(TEST_USER, TEST_PASSWORD) r = db('GET', ['users', TEST_USER]) # a correctly authenticated user will result in a 200 response self.assertEquals(200, r.status)
def testLoginLogout(self): """ Make sure login and logout functions set things up correctly """ db = FluidDB(TEST_INSTANCE) # start from a blank slate self.assertFalse('Authorization' in db.headers) # Login db.login(TEST_USER, TEST_PASSWORD) userpass = TEST_USER + ':' + TEST_PASSWORD auth = 'Basic ' + userpass.encode('base64').strip() self.assertEquals(db.headers['Authorization'], auth) # Logout db.logout() self.assertFalse('Authorization' in db.headers)
def testCall(self): """Makes the simplest possible request to the sandbox """ db = FluidDB(TEST_INSTANCE) r = db('GET', ['users', TEST_USER]) # expect a 200 response self.assertEquals(200, r.status) # and we get the expected payload self.assertEquals(u'%s' % TEST_USER, r.value['name'])
def testLoginLogoutOAuth2(self): """ Make sure login and logout functions set things up correctly when we use OAuth2. """ token = 'kajfjowijmssafuwoisflsjlfsoieuossfh' db = FluidDB(TEST_INSTANCE) # start from a blank slate self.assertFalse('Authorization' in db.headers) self.assertFalse('X-FluidDB-Access-Token' in db.headers) # Login db.login_oauth2(token) self.assertEquals(db.headers['Authorization'], 'oauth2') self.assertEquals(db.headers['X-FluidDB-Access-Token'], token) # Logout db.logout() self.assertFalse('Authorization' in db.headers) self.assertFalse('X-FluidDB-Access-Token' in db.headers)
def testTrailingSlashHandling(self): """ Make sure we get a complaint if the base URL for the instance of fluiddb ends with a slash. BAD: http://fluiddb.fluidinfo.com/ GOOD: http://fluiddb.fluidinfo.com Why not knock off the trailing slash..? Well, it's easy to complain but hard to second guess the caller's intention """ # Bad self.assertRaises(ValueError, FluidDB, 'http://sandbox.fluidinfo.com/') # Good self.assertTrue(FluidDB('http://sandbox.fluidinfo.com'))
def test_signals(self): """Test the logging signals """ called = [] @fom_request_sent.connect def on_req(db, request, called=called): called.append(request) @fom_response_received.connect def on_resp(db, response, called=called): called.append(response) db = FluidDB('http://sandbox.fluidinfo.com') r = db('GET', ['users', 'test']) self.assertEqual(len(called), 2)
def testGetBodyAndType(self): """ Make sure FOM is sending the right sort of thing down the wire to FluidDB """ # good # with mime-type content, content_type = _get_body_and_type('foo', 'text/plain') self.assertEquals('foo', content) self.assertEquals('text/plain', content_type) # dict -> json content, content_type = _get_body_and_type({'foo': 'bar'}, None) # returns a string representation of json self.assertTrue(isinstance(content, basestring)) self.assertEquals('application/json', content_type) # primitive types values = [ 1, 1.2, 'string', u'string', ['foo', 'bar'], (u'foo', u'bar'), True, False, None ] for val in values: content, content_type = _get_body_and_type(val, None) # returns a string representation (of json) self.assertTrue(isinstance(content, basestring)) self.assertEqual('application/vnd.fluiddb.value+json', content_type) # json body = [{'foo': 'bar'}, 1, "two"] content, content_type = _get_body_and_type(body, 'application/json') self.assertTrue(isinstance(content, basestring)) self.assertEquals('application/json', content_type) # bad # can't handle the type without a mime self.assertRaises(ValueError, _get_body_and_type, FluidDB(), None) # list or tuple contains something other than a string self.assertRaises(ValueError, _get_body_and_type, [1, 2, 3], None) # test NO_CONTENT as argument expected = None, None actual = _get_body_and_type(NO_CONTENT, None) self.assertEquals(expected, actual)
def __init__(self, base_url=BASE_URL): FluidApi.__init__(self, FluidDB(base_url))
def __init__(self, *args, **kw): FluidDB.__init__(self, *args, **kw) self.agent = client.Agent(reactor)
def __init__(self): FluidDB.__init__(self, 'http://testing') self.reqs = [] self.resps = deque() self.default_response = FakeHttpLibResponse(200, 'text/plain', 'empty')
def testDefault(self): """Ensure that init sets the instance's URL correctly """ db = FluidDB('http://sandbox.fluidinfo.com') self.assertEquals(db.base_url, 'http://sandbox.fluidinfo.com')