def test_create_report_file(self): filters = build_report_filters( field="Created", values=( dt.strftime(dt.now() - td(days=1), "%Y-%m-%dT%H:%M:%S.%f%zZ"), dt.strftime(dt.now(), "%Y-%m-%dT%H:%M:%S.%f%zZ"), ), f_type="date", exact_match=True, ) created_issues = get_issues_for_report(["Created"], filters) filters = build_report_filters( field="Resolved", values=( dt.strftime(dt.now() - td(days=1), "%Y-%m-%dT%H:%M:%S.%f%zZ"), dt.strftime(dt.now(), "%Y-%m-%dT%H:%M:%S.%f%zZ"), ), f_type="date", exact_match=True, ) resolved_issues = get_issues_for_report(["Created", "Resolved"], filters) filepath = make_report_path(filters[0]["current_value"][1]) create_report_file( created_issues=created_issues, resolved_issues=resolved_issues, filename="test_file", file_path=filepath, ) assert os.path.isfile(filepath)
def post(self, request): from_date, to_date = request.data.pop("period") date_filter = build_report_filters( **parse_field("created", (from_date, to_date)) ) filters = [] for field in request.data: filters += build_report_filters( **parse_field(field, request.data.get(field)) ) new_issues = get_issues_for_report( REPORT_FIELDS, filters + date_filter ) date_filter[0]["name"] = "Resolved" REPORT_FIELDS.insert(5, "Resolved") closed_issues = get_issues_for_report( REPORT_FIELDS, filters + date_filter ) if closed_issues.empty and new_issues.empty: return Response({}) report = make_report(new_issues, closed_issues, to_date) return Response(report)
def post(self, request): from_date, to_date = get_datetime_range(request.data.get("date")) filters = build_report_filters(field="Created", period=(from_date, to_date)) fields = [ "Project", "Key", "Status", "Priority", "Created", "Reporter", "Assignee", ] new_issues = get_issues_for_report(fields, filters) filters = build_report_filters(field="Resolved", period=(from_date, to_date)) fields.insert(5, "Resolved") closed_issues = get_issues_for_report(fields, filters) report = make_report(new_issues, closed_issues, from_date) return Response(report)
def test_write_report_dataframe(self): filters = build_report_filters( field="Created", values=( dt.strftime(dt.now() - td(days=1), "%Y-%m-%dT%H:%M:%S.%f%zZ"), dt.strftime(dt.now(), "%Y-%m-%dT%H:%M:%S.%f%zZ"), ), f_type="date", exact_match=True, ) issues = get_issues_for_report(["Created"], filters) filepath = make_report_path(filters[0]["current_value"][1]) filename = "test_file" with ExcelWriter(filepath, engine="xlsxwriter") as writer: if not writer.book.get_worksheet_by_name(filename): sheet = writer.book.add_worksheet(filename) writer.sheets.update({filename: sheet}) text_style = writer.book.add_format() row = write_report_dataframe( df=issues, writer=writer, sheet_name=filename, header="Test", text_style=text_style, row_number=0, ) assert row == 23
def test_get_issues_report(self): filters = build_report_filters(field="Created", values=(), f_type="date", exact_match=True) issues = get_issues_for_report(self.report_fields, filters) assert len(issues) == 100
def test_get_issues_report_for_certain_period(self): filters = build_report_filters( field="Created", values=( dt.strftime(dt.now() - td(days=1), "%Y-%m-%dT%H:%M:%S.%f%zZ"), dt.strftime(dt.now(), "%Y-%m-%dT%H:%M:%S.%f%zZ"), ), f_type="date", exact_match=True, ) issues = get_issues_for_report(self.report_fields, filters) assert len(issues) == 20
def test_build_report_filters_resolved(self): filters = build_report_filters( field="Resolved", values=("01-12-1980", "31-12-1980"), f_type="date", exact_match=True, ) assert filters == [{ "name": "Resolved", "filtration_type": "date", "current_value": ("01-12-1980", "31-12-1980"), "exact_match": True, }]
def test_build_report_filters_created(self): filters = build_report_filters( field="Created", values=("01-01-2000", "30-01-2000"), f_type="date", exact_match=True, ) assert filters == [{ "name": "Created", "filtration_type": "date", "current_value": ("01-01-2000", "30-01-2000"), "exact_match": True, }]