def test_load_configuration(self): """Load configuration objects from factory.""" config = ConfigurationFactory.from_env() config = Configuration() config.from_json() print(config.github_client_id) print(config.github_client_secret) print(ConfigurationFactory.generate_secret_key())
def test_error_payload_source_line_midfile(): with mock_traceback(line_no=5) as traceback_mock: config = Configuration() payload = error_payload(dict(error_class='Exception', error_message='Test'), None, config) expected = dict(zip(range(2, 9), ["Line {}\n".format(x) for x in range(2, 9)])) eq_(traceback_mock.call_count, 1) eq_(payload['backtrace'][0]['source'], expected)
def setUp(self): import flask if flask.__version__.startswith('0.12') and PYTHON_VERSION != ( 2, 6) and PYTHON_VERSION != (2, 7) and PYTHON_VERSION < (3, 3): self.skipTest( 'Flask 0.12 requires Python 2.6, 2.7 or Python3 > 3.2') if flask.__version__.startswith('1.0') and PYTHON_VERSION != ( 2, 7) and PYTHON_VERSION < (3, 4): self.skipTest('Flask 1.0 requires Python 2.7 or Python3 > 3.3') if flask.__version__.startswith('1.1') and PYTHON_VERSION != ( 2, 7) and PYTHON_VERSION < (3, 5): self.skipTest('Flask 1.1 requires Python 2.7 or Python3 > 3.4') self.config = Configuration() self.app = flask.Flask(__name__) self.app.secret_key = 'safe' self.app.config.update({'HONEYBADGER_ENVIRONMENT': 'production_flask'}) self.plugin = FlaskPlugin() @self.app.route('/test', methods=['GET', 'POST', 'PUT']) def foo(): return 'bar'
def test_error_payload_project_root_replacement(): with mock_traceback() as traceback_mock: config = Configuration(project_root=os.path.dirname(__file__)) payload = error_payload(dict(error_class='Exception', error_message='Test'), None, config) eq_(traceback_mock.call_count, 1) ok_(payload['backtrace'][0]['file'].startswith('[PROJECT_ROOT]')) eq_(payload['backtrace'][1]['file'], '/fake/path/fake_file.py')
def test_server_payload(): config = Configuration(project_root=os.path.dirname(__file__), environment='test', hostname='test.local') payload = server_payload(config) eq_(payload['project_root'], os.path.dirname(__file__)) eq_(payload['environment_name'], 'test') eq_(payload['hostname'], 'test.local') eq_(payload['pid'], os.getpid()) assert type(payload['stats']['mem']['total']) == float assert type(payload['stats']['mem']['free']) == float
def test_connection_success(): api_key = 'badgerbadgermushroom' payload = {'test': 'payload'} config = Configuration(api_key=api_key) def test_request(request_object): eq_(request_object.get_header('X-api-key'), api_key) eq_(request_object.get_full_url(), '{}/v1/notices/'.format(config.endpoint)) eq_(request_object.data, b(json.dumps(payload))) with mock_urlopen(test_request) as request_mock: send_notice(config, payload)
def setUp(self): if PY3_2: self.skipTest( 'Flask requires Python3 > 3.2. More info at http://flask.pocoo.org/docs/0.12/python3/#requirements' ) import flask self.config = Configuration() self.app = flask.Flask(__name__) self.app.secret_key = 'safe' self.app.config.update({'HONEYBADGER_ENVIRONMENT': 'production_flask'}) self.plugin = FlaskPlugin() @self.app.route('/test', methods=['GET', 'POST', 'PUT']) def foo(): return 'bar'
def test_args_overrides_12factor(): os.environ['HONEYBADGER_ENVIRONMENT'] = 'test' c = Configuration(environment='staging') assert c.environment == 'staging'
def test_12factor_overrides_defaults(): os.environ['HONEYBADGER_ENVIRONMENT'] = 'staging' c = Configuration() assert c.environment == 'staging'
def test_error_payload_source_missing_file(_isfile): with mock_traceback(line_no=5) as traceback_mock: config = Configuration() payload = error_payload( dict(error_class='Exception', error_message='Test'), None, config) eq_(payload['source'], {})
def test_is_dev_false_for_non_dev_environments(): c = Configuration(environment='production') assert c.is_dev() == False
def test_force_report_data_not_active(): c = Configuration() assert c.force_report_data == False
def test_can_only_set_valid_options(): c = Configuration(foo='bar') print(c.foo)
def test_is_dev_true_for_dev_environments(): for env in Configuration.DEVELOPMENT_ENVIRONMENTS: c = Configuration(environment=env) assert c.is_dev()
def test_config_bool_types_are_accurate(): os.environ['HONEYBADGER_FORCE_REPORT_DATA'] = '1' c = Configuration() del os.environ['HONEYBADGER_FORCE_REPORT_DATA'] assert c.force_report_data == True
def test_config_var_types_are_accurate(): os.environ['HONEYBADGER_PARAMS_FILTERS'] = 'password,password_confirm,user_email' os.environ['HONEYBADGER_TRACE_THRESHOLD'] = '2500' c = Configuration() assert c.params_filters == ['password', 'password_confirm', 'user_email'] assert c.trace_threshold == 2500
def setUp(self): self.plugin = DjangoPlugin() self.rf = RequestFactory() self.config = Configuration() self.url = url(r'test', view, name='test_view')
def test_args_overrides_defaults(): c = Configuration(environment='staging') assert c.environment == 'staging'
def test_psutil_is_optional(): config = Configuration() with patch.dict(sys.modules, {'psutil':None}): payload = server_payload(config) eq_(payload['stats'], {})
def setUp(self): self.plugin = DjangoPlugin() self.rf = RequestFactory() self.config = Configuration() self.url = url(r'test', plain_view, name='test_view') self.default_payload = {'request': {}}
def test_config_var_types_are_accurate(): os.environ['HONEYBADGER_PARAMS_FILTERS'] = 'password,password_confirm,user_email' c = Configuration() assert c.params_filters == ['password', 'password_confirm', 'user_email']