Exemplo n.º 1
0
 def test_process_response_special_processor(self):
     "special handling of results may be necessary for specific time frames"
     frame = {'id': '1', 'prefix': '/events'}
     fixture = json.load(
         open(
             os.path.join(self.fixture_dir,
                          'ga-response-events-frame2.json'), 'r'))
     with patch('metrics.event_type.results_processor_frame_1') as mock:
         logic.process_response(models.EVENT, frame, fixture)
         self.assertTrue(mock.called)
Exemplo n.º 2
0
    def test_process_response_generic_processor(self):
        "response is processed predictably, views are ints, dates are dates, results retain their order, etc"
        frame = {'id': '2', 'prefix': '/events'}
        fixture = json.load(
            open(
                os.path.join(self.fixture_dir,
                             'ga-response-events-frame2.json'), 'r'))

        processed_results = logic.process_response(models.EVENT, frame,
                                                   fixture)

        # list index, expected row
        expected = [(10, {
            'views': 7,
            'identifier': '',
            'date': date(2018, 1, 16)
        }),
                    (54, {
                        'identifier': '843d8750',
                        'views': 247,
                        'date': date(2018, 1, 12)
                    }),
                    (57, {
                        'views': 446,
                        'identifier': '843d8750',
                        'date': date(2018, 1, 15)
                    }),
                    (121, {
                        'views': 2,
                        'identifier': 'c40798c3',
                        'date': date(2018, 1, 11)
                    })]
        for idx, expected_row in expected:
            self.assertEqual(expected_row, processed_results[idx])
Exemplo n.º 3
0
 def setUp(self):
     # populate db
     fixture = json.load(
         open(
             os.path.join(self.fixture_dir,
                          'ga-response-events-frame2.json'), 'r'))
     frame = {'id': '2', 'prefix': '/events'}
     rows = logic.aggregate(
         logic.process_response(models.EVENT, frame, fixture))
     logic.update_page_counts(models.EVENT, rows)
     self.c = Client()
Exemplo n.º 4
0
 def test_process_response_no_results(self):
     "a response with no results issues a warning but otherwise doesn't break"
     frame = {'id': '2', 'prefix': '/events'}
     fixture = json.load(
         open(
             os.path.join(self.fixture_dir,
                          'ga-response-events-frame2.json'), 'r'))
     del fixture['rows']
     with patch('metrics.logic.LOG') as mock:
         processed_results = logic.process_response(models.EVENT, frame,
                                                    fixture)
         self.assertEqual(mock.warn.call_count, 1)
         expected_results = []
         self.assertEqual(processed_results, expected_results)
Exemplo n.º 5
0
    def test_process_response_bad_apples(self):
        "bad rows in response are discarded"
        frame = {'id': '2', 'prefix': '/events'}
        fixture = json.load(
            open(
                os.path.join(self.fixture_dir,
                             'ga-response-events-frame2.json'), 'r'))

        apple1 = 1
        fixture['rows'][apple1] = [
            None, None, None
        ]  # it's a triple but quite useless (ValueError)
        apple2 = 7
        fixture['rows'][
            apple2] = 'how you like dem apples?'  # unhandled (BaseException)

        with patch('metrics.logic.LOG') as mock:
            processed_results = logic.process_response(models.EVENT, frame,
                                                       fixture)  # kaboom
            expected_results = 147 - 2  # total non-aggregated results minus bad apples
            self.assertEqual(len(processed_results), expected_results)
            self.assertEqual(mock.exception.call_count,
                             1)  # one unhandled error
            self.assertEqual(mock.info.call_count, 1)  # one handled error