Exemplo n.º 1
0
    def test_notifiying_to_receiver_and_all_groups(self):
        self.assertEqual(0, StackedMailEntry.objects.all().count())

        ViewNotifications.create_notification_email('[email protected]', 'title1',
                                                    'content1',
                                                    ['admin', 'Group1'])

        self.assertEqual(3, StackedMailEntry.objects.all().count())
        self.assertEqual(
            1,
            StackedMailEntry.objects.filter(sender='*****@*****.**',
                                            receiver='[email protected]',
                                            title='title1',
                                            content='content1').count())
        self.assertEqual(
            1,
            StackedMailEntry.objects.filter(sender='*****@*****.**',
                                            receiver='*****@*****.**',
                                            title='title1',
                                            content='content1').count())
        self.assertEqual(
            1,
            StackedMailEntry.objects.filter(sender='*****@*****.**',
                                            receiver='*****@*****.**',
                                            title='title1',
                                            content='content1').count())
Exemplo n.º 2
0
    def test_notifying_on_benchmark_fluctuation_no_result(self):
        domain = 'test.com'
        max_fluctuation = 0.1

        fluc_overrides = {}
        fluc_overrides['id2'] = 0.28

        commit = {}
        commit['hash'] = '0000100001000010000100001000010000100001'
        commit['author'] = {}
        commit['author']['name'] = 'user1'
        commit['author']['email'] = '*****@*****.**'
        commit['author_date'] = 'user_date'

        worker = {}
        worker['name'] = 'worker-name-1'
        worker['operative_system'] = 'osx'

        uni_fluc = {}
        uni_fluc['id1'] = {}
        uni_fluc['id1']['parent'] = {}
        uni_fluc['id1']['parent']['has_results'] = False
        uni_fluc['id1']['parent']['fluctuation_ratio'] = 0.0
        uni_fluc['id1']['current'] = {}
        uni_fluc['id1']['current']['has_results'] = False
        uni_fluc['id1']['son'] = {}
        uni_fluc['id1']['son']['has_results'] = False
        uni_fluc['id1']['son']['fluctuation_ratio'] = 0.0

        ViewNotifications.notify_benchmark_fluctuation(28, commit, worker,
                                                       'def_1', domain,
                                                       uni_fluc)

        self.assertEqual(0, StackedMailEntry.objects.all().count())
Exemplo n.º 3
0
    def test_notifying_on_schema_failure(self):
        self.assertEqual(0, StackedMailEntry.objects.all().count())

        ViewNotifications.notify_schema_failed('[email protected]', 'message-1-1-1-1',
                                               'schema-1-1-1-1')

        self.assertEqual(2, StackedMailEntry.objects.all().count())
        self.assertEqual(
            1,
            StackedMailEntry.objects.filter(sender='*****@*****.**',
                                            receiver='[email protected]').count())
        self.assertEqual(
            1,
            StackedMailEntry.objects.filter(sender='*****@*****.**',
                                            receiver='*****@*****.**').count())
        self.assertTrue('message-1-1-1-1' in StackedMailEntry.objects.filter(
            sender='*****@*****.**',
            receiver='[email protected]').first().content)
        self.assertTrue('schema-1-1-1-1' in StackedMailEntry.objects.filter(
            sender='*****@*****.**',
            receiver='[email protected]').first().content)
        self.assertTrue('message-1-1-1-1' in StackedMailEntry.objects.filter(
            sender='*****@*****.**',
            receiver='*****@*****.**').first().content)
        self.assertTrue('schema-1-1-1-1' in StackedMailEntry.objects.filter(
            sender='*****@*****.**',
            receiver='*****@*****.**').first().content)
Exemplo n.º 4
0
    def test_notifiying_only_receiver(self):
        self.assertEqual(0, StackedMailEntry.objects.all().count())

        ViewNotifications.create_notification_email('[email protected]', 'title1',
                                                    'content1', [])

        self.assertEqual(1, StackedMailEntry.objects.all().count())
        self.assertEqual(
            1,
            StackedMailEntry.objects.filter(sender='*****@*****.**',
                                            receiver='[email protected]',
                                            title='title1',
                                            content='content1').count())
Exemplo n.º 5
0
    def test_notifying_on_command_failure(self):
        self.assertEqual(0, StackedMailEntry.objects.all().count())

        com1 = {}
        com1['command'] = 'command-1'
        com1['result'] = {}
        com1['result']['status'] = 0
        com1['result']['out'] = 'out-1'
        com1['result']['error'] = 'error-1'

        com2 = {}
        com2['command'] = 'command-2'
        com2['result'] = {}
        com2['result']['status'] = -1
        com2['result']['out'] = 'out-2'
        com2['result']['error'] = 'error-2'

        report_json = {}
        report_json['command_set'] = []
        report_json['command_set'].append(com1)
        report_json['command_set'].append(com2)

        ViewNotifications.notify_benchmark_command_failure(
            28, '[email protected]', '0000100001000010000100001000010000100001',
            report_json, 'test.com')

        self.assertEqual(2, StackedMailEntry.objects.all().count())
        self.assertEqual(
            1,
            StackedMailEntry.objects.filter(sender='*****@*****.**',
                                            receiver='[email protected]').count())
        self.assertEqual(
            1,
            StackedMailEntry.objects.filter(sender='*****@*****.**',
                                            receiver='*****@*****.**').count())
        self.assertTrue(
            'http://test.com/main/execution/28/complete/' in
            StackedMailEntry.objects.filter(sender='*****@*****.**',
                                            receiver='[email protected]').first().content)
        self.assertTrue('command-1' in StackedMailEntry.objects.filter(
            sender='*****@*****.**',
            receiver='[email protected]').first().content)
        self.assertFalse('out-1' in StackedMailEntry.objects.filter(
            sender='*****@*****.**',
            receiver='[email protected]').first().content)
        self.assertFalse('error-1' in StackedMailEntry.objects.filter(
            sender='*****@*****.**',
            receiver='[email protected]').first().content)
        self.assertTrue('command-2' in StackedMailEntry.objects.filter(
            sender='*****@*****.**',
            receiver='[email protected]').first().content)
        self.assertTrue('out-2' in StackedMailEntry.objects.filter(
            sender='*****@*****.**',
            receiver='[email protected]').first().content)
        self.assertTrue('error-2' in StackedMailEntry.objects.filter(
            sender='*****@*****.**',
            receiver='[email protected]').first().content)

        self.assertTrue(
            'http://test.com/main/execution/28/complete/' in StackedMailEntry.
            objects.filter(sender='*****@*****.**',
                           receiver='*****@*****.**').first().content)
        self.assertTrue('command-1' in StackedMailEntry.objects.filter(
            sender='*****@*****.**',
            receiver='*****@*****.**').first().content)
        self.assertFalse('out-1' in StackedMailEntry.objects.filter(
            sender='*****@*****.**',
            receiver='*****@*****.**').first().content)
        self.assertFalse('error-1' in StackedMailEntry.objects.filter(
            sender='*****@*****.**',
            receiver='*****@*****.**').first().content)
        self.assertTrue('command-2' in StackedMailEntry.objects.filter(
            sender='*****@*****.**',
            receiver='*****@*****.**').first().content)
        self.assertTrue('out-2' in StackedMailEntry.objects.filter(
            sender='*****@*****.**',
            receiver='*****@*****.**').first().content)
        self.assertTrue('error-2' in StackedMailEntry.objects.filter(
            sender='*****@*****.**',
            receiver='*****@*****.**').first().content)
Exemplo n.º 6
0
    def test_notifying_on_benchmark_fluctuation_current_result_and_parent_and_son_fluctuation(
            self):
        domain = 'test.com'
        max_fluctuation = 0.1

        fluc_overrides = {}
        fluc_overrides['id2'] = 0.28

        commit = {}
        commit['hash'] = '0000100001000010000100001000010000100001'
        commit['author'] = {}
        commit['author']['name'] = 'user1'
        commit['author']['email'] = '*****@*****.**'
        commit['author_date'] = 'user_date'

        worker = {}
        worker['name'] = 'worker-name-1'
        worker['operative_system'] = 'osx'

        uni_fluc = {}
        uni_fluc['id1'] = {}
        uni_fluc['id1']['parent'] = {}
        uni_fluc['id1']['parent']['has_results'] = True
        uni_fluc['id1']['parent'][
            'commit_hash'] = '0000000000000000000000000000000000000000'
        uni_fluc['id1']['parent']['fluctuation_ratio'] = -0.5
        uni_fluc['id1']['parent']['median'] = 0.5
        uni_fluc['id1']['current'] = {}
        uni_fluc['id1']['current'][
            'commit_hash'] = '0000100001000010000100001000010000100001'
        uni_fluc['id1']['current']['has_results'] = True
        uni_fluc['id1']['current']['median'] = 1.0
        uni_fluc['id1']['son'] = {}
        uni_fluc['id1']['son']['has_results'] = True
        uni_fluc['id1']['son'][
            'commit_hash'] = '0000200002000020000200002000020000200002'
        uni_fluc['id1']['son']['fluctuation_ratio'] = 0.5
        uni_fluc['id1']['son']['median'] = 1.5

        ViewNotifications.notify_benchmark_fluctuation(28, commit, worker,
                                                       'def_1', domain,
                                                       uni_fluc)

        self.assertEqual(2, StackedMailEntry.objects.all().count())
        self.assertEqual(
            1,
            StackedMailEntry.objects.filter(receiver='*****@*****.**').count())
        self.assertEqual(
            1,
            StackedMailEntry.objects.filter(receiver='*****@*****.**').count())

        content1 = StackedMailEntry.objects.filter(
            receiver='*****@*****.**').first().content
        content2 = StackedMailEntry.objects.filter(
            receiver='*****@*****.**').first().content
        self.assertEqual(content1, content2)

        email = StackedMailEntry.objects.all().first()

        self.assertTrue('Commit Hash: 0000100001000010000100001000010000100001'
                        in email.content)
        self.assertTrue('Commit Author: user1' in email.content)
        self.assertTrue('Commit Author Email: [email protected]' in email.content)
        self.assertTrue('Worker Name: worker-name-1' in email.content)
        self.assertTrue('Worker Operative System: osx' in email.content)
        self.assertTrue('Benchmark Definition Name: def_1' in email.content)
        self.assertTrue('Parent commit: 0000000' in email.content)
        self.assertTrue('Parent median result: 0.5' in email.content)
        self.assertTrue(
            'Parent fluctuation vs Current commit: -50.0%' in email.content)
        self.assertTrue('Current commit: 0000100' in email.content)
        self.assertTrue('Current median result: 1.0' in email.content)
        self.assertTrue('Son commit: 0000200' in email.content)
        self.assertTrue('Son median result: 1.5' in email.content)
        self.assertTrue(
            'Son fluctuation vs Current commit: 50.0%' in email.content)
        self.assertTrue(
            'http://test.com/main/execution/28/window/' in email.content)
def save_benchmark_execution(request, benchmark_execution_id):
    """ Check and save a benchmark execution data into the db """
    if request.method == 'POST':
        bench_exec_entry = BenchmarkExecutionEntry.objects.filter(
            id=benchmark_execution_id).first()
        if bench_exec_entry is None:
            return res.get_response(404, 'Bench Execution Entry not found', {})

        (is_json_valid, post_info) = val.validate_json_string(request.body)
        if not is_json_valid:
            ViewNotifications.notify_json_invalid(
                bench_exec_entry.commit.author.email, request.body)
            return res.get_json_parser_failed({})

        (obj_validated, val_resp_obj) = val.validate_obj_schema(
            post_info, BenchmarkExecutionSchemas.SAVE_BENCHMARK_EXECUTION)
        if not obj_validated:
            ViewNotifications.notify_schema_failed(
                bench_exec_entry.commit.author.email, post_info, val_resp_obj)
            report = create_false_report('schema_failed', val_resp_obj)
            BenchmarkExecutionController.save_bench_execution(
                bench_exec_entry, report)
            return res.get_schema_failed(val_resp_obj)

        for command in val_resp_obj['command_set']:
            (ids_correct,
             ids) = check_benchmark_json_ids(command['result']['out'])
            if not ids_correct:
                data = {'out': command['result']['out'], 'ids': ids}
                return res.get_response(400, 'Benchmark ids are not correct',
                                        data)

        report = val_resp_obj
        BenchmarkExecutionController.save_bench_execution(
            bench_exec_entry, report)
        young_to_notify = BenchmarkExecutionController.is_benchmark_young_for_notifications(
            bench_exec_entry)

        if not did_commands_succeed(report) and young_to_notify:
            ViewNotifications.notify_benchmark_command_failure(
                bench_exec_entry.id, bench_exec_entry.commit.author.email,
                bench_exec_entry.commit.commit_hash, report,
                request.get_host())

        allow_notifications = BenchmarkFluctuationWaiverEntry.objects.filter(
            git_user__id=bench_exec_entry.commit.author.id,
            notification_allowed=True).exists()

        fluctuation_exist = BenchmarkFluctuationController.does_benchmark_fluctuation_exist(
            bench_exec_entry)

        if fluctuation_exist[0] and young_to_notify and allow_notifications:
            ViewNotifications.notify_benchmark_fluctuation(
                bench_exec_entry.id, bench_exec_entry.commit.as_object(),
                bench_exec_entry.worker.as_object(),
                bench_exec_entry.definition.name, request.get_host(),
                fluctuation_exist[1])

        return res.get_response(200, 'Benchmark Execution saved', {})
    else:
        return res.get_response(400, 'Only post allowed', {})