def test_there_is_one_channel_per_each_name_received():
    report = WorstReport()
    report.handle_results_collected(
        signal=None, sender=WithId('id'),
        results=[
            NameValueResult('one', 1), NameValueResult('two', 2)], context={})
    assert list(report.data.keys()) == ['id']
    assert get_tp_names(report, 'id') == ['one', 'two']
    assert (1, {}) == get_value_and_context(report, 'id', tp='one')
    assert (2, {}) == get_value_and_context(report, 'id', tp='two')
def test_report_printed_includes_all_needed_data():
    report = WorstReport()
    report.handle_results_collected(
        signal=None, sender=FakeSender('id 2', 'querycount'),
        results=[
            NameValueResult(name='nine', value=9)], context={'foo': 'bar'})
    report.handle_results_collected(
        signal=None, sender=FakeSender('id 1', 'querycount'),
        results=[NameValueResult(name='two', value=2)],
        context={'test': 'some.app.tests.TestCase.test_foo'})
    stream = six.StringIO()
    report.render(stream)
    assert stream.getvalue().strip() == expected_report_data
def test_has_separate_section_for_each_sender_type():
    report = WorstReport()
    report.handle_results_collected(
        signal=None, sender=FakeSender('id', 'type one'),
        results=[NameValueResult('count', 1)], context={'event': 'first'})
    report.handle_results_collected(
        signal=None, sender=FakeSender('id', 'type two'),
        results=[NameValueResult('count', 3)], context={'event': 'second'})
    assert list(report.data.keys()) == ['id']
    assert get_type_names(report, 'id') == ['type one', 'type two']
    assert (1, {'event': 'first'}) == \
        get_value_and_context(report, 'id', 'type one', 'count')
    assert (3, {'event': 'second'}) == \
        get_value_and_context(report, 'id', 'type two', 'count')
Example #4
0
 def test_when_exactly_limit_there_is_no_error(
         self, limit_cls_and_name, number):
     limit_cls, name = limit_cls_and_name
     limit_obj = limit_cls(**{name: number})
     limit_obj.handle_results(
         results=[NameValueResult(name, number)], context=None)
     assert True  # no exception raised
def test_has_separate_context_for_each_channels_worst():
    report = WorstReport()
    report.handle_results_collected(
        signal=None, sender=WithId('id'),
        results=[NameValueResult('one', 1), NameValueResult('two', 2)],
        context={'event': 'first'})
    report.handle_results_collected(
        signal=None, sender=WithId('id'),
        results=[NameValueResult('one', 3), NameValueResult('two', 1)],
        context={'event': 'second'})
    assert list(report.data.keys()) == ['id']
    assert get_tp_names(report, 'id') == ['one', 'two']
    assert (3, {'event': 'second'}) == \
        get_value_and_context(report, 'id', tp='one')
    assert (2, {'event': 'first'}) == \
        get_value_and_context(report, 'id', tp='two')
Example #6
0
 def test_when_below_the_limit_there_is_no_error(
         self, limit_cls_and_name, limit, value):
     limit_cls, name = limit_cls_and_name
     assert limit > value, 'test pre-req'
     limit_obj = limit_cls(**{name: limit})
     limit_obj.handle_results(
         results=[NameValueResult(name, value)], context=None)
     assert True  # no exception raised
Example #7
0
 def test_when_no_data_in_settings_dont_fail(self, limit_cls, settings):
     id_ = 'settings has no value for this limit'
     collector = limit_cls.collector_cls(id_=id_)  # noqa: F841
     limit = limit_cls(collector_id=id_, settings_based=True)
     settings.PERFORMANCE_LIMITS = {}
     assert limit.data == {}
     limit.handle_results(
         results=[NameValueResult('total', 1)], context={})
     assert True  # no error is raised
Example #8
0
 def test_when_above_the_limit_there_is_an_error(
         self, limit_cls_and_name, limit, value):
     limit_cls, name = limit_cls_and_name
     assert limit < value, 'test pre-req'
     limit_obj = limit_cls(**{name: limit})
     result = NameValueResult(name, value)
     with pytest.raises(LimitViolationError) as excinfo:
         limit_obj.handle_results(
             results=[result], context=None)
     assert excinfo.value.limit_obj == limit_obj
     assert excinfo.value.result == result
     assert excinfo.value.actual == str(value)
     assert not excinfo.value.context
Example #9
0
 def get_results_to_send(self):
     return [NameValueResult(name='total', value=time() - self.start)]