Ejemplo n.º 1
0
    def test_stream_inversion_invert_in_first_step(self):
        client = Mock()
        client.get = Mock(side_effect=[self.get_stream1(), self.get_stream5()])

        start = datetime.datetime(2014, 3, 20)
        end = datetime.datetime(2014, 3, 21)
        step1 = FunnelStep('stream1', output_fields=['type'], invert=True)
        step2 = FunnelStep('stream5', output_fields=['type'], invert=True)
        with self.assertRaises(AssertionError):
            funnel_analyze(client, [step1, step2], start, end, end, {}, None)
Ejemplo n.º 2
0
  def test_stream_inversion_invert_and_output_fields_raises_assertion_error(self): # noqa
    client = Mock()
    client.get = Mock(side_effect=[self.get_stream1(),
                                   self.get_stream5()])

    start = datetime.datetime(2014,3,20)
    end = datetime.datetime(2014,3,21)
    step1 = FunnelStep('stream1', output_fields=['type'])
    step2 = FunnelStep('stream5', invert=True, output_fields=['type'])
    with self.assertRaises(AssertionError):
      funnel_analyze(client, [step1, step2], start, end, end, {}, None)
Ejemplo n.º 3
0
    def test_funnel(self):
        client = Mock()
        client.get = Mock(side_effect=[self.get_stream1(), self.get_stream2()])

        start = datetime.datetime(2014, 3, 20)
        end = datetime.datetime(2014, 3, 21)
        step1 = FunnelStep('stream1')
        step2 = FunnelStep('stream2')
        funnel_output = funnel_analyze(client, [step1, step2], start, end, end,
                                       {}, None)
        self.assertEqual(funnel_output.stream_sizes(), [20, 7])
Ejemplo n.º 4
0
  def test_user_id_mapping_missing(self, mock_logging):
    client = Mock()
    client.get = Mock(side_effect=[self.get_stream1(),
                                   self.get_stream4()])

    start = datetime.datetime(2014,3,20)
    end = datetime.datetime(2014,3,21)
    step1 = FunnelStep('stream1')
    step2 = FunnelStep('stream2')
    with self.assertRaisesRegexp(UnboundLocalError,
                                 ("local variable 'user' referenced before "
                                  "assignment")):
        funnel_analyze(client, [step1, step2],
                       start, end, end, {}, None)
    mock_logging.error.assert_called_with(
        'Unable to get field %s on %s from %s', 'userId',
        'stream2',
        {'username': '******',
         'type': 'a',
         '@time': datetime_to_kronos_time(datetime.datetime(2014,3,19,23,58))})
Ejemplo n.º 5
0
    def test_user_id_mapping_missing(self, mock_logging):
        client = Mock()
        client.get = Mock(side_effect=[self.get_stream1(), self.get_stream4()])

        start = datetime.datetime(2014, 3, 20)
        end = datetime.datetime(2014, 3, 21)
        step1 = FunnelStep('stream1')
        step2 = FunnelStep('stream2')
        with self.assertRaisesRegexp(
                UnboundLocalError, ("local variable 'user' referenced before "
                                    "assignment")):
            funnel_analyze(client, [step1, step2], start, end, end, {}, None)
        mock_logging.error.assert_called_with(
            'Unable to get field %s on %s from %s', 'userId', 'stream2', {
                'username':
                '******',
                'type':
                'a',
                '@time':
                datetime_to_kronos_time(datetime.datetime(2014, 3, 19, 23, 58))
            })
Ejemplo n.º 6
0
  def test_funnel(self):
    client = Mock()
    client.get = Mock(side_effect=[self.get_stream1(),
                                   self.get_stream2()])

    start = datetime.datetime(2014,3,20)
    end = datetime.datetime(2014,3,21)
    step1 = FunnelStep('stream1')
    step2 = FunnelStep('stream2')
    funnel_output = funnel_analyze(client, [step1, step2],
                                  start, end,
                                  end, {}, None)
    self.assertEqual(funnel_output.stream_sizes(), [20, 7])
Ejemplo n.º 7
0
    def test_stream_inversion(self):
        client = Mock()
        client.get = Mock(side_effect=[self.get_stream1(), self.get_stream5()])

        start = datetime.datetime(2014, 3, 20)
        end = datetime.datetime(2014, 3, 21)
        step1 = FunnelStep('stream1', output_fields=['type'])
        step2 = FunnelStep('stream5', invert=True)
        funnel_output = funnel_analyze(client, [step1, step2], start, end, end,
                                       {}, None)
        self.assertEqual(funnel_output.stream_sizes(), [20, 10])
        # Second funnel step should only contain odd users because of inversion.
        self.assertIn('3', funnel_output.user_ids()[1])
        self.assertIn('5', funnel_output.user_ids()[1])
Ejemplo n.º 8
0
    def test_funnel_properties(self):
        client = Mock()
        client.get = Mock(side_effect=[self.get_stream1(), self.get_stream3()])

        start = datetime.datetime(2014, 3, 20)
        end = datetime.datetime(2014, 3, 21)
        step1 = FunnelStep('stream1', output_fields=['type'])
        step2 = FunnelStep('stream2', output_fields=['type'])
        funnel_output = funnel_analyze(client, [step1, step2], start, end, end,
                                       {}, None)
        self.assertEqual(funnel_output.stream_sizes(), [20, 2])
        self.assertEqual(len(funnel_output.stream_data()[0]), 20)
        self.assertEqual(funnel_output.stream_data()[0]['0'], {'type': 'b'})
        self.assertEqual(funnel_output.stream_data()[0]['1'], {'type': 'a'})
Ejemplo n.º 9
0
    def test_funnel_properties_missing_field(self, mock_logging):
        client = Mock()
        client.get = Mock(side_effect=[self.get_stream1(), self.get_stream3()])

        start = datetime.datetime(2014, 3, 20)
        end = datetime.datetime(2014, 3, 21)
        step1 = FunnelStep('stream1', output_fields=['type'])
        step2 = FunnelStep('stream2', output_fields=['color'])
        funnel_output = funnel_analyze(client, [step1, step2], start, end, end,
                                       {}, None)
        self.assertEqual(funnel_output.stream_sizes(), [20, 2])
        self.assertEqual(funnel_output.stream_data()[1]['0'], {})
        mock_logging.warn.assert_called_with(
            'Field %s does not appear in stream %s', 'color', 'stream2')
Ejemplo n.º 10
0
  def test_funnel_properties(self):
    client = Mock()
    client.get = Mock(side_effect=[self.get_stream1(),
                                   self.get_stream3()])

    start = datetime.datetime(2014,3,20)
    end = datetime.datetime(2014,3,21)
    step1 = FunnelStep('stream1', output_fields=['type'])
    step2 = FunnelStep('stream2', output_fields=['type'])
    funnel_output = funnel_analyze(client, [step1, step2],
                                   start, end, end, {}, None)
    self.assertEqual(funnel_output.stream_sizes(), [20, 2])
    self.assertEqual(len(funnel_output.stream_data()[0]), 20)
    self.assertEqual(funnel_output.stream_data()[0]['0'], {'type': 'b'})
    self.assertEqual(funnel_output.stream_data()[0]['1'], {'type': 'a'})
Ejemplo n.º 11
0
  def test_stream_inversion(self):
    client = Mock()
    client.get = Mock(side_effect=[self.get_stream1(),
                                   self.get_stream5()])

    start = datetime.datetime(2014,3,20)
    end = datetime.datetime(2014,3,21)
    step1 = FunnelStep('stream1', output_fields=['type'])
    step2 = FunnelStep('stream5', invert=True)
    funnel_output = funnel_analyze(client, [step1, step2],
                                   start, end, end, {}, None)
    self.assertEqual(funnel_output.stream_sizes(), [20, 10])
    # Second funnel step should only contain odd users because of inversion.
    self.assertIn('3', funnel_output.user_ids()[1])
    self.assertIn('5', funnel_output.user_ids()[1])
Ejemplo n.º 12
0
  def test_funnel_properties_missing_field(self, mock_logging):
    client = Mock()
    client.get = Mock(side_effect=[self.get_stream1(),
                                   self.get_stream3()])

    start = datetime.datetime(2014,3,20)
    end = datetime.datetime(2014,3,21)
    step1 = FunnelStep('stream1', output_fields=['type'])
    step2 = FunnelStep('stream2', output_fields=['color'])
    funnel_output = funnel_analyze(client, [step1, step2],
                                   start, end, end, {}, None)
    self.assertEqual(funnel_output.stream_sizes(), [20, 2])
    self.assertEqual(funnel_output.stream_data()[1]['0'], {})
    mock_logging.warn.assert_called_with(
        'Field %s does not appear in stream %s', 'color', 'stream2')
Ejemplo n.º 13
0
    def test_user_filter(self):
        def get_odd_users(user):
            return int(user) % 2

        client = Mock()
        client.get = Mock(side_effect=[self.get_stream1(), self.get_stream3()])

        start = datetime.datetime(2014, 3, 20)
        end = datetime.datetime(2014, 3, 21)
        step1 = FunnelStep('stream1', output_fields=['type'])
        step2 = FunnelStep('stream2', output_fields=['type'])
        funnel_output = funnel_analyze(client, [step1, step2], start, end, end,
                                       {}, get_odd_users)
        self.assertEqual(funnel_output.stream_sizes(), [10, 1])
        self.assertEqual(len(funnel_output.stream_data()[0]), 10)
Ejemplo n.º 14
0
  def test_user_filter(self):
    def get_odd_users(user):
      return int(user) % 2

    client = Mock()
    client.get = Mock(side_effect=[self.get_stream1(),
                                   self.get_stream3()])

    start = datetime.datetime(2014,3,20)
    end = datetime.datetime(2014,3,21)
    step1 = FunnelStep('stream1', output_fields=['type'])
    step2 = FunnelStep('stream2', output_fields=['type'])
    funnel_output = funnel_analyze(client, [step1, step2],
                                   start, end, end, {}, get_odd_users)
    self.assertEqual(funnel_output.stream_sizes(), [10, 1])
    self.assertEqual(len(funnel_output.stream_data()[0]), 10)
Ejemplo n.º 15
0
  def test_event_filter(self):
    def get_type_a(event):
      return event['type'] == 'a'

    client = Mock()
    client.get = Mock(side_effect=[self.get_stream1(),
                                   self.get_stream3()])

    start = datetime.datetime(2014,3,20)
    end = datetime.datetime(2014,3,21)
    step1 = FunnelStep('stream1', event_filter=get_type_a,
                       output_fields=['type'])
    step2 = FunnelStep('stream2', event_filter=get_type_a,
                       output_fields=['type'])
    funnel_output = funnel_analyze(client, [step1, step2],
                                   start, end, end, {}, None)
    self.assertEqual(funnel_output.stream_sizes(), [10, 1])
    self.assertEqual(len(funnel_output.stream_data()[0]), 10)
Ejemplo n.º 16
0
  def test_user_id_mapping(self):
    client = Mock()
    client.get = Mock(side_effect=[self.get_stream1(),
                                   self.get_stream4(),
                                   self.get_stream4()])

    start = datetime.datetime(2014,3,20)
    end = datetime.datetime(2014,3,21)
    step1 = FunnelStep('stream1', output_fields=['type'])
    step2 = FunnelStep('stream2', user_field='username', output_fields=['type'])
    step3 = FunnelStep('stream3', user_field='username', output_fields=['type'])
    user_id_mappers = {'username': lambda x: x}
    funnel_output = funnel_analyze(client, [step1, step2, step3],
                                   start, end, end, user_id_mappers, None)
    self.assertEqual(funnel_output.stream_sizes(), [20, 2, 2])
    self.assertEqual(len(funnel_output.stream_data()[0]), 20)
    self.assertEqual(funnel_output.stream_data()[0]['0'], {'type': 'b'})
    self.assertEqual(funnel_output.stream_data()[0]['1'], {'type': 'a'})
Ejemplo n.º 17
0
    def test_event_filter(self):
        def get_type_a(event):
            return event['type'] == 'a'

        client = Mock()
        client.get = Mock(side_effect=[self.get_stream1(), self.get_stream3()])

        start = datetime.datetime(2014, 3, 20)
        end = datetime.datetime(2014, 3, 21)
        step1 = FunnelStep('stream1',
                           event_filter=get_type_a,
                           output_fields=['type'])
        step2 = FunnelStep('stream2',
                           event_filter=get_type_a,
                           output_fields=['type'])
        funnel_output = funnel_analyze(client, [step1, step2], start, end, end,
                                       {}, None)
        self.assertEqual(funnel_output.stream_sizes(), [10, 1])
        self.assertEqual(len(funnel_output.stream_data()[0]), 10)
Ejemplo n.º 18
0
    def test_user_id_mapping(self):
        client = Mock()
        client.get = Mock(side_effect=[
            self.get_stream1(),
            self.get_stream4(),
            self.get_stream4()
        ])

        start = datetime.datetime(2014, 3, 20)
        end = datetime.datetime(2014, 3, 21)
        step1 = FunnelStep('stream1', output_fields=['type'])
        step2 = FunnelStep('stream2',
                           user_field='username',
                           output_fields=['type'])
        step3 = FunnelStep('stream3',
                           user_field='username',
                           output_fields=['type'])
        user_id_mappers = {'username': lambda x: x}
        funnel_output = funnel_analyze(client, [step1, step2, step3], start,
                                       end, end, user_id_mappers, None)
        self.assertEqual(funnel_output.stream_sizes(), [20, 2, 2])
        self.assertEqual(len(funnel_output.stream_data()[0]), 20)
        self.assertEqual(funnel_output.stream_data()[0]['0'], {'type': 'b'})
        self.assertEqual(funnel_output.stream_data()[0]['1'], {'type': 'a'})