def test_code(self):
        """
            It should include code
        """
        config = Configuration()
        line = inspect.currentframe().f_lineno + 1
        notification = Notification(Exception("oops"), config, {})

        payload = json.loads(notification._payload())

        code = payload['events'][0]['exceptions'][0]['stacktrace'][0]['code']
        lvl = "        "
        self.assertEqual(code[str(line - 3)], lvl + "\"\"\"")
        self.assertEqual(code[str(line - 2)], lvl + "config = Configuration()")
        self.assertEqual(code[str(line - 1)],
                         lvl + "line = inspect.currentframe().f_lineno + 1")
        self.assertEqual(
            code[str(line)],
            lvl +
            "notification = Notification(Exception(\"oops\"), config, {})"
            )
        self.assertEqual(code[str(line + 1)], "")
        self.assertEqual(code[str(line + 2)],
                         lvl + "payload = json.loads(notification._payload())")
        self.assertEqual(code[str(line + 3)], "")
def test_code_turned_off():
    config = Configuration()
    config.send_code = False
    notification = Notification(Exception("oops"), config, {}, traceback=fixtures.end_of_file[2])

    payload = notification._payload()


    code = payload['events'][0]['exceptions'][0]['stacktrace'][0]['code']
    assert(None == code)
def test_code_at_end_of_file():

    config = Configuration()
    line = inspect.currentframe().f_lineno + 1
    notification = Notification(fixtures.end_of_file[1], config, {}, traceback=fixtures.end_of_file[2])

    payload = notification._payload()

    code = payload['events'][0]['exceptions'][0]['stacktrace'][0]['code']
    assert({5: '# 5', 6: '# 6', 7: '# 7', 8: '# 8', 9: 'try:', 10: '    import sys; raise Exception("end")', 11: 'except Exception: end_of_file = sys.exc_info()'} == code)
    def test_code_turned_off(self):
        config = Configuration()
        config.send_code = False
        notification = Notification(Exception("oops"), config, {},
                                    traceback=fixtures.end_of_file[2])

        payload = json.loads(notification._payload())

        code = payload['events'][0]['exceptions'][0]['stacktrace'][0]['code']
        self.assertEqual(code, None)
Example #5
0
    def test_default_app_type(self):
        """
        app_type is None by default
        """
        config = Configuration()
        notification = Notification(Exception("oops"), config, {})
        payload = json.loads(notification._payload())
        app = payload['events'][0]['app']

        assert app['type'] is None
Example #6
0
def test_code_turned_off():
    config = Configuration()
    config.send_code = False
    notification = Notification(Exception("oops"),
                                config, {},
                                traceback=fixtures.end_of_file[2])

    payload = notification._payload()

    code = payload['events'][0]['exceptions'][0]['stacktrace'][0]['code']
    assert (None == code)
Example #7
0
    def test_configured_app_type(self):
        """
        It should include app type if specified
        """
        config = Configuration()
        config.configure(app_type='rq')
        notification = Notification(Exception("oops"), config, {})
        payload = json.loads(notification._payload())
        app = payload['events'][0]['app']

        assert app['type'] == 'rq'
def test_sanitize():
    """
        It should sanitize request data
    """
    config = Configuration()
    notification = Notification(Exception("oops"), config, {}, request={"params":{"password":"******"}})

    notification.add_tab("request", {"arguments":{"password":"******"}})

    payload = notification._payload()

    assert(payload['events'][0]['metaData']['request']['arguments']['password'] == '[FILTERED]')
    assert(payload['events'][0]['metaData']['request']['params']['password'] == '[FILTERED]')
Example #9
0
    def test_device_data(self):
        """
            It should include device data
        """
        config = Configuration()
        config.hostname = 'test_host_name'
        config.runtime_versions = {'python': '9.9.9'}
        notification = Notification(Exception("oops"), config, {})

        payload = json.loads(notification._payload())

        device = payload['events'][0]['device']
        self.assertEqual('test_host_name', device['hostname'])
        self.assertEqual('9.9.9', device['runtimeVersions']['python'])
    def test_sanitize(self):
        """
            It should sanitize request data
        """
        config = Configuration()
        notification = Notification(Exception("oops"), config, {},
                                    request={"params": {"password": "******"}})

        notification.add_tab("request", {"arguments": {"password": "******"}})

        payload = json.loads(notification._payload())
        request = payload['events'][0]['metaData']['request']
        self.assertEqual(request['arguments']['password'], '[FILTERED]')
        self.assertEqual(request['params']['password'], '[FILTERED]')
    def test_code_at_end_of_file(self):

        config = Configuration()
        notification = Notification(fixtures.end_of_file[1], config, {},
                                    traceback=fixtures.end_of_file[2])

        payload = notification._payload()

        code = payload['events'][0]['exceptions'][0]['stacktrace'][0]['code']
        self.assertEqual({6:  '# 5',
             7:  '# 6',
             8:  '# 7',
             9:  '# 8',
             10: 'try:',
             11: '    import sys; raise Exception("end")',
             12: 'except Exception: end_of_file = sys.exc_info()'}, code)
Example #12
0
    def test_code_at_end_of_file(self):

        config = Configuration()
        notification = Notification(fixtures.end_of_file[1], config, {},
                                    traceback=fixtures.end_of_file[2])

        payload = json.loads(notification._payload())

        code = payload['events'][0]['exceptions'][0]['stacktrace'][0]['code']
        self.assertEqual({'6':  '# 5',
             '7':  '# 6',
             '8':  '# 7',
             '9':  '# 8',
             '10': 'try:',
             '11': '    import sys; raise Exception("end")',
             '12': 'except Exception: end_of_file = sys.exc_info()'}, code)
Example #13
0
    def test_code_at_start_of_file(self):

        config = Configuration()
        notification = Notification(fixtures.start_of_file[1], config, {},
                                    traceback=fixtures.start_of_file[2])

        payload = json.loads(notification._payload())

        code = payload['events'][0]['exceptions'][0]['stacktrace'][0]['code']
        self.assertEqual({'1': '# flake8: noqa',
             '2': 'try:',
             '3': '    import sys; raise Exception("start")',
             '4': 'except Exception: start_of_file = sys.exc_info()',
             '5': '# 4',
             '6': '# 5',
             '7': '# 6'}, code)
    def test_code_at_end_of_file(self):

        config = Configuration()
        notification = Notification(fixtures.end_of_file[1], config, {},
                                    traceback=fixtures.end_of_file[2])

        payload = json.loads(notification._payload())

        code = payload['events'][0]['exceptions'][0]['stacktrace'][0]['code']
        self.assertEqual(
            {'6':  '# 5',
             '7':  '# 6',
             '8':  '# 7',
             '9':  '# 8',
             '10': 'try:',
             '11': '    import sys; raise Exception("end")',
             '12': 'except Exception: end_of_file = sys.exc_info()'}, code)
    def test_code_at_start_of_file(self):

        config = Configuration()
        notification = Notification(fixtures.start_of_file[1], config, {},
                                    traceback=fixtures.start_of_file[2])

        payload = json.loads(notification._payload())

        code = payload['events'][0]['exceptions'][0]['stacktrace'][0]['code']
        self.assertEqual(
            {'1': '# flake8: noqa',
             '2': 'try:',
             '3': '    import sys; raise Exception("start")',
             '4': 'except Exception: start_of_file = sys.exc_info()',
             '5': '# 4',
             '6': '# 5',
             '7': '# 6'}, code)
Example #16
0
def test_code():
    """
        It should include code
    """
    config = Configuration()
    line = inspect.currentframe().f_lineno + 1
    notification = Notification(Exception("oops"), config, {})

    payload = notification._payload()

    code = payload['events'][0]['exceptions'][0]['stacktrace'][0]['code']

    assert(code[line - 3] == "    \"\"\"")
    assert(code[line - 2] == "    config = Configuration()")
    assert(code[line - 1] == "    line = inspect.currentframe().f_lineno + 1")
    assert(code[line + 0] == "    notification = Notification(Exception(\"oops\"), config, {})" )
    assert(code[line + 1] == "")
    assert(code[line + 2] == "    payload = notification._payload()")
    assert(code[line + 3] == "")
Example #17
0
def test_sanitize():
    """
        It should sanitize request data
    """
    config = Configuration()
    notification = Notification(Exception("oops"),
                                config, {},
                                request={"params": {
                                    "password": "******"
                                }})

    notification.add_tab("request", {"arguments": {"password": "******"}})

    payload = notification._payload()

    assert (payload['events'][0]['metaData']['request']['arguments']
            ['password'] == '[FILTERED]')
    assert (payload['events'][0]['metaData']['request']['params']['password']
            == '[FILTERED]')
Example #18
0
def test_code():
    """
        It should include code
    """
    config = Configuration()
    line = inspect.currentframe().f_lineno + 1
    notification = Notification(Exception("oops"), config, {})

    payload = notification._payload()

    code = payload['events'][0]['exceptions'][0]['stacktrace'][0]['code']

    assert (code[line - 3] == "    \"\"\"")
    assert (code[line - 2] == "    config = Configuration()")
    assert (code[line - 1] == "    line = inspect.currentframe().f_lineno + 1")
    assert (code[line + 0] ==
            "    notification = Notification(Exception(\"oops\"), config, {})")
    assert (code[line + 1] == "")
    assert (code[line + 2] == "    payload = notification._payload()")
    assert (code[line + 3] == "")
Example #19
0
def test_code_at_end_of_file():

    config = Configuration()
    line = inspect.currentframe().f_lineno + 1
    notification = Notification(fixtures.end_of_file[1],
                                config, {},
                                traceback=fixtures.end_of_file[2])

    payload = notification._payload()

    code = payload['events'][0]['exceptions'][0]['stacktrace'][0]['code']
    assert ({
        5: '# 5',
        6: '# 6',
        7: '# 7',
        8: '# 8',
        9: 'try:',
        10: '    import sys; raise Exception("end")',
        11: 'except Exception: end_of_file = sys.exc_info()'
    } == code)