def test_build_potential_args(self): potential_args = { 'foo': 'bar', 'baz': 'bat', } expected_args = dict(potential_args) expected_args['access_token'] = rollbar.TOKEN actor = rollbar.RollbarBase('Unittest Deploy', {}) args = actor._build_potential_args(potential_args) self.assertEquals(args, expected_args)
def test_fetch_wrapper_with_403(self): actor = rollbar.RollbarBase('Unit Test Action', {}) response_dict = {'err': 1, 'messsage': 'access token not found: xxx'} response_body = json.dumps(response_dict) http_response = httpclient.HTTPError(code=403, response=response_body) with mock.patch.object(actor, '_get_http_client') as m: m.return_value = FakeExceptionRaisingHTTPClientClass() m.return_value.response_value = http_response with self.assertRaises(exceptions.InvalidCredentials): yield actor._fetch_wrapper('http://fake.com')
def test_fetch_wrapper_with_other_failure(self): actor = rollbar.RollbarBase('Unit Test Action', {}) response_dict = {'err': 1, 'messsage': 'Something bad happened'} response_body = json.dumps(response_dict) http_response = httpclient.HTTPError(code=123, response=response_body) with mock.patch.object(actor, '_get_http_client') as m: m.return_value = FakeExceptionRaisingHTTPClientClass() m.return_value.response_value = http_response with self.assertRaises(exceptions.RecoverableActorFailure): yield actor._fetch_wrapper('http://fake.com')
def test_project(self): actor = rollbar.RollbarBase('Unit Test Action', {}) response_dict = {'err': 0, 'result': '...'} response_body = json.dumps(response_dict) http_response = httpclient.HTTPResponse( httpclient.HTTPRequest('/'), code=200, buffer=StringIO.StringIO(response_body)) with mock.patch.object(actor, '_get_http_client') as m: m.return_value = FakeHTTPClientClass() m.return_value.response_value = http_response res = yield actor._project() self.assertEquals(res, response_dict)
def test_fetch_wrapper(self): actor = rollbar.RollbarBase('Unit Test Action', {}) # Valid response test response_dict = {'status': 'sent'} response_body = json.dumps(response_dict) http_response = httpclient.HTTPResponse( httpclient.HTTPRequest('/'), code=200, buffer=StringIO.StringIO(response_body)) with mock.patch.object(actor, '_get_http_client') as m: m.return_value = FakeHTTPClientClass() m.return_value.response_value = http_response res = yield actor._fetch_wrapper('http://fake.com') self.assertEquals(res, response_dict)
def test_init_without_environment_creds(self): # Un-set the token now and make sure the init fails rollbar.TOKEN = None with self.assertRaises(exceptions.InvalidCredentials): rollbar.RollbarBase('Unittest Deploy', {})