|
| 1 | +#!/usr/bin/env python3 |
| 2 | + |
| 3 | +""" |
| 4 | +Test to verify that the Status and Created At columns have their content aligned with headers. |
| 5 | +
|
| 6 | +This test specifically validates the fix for issue #568 where the Status and Created At |
| 7 | +columns had their data swapped. |
| 8 | +""" |
| 9 | + |
| 10 | +import os |
| 11 | +import unittest |
| 12 | +from datetime import timedelta |
| 13 | +from unittest.mock import patch |
| 14 | + |
| 15 | +from classes import IssueWithMetrics |
| 16 | +from markdown_writer import get_non_hidden_columns, write_to_markdown |
| 17 | + |
| 18 | + |
| 19 | +@patch.dict( |
| 20 | + os.environ, |
| 21 | + { |
| 22 | + "SEARCH_QUERY": "is:open repo:user/repo", |
| 23 | + "GH_TOKEN": "test_token", |
| 24 | + "HIDE_CREATED_AT": "False", |
| 25 | + "HIDE_STATUS": "False", |
| 26 | + }, |
| 27 | +) |
| 28 | +class TestColumnOrderFix(unittest.TestCase): |
| 29 | + """Test that Status and Created At columns have correct data.""" |
| 30 | + |
| 31 | + def test_status_and_created_at_columns_alignment(self): |
| 32 | + """Test that Status and Created At columns show correct data values. |
| 33 | +
|
| 34 | + This test specifically validates that: |
| 35 | + 1. The Status column contains actual status values (not dates) |
| 36 | + 2. The Created At column contains actual date values (not status) |
| 37 | + """ |
| 38 | + # Create test data with clearly distinguishable Status and Created At values |
| 39 | + issues_with_metrics = [ |
| 40 | + IssueWithMetrics( |
| 41 | + title="Test Issue", |
| 42 | + html_url="https://github.com/user/repo/issues/1", |
| 43 | + author="testuser", |
| 44 | + assignee="assignee1", |
| 45 | + assignees=["assignee1"], |
| 46 | + created_at="2023-01-01T00:00:00Z", # This should appear in Created At column |
| 47 | + status="open", # This should appear in Status column |
| 48 | + time_to_first_response=timedelta(days=1), |
| 49 | + time_to_close=timedelta(days=2), |
| 50 | + time_to_answer=timedelta(days=3), |
| 51 | + ) |
| 52 | + ] |
| 53 | + |
| 54 | + # Call the function |
| 55 | + write_to_markdown( |
| 56 | + issues_with_metrics=issues_with_metrics, |
| 57 | + average_time_to_first_response=None, |
| 58 | + average_time_to_close=None, |
| 59 | + average_time_to_answer=None, |
| 60 | + average_time_in_draft=None, |
| 61 | + average_time_in_labels=None, |
| 62 | + num_issues_opened=1, |
| 63 | + num_issues_closed=0, |
| 64 | + num_mentor_count=0, |
| 65 | + labels=None, |
| 66 | + search_query="is:issue is:open repo:user/repo", |
| 67 | + hide_label_metrics=True, |
| 68 | + hide_items_closed_count=False, |
| 69 | + enable_mentor_count=False, |
| 70 | + non_mentioning_links=False, |
| 71 | + report_title="Test Report", |
| 72 | + output_file="test_column_order.md", |
| 73 | + ) |
| 74 | + |
| 75 | + # Read the generated markdown |
| 76 | + with open("test_column_order.md", "r", encoding="utf-8") as file: |
| 77 | + content = file.read() |
| 78 | + |
| 79 | + # The table should have the columns in the correct order |
| 80 | + # and the data should be properly aligned |
| 81 | + expected_header = ( |
| 82 | + "| Title | URL | Assignee | Author | Time to first response | " |
| 83 | + "Time to close | Time to answer | Created At | Status |" |
| 84 | + ) |
| 85 | + self.assertIn(expected_header, content) |
| 86 | + |
| 87 | + # Verify the data row has correct values in correct positions |
| 88 | + # The Created At column should contain the date value |
| 89 | + # The Status column should contain the status value |
| 90 | + expected_row = ( |
| 91 | + "| Test Issue | https://github.com/user/repo/issues/1 | " |
| 92 | + "[assignee1](https://github.com/assignee1) | " |
| 93 | + "[testuser](https://github.com/testuser) | 1 day, 0:00:00 | " |
| 94 | + "2 days, 0:00:00 | 3 days, 0:00:00 | 2023-01-01T00:00:00Z | open |" |
| 95 | + ) |
| 96 | + self.assertIn(expected_row, content) |
| 97 | + |
| 98 | + # Clean up |
| 99 | + os.remove("test_column_order.md") |
| 100 | + |
| 101 | + def test_get_non_hidden_columns_order(self): |
| 102 | + """Test that get_non_hidden_columns returns columns in the correct order.""" |
| 103 | + columns = get_non_hidden_columns(labels=None) |
| 104 | + |
| 105 | + # Find the indices of the Status and Created At columns |
| 106 | + try: |
| 107 | + created_at_index = columns.index("Created At") |
| 108 | + status_index = columns.index("Status") |
| 109 | + |
| 110 | + # Status should come after Created At |
| 111 | + self.assertGreater( |
| 112 | + status_index, |
| 113 | + created_at_index, |
| 114 | + "Status column should come after Created At column", |
| 115 | + ) |
| 116 | + except ValueError: |
| 117 | + # If one of the columns is hidden, that's fine, but we shouldn't get here |
| 118 | + # given our environment variables |
| 119 | + self.fail("Both Status and Created At columns should be present") |
| 120 | + |
| 121 | + |
| 122 | +if __name__ == "__main__": |
| 123 | + unittest.main() |
0 commit comments