# Path: django_performance_testing/management/commands/djpt_worst_report.py
# class Command(BaseCommand):
#     help = """
#     DJPT command to print the worst performing items based on the
#     vailable collectors
#     """
# 
#     def handle(self, *args, **kwargs):
#         self.report = WorstReport()
#         datafile_path = get_datafile_path()
#         reader = Reader(datafile_path)
#         reader.read_all()
#         self.report.render(self.stdout)
# 
# Path: django_performance_testing/signals.py



from django.contrib.auth.models import Group
from django.utils import six
from django_performance_testing.management.commands.djpt_worst_report \
    import Command as WorstReportCommand
from django_performance_testing.signals import results_collected
from testapp.test_helpers import WithId, run_testcases_with_django_runner
import pytest
import unittest


def test_after_running_django_testcases_report_is_printed(packaged_runner):
    whatever = get_report_value_for(packaged_runner(), 'whatever', '')
    assert whatever.value == 2
    assert whatever.context == {'test': 'two'}


def test_has_worst_test_method_in_the_report(packaged_runner):
    report_data = get_report_data(packaged_runner())
    assert 'test method' in report_data


def get_report_value_for(test_run, heading, item_name):
    report_data = get_report_data(test_run)
    assert heading in list(report_data.keys())
    return report_data[heading]['type name'][item_name]


def get_report_data(test_run):
    cmd = get_command_after_run()
    return cmd.report.data


def get_report_text():
    cmd = get_command_after_run()
    return cmd.stdout.getvalue()


def get_command_after_run():

# Path: django_performance_testing/management/commands/djpt_worst_report.py
# class Command(BaseCommand):
#     help = """
#     DJPT command to print the worst performing items based on the
#     vailable collectors
#     """
# 
#     def handle(self, *args, **kwargs):
#         self.report = WorstReport()
#         datafile_path = get_datafile_path()
#         reader = Reader(datafile_path)
#         reader.read_all()
#         self.report.render(self.stdout)
# 
# Path: django_performance_testing/signals.py



# Path: tests/testapp/tests/test_worst_report_integrates_with_django_testrunner.py
from django.contrib.auth.models import Group
from django.utils import six
from django_performance_testing.management.commands.djpt_worst_report \
    import Command as WorstReportCommand
from django_performance_testing.signals import results_collected
from testapp.test_helpers import WithId, run_testcases_with_django_runner
import pytest
import unittest



def test_after_running_django_testcases_report_is_printed(packaged_runner):
    whatever = get_report_value_for(packaged_runner(), 'whatever', '')
    assert whatever.value == 2
    assert whatever.context == {'test': 'two'}


def test_has_worst_test_method_in_the_report(packaged_runner):
    report_data = get_report_data(packaged_runner())
    assert 'test method' in report_data


def get_report_value_for(test_run, heading, item_name):
    report_data = get_report_data(test_run)
    assert heading in list(report_data.keys())
    return report_data[heading]['type name'][item_name]


def get_report_data(test_run):
    cmd = get_command_after_run()
    return cmd.report.data


def get_report_text():
    cmd = get_command_after_run()
    return cmd.stdout.getvalue()


def get_command_after_run():

    cmd = WorstReportCommand(stdout=six.StringIO())