import pytest
from time import mktime
from sfm.routes.metrics import routes
from sfm.routes.metrics import crud
from sfm.routes.utilities.routes import random_sha
from sqlmodel import Session, select
from sfm.models import Project, WorkItem, Commit
from tests.conftest import hashed_token1, time_shift
from datetime import datetime, timedelta
from fastapi.testclient import TestClient
from sfm.utils import unix_time_seconds

# Test calc_frequency function
def test_calc_frequency(db: Session):

    day_proj = Project(
        **{
            "name": "Test Project for Daily Deploys",
            "lead_name": "<NAME>",
            "lead_email": "<EMAIL>",
            "description": "A test project for testing",
            "location": "githubville",
            "repo_url": "github.com/DoraEnterprises",
            "on_prem": False,
            "project_auth_token_hashed": hashed_token1,
        }
    )
    week_proj = Project(
        **{
            "name": "Test Project for Weekly Deploys",
            "lead_name": "<NAME>",
            "lead_email": "<EMAIL>",
            "description": "A test project for testing",
            "location": "githubville",
            "repo_url": "github.com/DoraEnterprises",
            "on_prem": False,
            "project_auth_token_hashed": hashed_token1,
        }
    )
    month_proj = Project(
        **{
            "name": "Test Project for Monthly Deploys",
            "lead_name": "<NAME>",
            "lead_email": "<EMAIL>",
            "description": "A test project for testing",
            "location": "githubville",
            "repo_url": "github.com/DoraEnterprises",
            "on_prem": False,
            "project_auth_token_hashed": hashed_token1,
        }
    )
    year_proj = Project(
        **{
            "name": "Test Project for Yearly Deploys",
            "lead_name": "<NAME>",
            "lead_email": "<EMAIL>",
            "description": "A test project for testing",
            "location": "githubville",
            "repo_url": "github.com/DoraEnterprises",
            "on_prem": False,
            "project_auth_token_hashed": hashed_token1,
        }
    )
    db.add_all([day_proj, week_proj, month_proj, year_proj])
    db.commit()
    db.refresh(day_proj)
    db.refresh(week_proj)
    db.refresh(month_proj)
    db.refresh(year_proj)

    daily_deploys = []
    weekly_deploys = []
    monthly_deploys = []
    yearly_deploys = []
    start_date = datetime.now() - timedelta(days=84)
    for day in range(0, 84):
        daily_deploys.append(
            WorkItem(
                **{
                    "category": "Deployment",
                    "start_time": None,
                    "end_time": start_date + timedelta(days=day),
                    "duration_open": None,
                    "comments": "Test description for test work item in the database",
                    "project_id": day_proj.id,
                }
            )
        )
        if (day % 3) == 0:
            weekly_deploys.append(
                WorkItem(
                    **{
                        "category": "Deployment",
                        "start_time": None,
                        "end_time": start_date + timedelta(days=day),
                        "duration_open": None,
                        "comments": "Test description for test work item in the database",
                        "project_id": week_proj.id,
                    }
                )
            )
        elif (day % 20) == 0:
            monthly_deploys.append(
                WorkItem(
                    **{
                        "category": "Deployment",
                        "start_time": None,
                        "end_time": start_date + timedelta(days=day),
                        "duration_open": None,
                        "comments": "Test description for test work item in the database",
                        "project_id": month_proj.id,
                    }
                )
            )

    yearly_deploys.append(
        WorkItem(
            **{
                "category": "Deployment",
                "start_time": None,
                "end_time": start_date,
                "duration_open": None,
                "comments": "Test description for test work item in the database",
                "project_id": year_proj.id,
            }
        )
    )

    db.add_all(daily_deploys)
    db.add_all(weekly_deploys)
    db.add_all(monthly_deploys)
    db.add_all(yearly_deploys)
    db.commit()

    assert crud.calc_frequency(day_proj.work_items) == "Daily"
    assert crud.calc_frequency(week_proj.work_items) == "Weekly"
    assert crud.calc_frequency(month_proj.work_items) == "Monthly"
    assert crud.calc_frequency(year_proj.work_items) == "Yearly"


# Test combine_deploys function
def test_combine_deploys():
    deployment_list = [
        datetime(2021, 5, 31).date(),
        datetime(2021, 5, 31).date(),
        datetime(2021, 5, 31).date(),
        datetime(2021, 6, 1).date(),
        datetime(2021, 6, 3).date(),
    ]

    result = crud.combine_deploys(deployment_list)[:4]
    print(result)
    expected_result = [
        [unix_time_seconds(datetime(2021, 5, 31).date()), 3],
        [unix_time_seconds(datetime(2021, 6, 1).date()), 1],
        [unix_time_seconds(datetime(2021, 6, 2).date()), 0],
        [unix_time_seconds(datetime(2021, 6, 3).date()), 1],
    ]
    print(expected_result)
    assert result == expected_result


# Test lead_times_per_day function
def test_lead_time_per_day():
    commit_list = [
        datetime(2021, 5, 31).date(),
        datetime(2021, 5, 31).date(),
        datetime(2021, 5, 31).date(),
        datetime(2021, 6, 1).date(),
        datetime(2021, 6, 3).date(),
    ]
    lead_time = [60, 120, 180, 240, 300]

    result = crud.lead_times_per_day(commit_list, lead_time)
    result[0] = result[0][:4]
    result[1] = result[1][:4]
    print(result)

    expected_result = [
        [
            [unix_time_seconds(datetime(2021, 5, 31).date()), 3],
            [unix_time_seconds(datetime(2021, 6, 1).date()), 1],
            [unix_time_seconds(datetime(2021, 6, 2).date()), 0],
            [unix_time_seconds(datetime(2021, 6, 3).date()), 1],
        ],
        [
            [unix_time_seconds(datetime(2021, 5, 31).date()), 2.0],
            [unix_time_seconds(datetime(2021, 6, 1).date()), 4.0],
            [unix_time_seconds(datetime(2021, 6, 2).date()), 0.0],
            [unix_time_seconds(datetime(2021, 6, 3).date()), 5.0],
        ],
    ]
    print(expected_result)
    assert result == expected_result


# Test get "/deployments" endpoint
def test_get_deployments(client: TestClient, db: Session):
    """Testing that the endpoint works as expected"""
    response = client.get("/metrics/deployments", params={"project_id": "2"})
    assert response is not None
    assert response.status_code == 200

    result = response.json()
    result["deployment_dates"] = result["deployment_dates"][:6]

    deploy_dates = [
        datetime(2021, 5, 31),  # Week 1
        datetime(2021, 6, 1),  # Week 2
        datetime(2021, 6, 2),  # Week 10
        datetime(2021, 6, 3),  # Week 11
        datetime(2021, 6, 4),
        datetime(2021, 6, 5),  # Week 12
    ]
    deploy_dates = [deploy + time_shift for deploy in deploy_dates]
    deployment_dates = [
        [unix_time_seconds(deploy_dates[0].date()), 1],  # Week 1
        [unix_time_seconds(deploy_dates[1].date()), 0],  # Week 2
        [unix_time_seconds(deploy_dates[2].date()), 0],  # Week 10
        [unix_time_seconds(deploy_dates[3].date()), 0],  # Week 11
        [unix_time_seconds(deploy_dates[4].date()), 0],
        [unix_time_seconds(deploy_dates[5].date()), 0],  # Week 12
    ]

    expected_result = {
        "project_name": "Test Project 2",
        "deployment_dates": deployment_dates,
        "performance": "Monthly",
        "deployment_dates_description": "List of lists, where each sublist consits of [unix date, number of deploys on that date]",
        "performance_description": "Elite: Multiple deploys per day, High: Between once per day and once per week, Medium: Between once per week and once per month, Low: More than once per month",
    }

    assert result == expected_result

    """Test if given project name"""
    response2 = client.get(
        "/metrics/deployments", params={"project_name": "Test Project 2"}
    )
    assert response2 is not None
    assert response2.status_code == 200

    result2 = response2.json()
    result2["deployment_dates"] = result2["deployment_dates"][:6]

    assert result2 == expected_result

    """Test if given project_id AND project_name"""
    response3 = client.get(
        "/metrics/deployments",
        params={"project_id": "2", "project_name": "Test Project 2"},
    )
    assert response3 is not None
    assert response3.status_code == 200

    result3 = response3.json()
    result3["deployment_dates"] = result3["deployment_dates"][:6]

    assert result3 == expected_result

    response4 = client.get("/metrics/deployments")
    assert response4 is not None
    assert response4.status_code == 200

    result4 = response4.json()
    result4["deployment_dates"] = result4["deployment_dates"][:6]
    print(result4)
    deployment_dates = [
        [unix_time_seconds(deploy_dates[0].date()), 2],  # Week 1
        [unix_time_seconds(deploy_dates[1].date()), 0],  # Week 2
        [unix_time_seconds(deploy_dates[2].date()), 0],  # Week 10
        [unix_time_seconds(deploy_dates[3].date()), 0],  # Week 11
        [unix_time_seconds(deploy_dates[4].date()), 0],
        [unix_time_seconds(deploy_dates[5].date()), 0],  # Week 12
    ]

    expected_result4 = {
        "project_name": "all",
        "deployment_dates": deployment_dates,
        "performance": "Daily",
        "deployment_dates_description": "List of lists, where each sublist consits of [unix date, number of deploys on that date]",
        "performance_description": "Elite: Multiple deploys per day, High: Between once per day and once per week, Medium: Between once per week and once per month, Low: More than once per month",
    }

    print(expected_result4)
    assert result4 == expected_result4

    """Testing if you set all_deployments to false"""
    # response5 = client.get("/metrics/deployments", params={"all_deployments": "false"})
    # assert response5 is not None
    # assert response5.status_code == 200

    # result5 = response5.json()
    # print(result5)
    # print(result5[:])
    # for i in range(0, len(result5)):
    #     result5[i]["deployment_dates"] = result5[i]["deployment_dates"][:6]

    # deployment_dates = [
    #     [unix_time_seconds(deploy_dates[0].date()), 1],  # Week 1
    #     [unix_time_seconds(deploy_dates[1].date()), 0],  # Week 2
    #     [unix_time_seconds(deploy_dates[2].date()), 0],  # Week 10
    #     [unix_time_seconds(deploy_dates[3].date()), 0],  # Week 11
    #     [unix_time_seconds(deploy_dates[4].date()), 0],
    #     [unix_time_seconds(deploy_dates[5].date()), 0],  # Week 12
    # ]

    # expected_result5 = [
    #     {
    #         "project_name": "Test Project 1",
    #         "deployment_dates": deployment_dates,
    #         "performance": "Daily",
    #         "deployment_dates_description": "",
    #         "performance_description": "Elite: Multiple deploys per day, High: Between once per day and once per week, Medium: Between once per week and once per month, Low: More than once per month",
    #     },
    #     {
    #         "project_name": "Test Project 2",
    #         "deployment_dates": deployment_dates,
    #         "performance": "Monthly",
    #         "deployment_dates_description": "",
    #         "performance_description": "Elite: Multiple deploys per day, High: Between once per day and once per week, Medium: Between once per week and once per month, Low: More than once per month",
    #     },
    #     {
    #         "project_name": "Test Project with no WorkItems",
    #         "deployment_dates": [],
    #         "performance": "Yearly",
    #         "deployment_dates_description": "",
    #         "performance_description": "Elite: Multiple deploys per day, High: Between once per day and once per week, Medium: Between once per week and once per month, Low: More than once per month",
    #     },
    # ]
    # print(result5)
    # assert result5 == expected_result5


# Test get "/LeadTimeToChange" endpoint
def test_get_lead_time_endpoint(client: TestClient, db: Session):
    """Test that the endpoint works as expected when no parameters are passed"""
    response = client.get("/metrics/LeadTimeToChange")
    assert response is not None
    assert response.status_code == 200
    assert response.json()["project_name"] == "all"

    day_proj = Project(
        **{
            "name": "Test Project for Commits",
            "lead_name": "<NAME>",
            "lead_email": "<EMAIL>",
            "description": "A test project for testing",
            "location": "githubville",
            "repo_url": "github.com/DoraEnterprises",
            "on_prem": False,
            "project_auth_token_hashed": hashed_token1,
        }
    )
    week_proj = Project(
        **{
            "name": "Test Project for Commits",
            "lead_name": "<NAME>",
            "lead_email": "<EMAIL>",
            "description": "A test project for testing",
            "location": "githubville",
            "repo_url": "github.com/DoraEnterprises",
            "on_prem": False,
            "project_auth_token_hashed": hashed_token1,
        }
    )
    month_proj = Project(
        **{
            "name": "Test Project for Commits",
            "lead_name": "<NAME>",
            "lead_email": "<EMAIL>",
            "description": "A test project for testing",
            "location": "githubville",
            "repo_url": "github.com/DoraEnterprises",
            "on_prem": False,
            "project_auth_token_hashed": hashed_token1,
        }
    )
    gtmonth_proj = Project(
        **{
            "name": "Test Project for Commits",
            "lead_name": "<NAME>",
            "lead_email": "<EMAIL>",
            "description": "A test project for testing",
            "location": "githubville",
            "repo_url": "github.com/DoraEnterprises",
            "on_prem": False,
            "project_auth_token_hashed": hashed_token1,
        }
    )
    db.add(day_proj)
    db.add(week_proj)
    db.add(month_proj)
    db.add(gtmonth_proj)
    db.commit()
    db.refresh(day_proj)
    db.refresh(week_proj)
    db.refresh(month_proj)
    db.refresh(gtmonth_proj)

    day_work = WorkItem(
        **{
            "category": "Pull Request",
            "end_time": datetime(2021, 6, 11),
            "project_id": day_proj.id,
        }
    )
    week_work = WorkItem(
        **{
            "category": "Pull Request",
            "end_time": datetime(2021, 6, 11),
            "project_id": week_proj.id,
        }
    )
    month_work = WorkItem(
        **{
            "category": "Pull Request",
            "end_time": datetime(2021, 6, 11),
            "project_id": month_proj.id,
        }
    )
    gtmonth_work = WorkItem(
        **{
            "category": "Pull Request",
            "end_time": datetime(2021, 6, 11),
            "project_id": gtmonth_proj.id,
        }
    )
    db.add_all([day_work, week_work, month_work, gtmonth_work])
    db.commit()
    db.refresh(day_work)
    db.refresh(week_work)
    db.refresh(month_work)
    db.refresh(gtmonth_work)

    daily_commits = []
    weekly_commits = []
    monthly_commits = []
    gtmonth_commits = []
    end_date = datetime(2021, 6, 11)
    for day in range(0, 40):
        date = end_date - timedelta(days=day)
        if day <= 1:
            daily_commits.append(
                Commit(
                    **{
                        "sha": random_sha(day),
                        "date": date,
                        "message": "Test commit message for testing commits in the database",
                        "author": "<NAME>",
                        "work_item_id": day_work.id,
                        "time_to_pull": int((day_work.end_time - date).total_seconds()),
                    }
                )
            )
        elif day > 1 and day <= 7:
            weekly_commits.append(
                Commit(
                    **{
                        "sha": random_sha(day),
                        "date": date,
                        "message": "Test commit message for testing commits in the database",
                        "author": "<NAME>",
                        "work_item_id": week_work.id,
                        "time_to_pull": int(
                            (week_work.end_time - date).total_seconds()
                        ),
                    }
                )
            )
        elif day > 7 and day <= 30:
            monthly_commits.append(
                Commit(
                    **{
                        "sha": random_sha(day),
                        "date": date,
                        "message": "Test commit message for testing commits in the database",
                        "author": "<NAME>",
                        "work_item_id": month_work.id,
                        "time_to_pull": int(
                            (month_work.end_time - date).total_seconds()
                        ),
                    }
                )
            )
    date = end_date - timedelta(days=day)
    gtmonth_commits.append(
        Commit(
            **{
                "sha": random_sha(day),
                "date": date,
                "message": "Test commit message for testing commits in the database",
                "author": "<NAME>",
                "work_item_id": gtmonth_work.id,
                "time_to_pull": int((gtmonth_work.end_time - date).total_seconds()),
            }
        )
    )

    db.add_all(daily_commits)
    db.add_all(weekly_commits)
    db.add_all(monthly_commits)
    db.add_all(gtmonth_commits)
    db.commit()

    db.refresh(day_work)
    db.refresh(week_work)
    db.refresh(month_work)
    db.refresh(gtmonth_work)

    """Test Metrics Calculate correctly"""
    day_response = client.get(
        "/metrics/LeadTimeToChange", params={"project_id": f"{day_proj.id}"}
    )
    day_result = day_response.json()
    assert day_result["performance"] == "One Day"

    week_response = client.get(
        "/metrics/LeadTimeToChange", params={"project_id": f"{week_proj.id}"}
    )
    week_result = week_response.json()
    assert week_result["performance"] == "One Week"

    month_response = client.get(
        "/metrics/LeadTimeToChange", params={"project_id": f"{month_proj.id}"}
    )
    month_result = month_response.json()
    assert month_result["performance"] == "One Month"

    gtmonth_response = client.get(
        "/metrics/LeadTimeToChange", params={"project_id": f"{gtmonth_proj.id}"}
    )
    gtmonth_result = gtmonth_response.json()
    assert gtmonth_result["performance"] == "Greater than One Month"

    """Test giving project_name returns correctly"""
    day_response = client.get(
        "/metrics/LeadTimeToChange", params={"project_name": f"{day_proj.name}"}
    )
    day_result = day_response.json()
    assert day_result["performance"] == "One Day"

    """Test giving project_name and project_id returns correctly"""
    day_response = client.get(
        "/metrics/LeadTimeToChange",
        params={"project_name": f"{day_proj.name}", "project_id": f"{day_proj.id}"},
    )
    day_result = day_response.json()
    assert day_result["performance"] == "One Day"
    assert day_result["project_name"] == day_proj.name

    """Test giving a project with no workItems raises exception"""
    with pytest.raises(Exception) as ex:
        client.get(
            "/metrics/LeadTimeToChange",
            params={"project_name": "Test Project with no WorkItems"},
        )
        assert (
            ex.value.message
            == "No pull requests to main associated with specified project"
        )

    """Test giving a project name with no matching project raises exception"""
    response = client.get(
        "/metrics/LeadTimeToChange", params={"project_name": "Gibberish"}
    )
    assert response.status_code == 404

    """Test giving a project id with no matching project raises exception """
    response = client.get("/metrics/LeadTimeToChange", params={"project_id": "7777"})
    assert response.status_code == 404

    """Test get request when no pull requests exist in database"""
    pull_requests = db.exec(
        select(WorkItem).where(WorkItem.category == "Pull Request")
    ).all()
    for item in pull_requests:
        db.delete(item)
    db.commit()

    response = client.get("/metrics/LeadTimeToChange")
    assert response.status_code == 200


def test_time_to_restore(client: TestClient, db: Session):
    """Testing that the endpoint is working as expected"""
    response = client.get("metrics/TimeToRestore")
    assert response.status_code == 200

    result = response.json()
    result["daily_times_to_restore"] = result["daily_times_to_restore"][:5]
    print(result["daily_times_to_restore"])

    assert result["project_name"] == "all"
    assert result["time_to_restore"] == float(timedelta(days=5).total_seconds() / 3600)
    assert result["performance"] == "Less than one week"
    assert result["daily_times_to_restore"] == [
        [unix_time_seconds((datetime(2021, 6, 10) + time_shift).date()), 120.0],
        [unix_time_seconds((datetime(2021, 6, 11) + time_shift).date()), 0],
        [unix_time_seconds((datetime(2021, 6, 12) + time_shift).date()), 0],
        [unix_time_seconds((datetime(2021, 6, 13) + time_shift).date()), 0],
        [unix_time_seconds((datetime(2021, 6, 14) + time_shift).date()), 0],
    ]

    response = client.get(
        "/metrics/TimeToRestore", params={"project_name": "Test Project 1"}
    )
    result2 = response.json()
    result2["daily_times_to_restore"] = result2["daily_times_to_restore"][:5]

    assert result2["project_name"] == "Test Project 1"
    assert result2["time_to_restore"] == float(timedelta(days=5).total_seconds() / 3600)
    assert result2["performance"] == "Less than one week"
    assert result2["daily_times_to_restore"] == [
        [unix_time_seconds((datetime(2021, 6, 10) + time_shift).date()), 120.0],
        [unix_time_seconds((datetime(2021, 6, 11) + time_shift).date()), 0],
        [unix_time_seconds((datetime(2021, 6, 12) + time_shift).date()), 0],
        [unix_time_seconds((datetime(2021, 6, 13) + time_shift).date()), 0],
        [unix_time_seconds((datetime(2021, 6, 14) + time_shift).date()), 0],
    ]

    response = client.get(
        "/metrics/TimeToRestore", params={"project_name": "Test Project 2"}
    )

    result3 = response.json()

    assert result3["project_name"] == "Test Project 2"
    assert result3["time_to_restore"] == -1.0
    assert (
        result3["performance"]
        == "No closed production defects exist in the last 3 months"
    )
    assert result3["daily_times_to_restore"] == []


def test_change_failure_rate(client: TestClient, db: Session):
    """Testing that the endpoint is working as expected"""
    response = client.get("/metrics/ChangeFailureRate")
    assert response.status_code == 200
    assert response.json()["project_name"] == "all"

    response = client.get("/metrics/ChangeFailureRate", params={"project_id": "1"})
    assert response.status_code == 200
    print(response.json())
    assert response.json()["daily_change_failure_rate"][:3] == [
        [unix_time_seconds((datetime(2021, 6, 3) + time_shift).date()), 1.0],
        [unix_time_seconds((datetime(2021, 6, 4) + time_shift).date()), 0],
        [unix_time_seconds((datetime(2021, 6, 5) + time_shift).date()), 0],
    ]

    assert response.json()["change_failure_rate"] == 0.5
    assert response.json()["project_name"] == "Test Project 1"
    assert (
        response.json()["change_failure_rate_description"]
        == "Number of failed deployments per total number of deployments"
    )

datetime.datetime sfm.routes.utilities.routes.random_sha sfm.routes.metrics.crud.calc_frequency datetime.datetime.now sfm.models.Project pytest.raises sfm.routes.metrics.crud.combine_deploys sfm.routes.metrics.crud.lead_times_per_day sqlmodel.select sfm.models.WorkItem datetime.timedelta
[((511, 800), 'sfm.models.Project', 'Project', ([], {}), "(**{'name': 'Test Project for Daily Deploys', 'lead_name': '<NAME>',\n    'lead_email': '<EMAIL>', 'description': 'A test project for testing',\n    'location': 'githubville', 'repo_url': 'github.com/DoraEnterprises',\n    'on_prem': False, 'project_auth_token_hashed': hashed_token1})\n", (518, 800), False, 'from sfm.models import Project, WorkItem, Commit\n'), ((926, 1216), 'sfm.models.Project', 'Project', ([], {}), "(**{'name': 'Test Project for Weekly Deploys', 'lead_name': '<NAME>',\n    'lead_email': '<EMAIL>', 'description': 'A test project for testing',\n    'location': 'githubville', 'repo_url': 'github.com/DoraEnterprises',\n    'on_prem': False, 'project_auth_token_hashed': hashed_token1})\n", (933, 1216), False, 'from sfm.models import Project, WorkItem, Commit\n'), ((1343, 1638), 'sfm.models.Project', 'Project', ([], {}), "(**{'name': 'Test Project for Monthly Deploys', 'lead_name':\n    '<NAME>', 'lead_email': '<EMAIL>', 'description':\n    'A test project for testing', 'location': 'githubville', 'repo_url':\n    'github.com/DoraEnterprises', 'on_prem': False,\n    'project_auth_token_hashed': hashed_token1})\n", (1350, 1638), False, 'from sfm.models import Project, WorkItem, Commit\n'), ((1760, 2050), 'sfm.models.Project', 'Project', ([], {}), "(**{'name': 'Test Project for Yearly Deploys', 'lead_name': '<NAME>',\n    'lead_email': '<EMAIL>', 'description': 'A test project for testing',\n    'location': 'githubville', 'repo_url': 'github.com/DoraEnterprises',\n    'on_prem': False, 'project_auth_token_hashed': hashed_token1})\n", (1767, 2050), False, 'from sfm.models import Project, WorkItem, Commit\n'), ((5815, 5862), 'sfm.routes.metrics.crud.lead_times_per_day', 'crud.lead_times_per_day', (['commit_list', 'lead_time'], {}), '(commit_list, lead_time)\n', (5838, 5862), False, 'from sfm.routes.metrics import crud\n'), ((12815, 13098), 'sfm.models.Project', 'Project', ([], {}), "(**{'name': 'Test Project for Commits', 'lead_name': '<NAME>',\n    'lead_email': '<EMAIL>', 'description': 'A test project for testing',\n    'location': 'githubville', 'repo_url': 'github.com/DoraEnterprises',\n    'on_prem': False, 'project_auth_token_hashed': hashed_token1})\n", (12822, 13098), False, 'from sfm.models import Project, WorkItem, Commit\n'), ((13224, 13507), 'sfm.models.Project', 'Project', ([], {}), "(**{'name': 'Test Project for Commits', 'lead_name': '<NAME>',\n    'lead_email': '<EMAIL>', 'description': 'A test project for testing',\n    'location': 'githubville', 'repo_url': 'github.com/DoraEnterprises',\n    'on_prem': False, 'project_auth_token_hashed': hashed_token1})\n", (13231, 13507), False, 'from sfm.models import Project, WorkItem, Commit\n'), ((13634, 13917), 'sfm.models.Project', 'Project', ([], {}), "(**{'name': 'Test Project for Commits', 'lead_name': '<NAME>',\n    'lead_email': '<EMAIL>', 'description': 'A test project for testing',\n    'location': 'githubville', 'repo_url': 'github.com/DoraEnterprises',\n    'on_prem': False, 'project_auth_token_hashed': hashed_token1})\n", (13641, 13917), False, 'from sfm.models import Project, WorkItem, Commit\n'), ((14046, 14329), 'sfm.models.Project', 'Project', ([], {}), "(**{'name': 'Test Project for Commits', 'lead_name': '<NAME>',\n    'lead_email': '<EMAIL>', 'description': 'A test project for testing',\n    'location': 'githubville', 'repo_url': 'github.com/DoraEnterprises',\n    'on_prem': False, 'project_auth_token_hashed': hashed_token1})\n", (14053, 14329), False, 'from sfm.models import Project, WorkItem, Commit\n'), ((15684, 15705), 'datetime.datetime', 'datetime', (['(2021)', '(6)', '(11)'], {}), '(2021, 6, 11)\n', (15692, 15705), False, 'from datetime import datetime, timedelta\n'), ((2455, 2469), 'datetime.datetime.now', 'datetime.now', ([], {}), '()\n', (2467, 2469), False, 'from datetime import datetime, timedelta\n'), ((2472, 2490), 'datetime.timedelta', 'timedelta', ([], {'days': '(84)'}), '(days=84)\n', (2481, 2490), False, 'from datetime import datetime, timedelta\n'), ((4044, 4256), 'sfm.models.WorkItem', 'WorkItem', ([], {}), "(**{'category': 'Deployment', 'start_time': None, 'end_time':\n    start_date, 'duration_open': None, 'comments':\n    'Test description for test work item in the database', 'project_id':\n    year_proj.id})\n", (4052, 4256), False, 'from sfm.models import Project, WorkItem, Commit\n'), ((4537, 4577), 'sfm.routes.metrics.crud.calc_frequency', 'crud.calc_frequency', (['day_proj.work_items'], {}), '(day_proj.work_items)\n', (4556, 4577), False, 'from sfm.routes.metrics import crud\n'), ((4600, 4641), 'sfm.routes.metrics.crud.calc_frequency', 'crud.calc_frequency', (['week_proj.work_items'], {}), '(week_proj.work_items)\n', (4619, 4641), False, 'from sfm.routes.metrics import crud\n'), ((4665, 4707), 'sfm.routes.metrics.crud.calc_frequency', 'crud.calc_frequency', (['month_proj.work_items'], {}), '(month_proj.work_items)\n', (4684, 4707), False, 'from sfm.routes.metrics import crud\n'), ((4732, 4773), 'sfm.routes.metrics.crud.calc_frequency', 'crud.calc_frequency', (['year_proj.work_items'], {}), '(year_proj.work_items)\n', (4751, 4773), False, 'from sfm.routes.metrics import crud\n'), ((5080, 5117), 'sfm.routes.metrics.crud.combine_deploys', 'crud.combine_deploys', (['deployment_list'], {}), '(deployment_list)\n', (5100, 5117), False, 'from sfm.routes.metrics import crud\n'), ((7031, 7052), 'datetime.datetime', 'datetime', (['(2021)', '(5)', '(31)'], {}), '(2021, 5, 31)\n', (7039, 7052), False, 'from datetime import datetime, timedelta\n'), ((7072, 7092), 'datetime.datetime', 'datetime', (['(2021)', '(6)', '(1)'], {}), '(2021, 6, 1)\n', (7080, 7092), False, 'from datetime import datetime, timedelta\n'), ((7112, 7132), 'datetime.datetime', 'datetime', (['(2021)', '(6)', '(2)'], {}), '(2021, 6, 2)\n', (7120, 7132), False, 'from datetime import datetime, timedelta\n'), ((7153, 7173), 'datetime.datetime', 'datetime', (['(2021)', '(6)', '(3)'], {}), '(2021, 6, 3)\n', (7161, 7173), False, 'from datetime import datetime, timedelta\n'), ((7194, 7214), 'datetime.datetime', 'datetime', (['(2021)', '(6)', '(4)'], {}), '(2021, 6, 4)\n', (7202, 7214), False, 'from datetime import datetime, timedelta\n'), ((7224, 7244), 'datetime.datetime', 'datetime', (['(2021)', '(6)', '(5)'], {}), '(2021, 6, 5)\n', (7232, 7244), False, 'from datetime import datetime, timedelta\n'), ((17518, 17537), 'datetime.timedelta', 'timedelta', ([], {'days': 'day'}), '(days=day)\n', (17527, 17537), False, 'from datetime import datetime, timedelta\n'), ((19814, 19838), 'pytest.raises', 'pytest.raises', (['Exception'], {}), '(Exception)\n', (19827, 19838), False, 'import pytest\n'), ((15761, 15780), 'datetime.timedelta', 'timedelta', ([], {'days': 'day'}), '(days=day)\n', (15770, 15780), False, 'from datetime import datetime, timedelta\n'), ((4880, 4901), 'datetime.datetime', 'datetime', (['(2021)', '(5)', '(31)'], {}), '(2021, 5, 31)\n', (4888, 4901), False, 'from datetime import datetime, timedelta\n'), ((4918, 4939), 'datetime.datetime', 'datetime', (['(2021)', '(5)', '(31)'], {}), '(2021, 5, 31)\n', (4926, 4939), False, 'from datetime import datetime, timedelta\n'), ((4956, 4977), 'datetime.datetime', 'datetime', (['(2021)', '(5)', '(31)'], {}), '(2021, 5, 31)\n', (4964, 4977), False, 'from datetime import datetime, timedelta\n'), ((4994, 5014), 'datetime.datetime', 'datetime', (['(2021)', '(6)', '(1)'], {}), '(2021, 6, 1)\n', (5002, 5014), False, 'from datetime import datetime, timedelta\n'), ((5031, 5051), 'datetime.datetime', 'datetime', (['(2021)', '(6)', '(3)'], {}), '(2021, 6, 3)\n', (5039, 5051), False, 'from datetime import datetime, timedelta\n'), ((5574, 5595), 'datetime.datetime', 'datetime', (['(2021)', '(5)', '(31)'], {}), '(2021, 5, 31)\n', (5582, 5595), False, 'from datetime import datetime, timedelta\n'), ((5612, 5633), 'datetime.datetime', 'datetime', (['(2021)', '(5)', '(31)'], {}), '(2021, 5, 31)\n', (5620, 5633), False, 'from datetime import datetime, timedelta\n'), ((5650, 5671), 'datetime.datetime', 'datetime', (['(2021)', '(5)', '(31)'], {}), '(2021, 5, 31)\n', (5658, 5671), False, 'from datetime import datetime, timedelta\n'), ((5688, 5708), 'datetime.datetime', 'datetime', (['(2021)', '(6)', '(1)'], {}), '(2021, 6, 1)\n', (5696, 5708), False, 'from datetime import datetime, timedelta\n'), ((5725, 5745), 'datetime.datetime', 'datetime', (['(2021)', '(6)', '(3)'], {}), '(2021, 6, 3)\n', (5733, 5745), False, 'from datetime import datetime, timedelta\n'), ((14755, 14776), 'datetime.datetime', 'datetime', (['(2021)', '(6)', '(11)'], {}), '(2021, 6, 11)\n', (14763, 14776), False, 'from datetime import datetime, timedelta\n'), ((14935, 14956), 'datetime.datetime', 'datetime', (['(2021)', '(6)', '(11)'], {}), '(2021, 6, 11)\n', (14943, 14956), False, 'from datetime import datetime, timedelta\n'), ((15117, 15138), 'datetime.datetime', 'datetime', (['(2021)', '(6)', '(11)'], {}), '(2021, 6, 11)\n', (15125, 15138), False, 'from datetime import datetime, timedelta\n'), ((15302, 15323), 'datetime.datetime', 'datetime', (['(2021)', '(6)', '(11)'], {}), '(2021, 6, 11)\n', (15310, 15323), False, 'from datetime import datetime, timedelta\n'), ((17621, 17636), 'sfm.routes.utilities.routes.random_sha', 'random_sha', (['day'], {}), '(day)\n', (17631, 17636), False, 'from sfm.routes.utilities.routes import random_sha\n'), ((5191, 5212), 'datetime.datetime', 'datetime', (['(2021)', '(5)', '(31)'], {}), '(2021, 5, 31)\n', (5199, 5212), False, 'from datetime import datetime, timedelta\n'), ((5253, 5273), 'datetime.datetime', 'datetime', (['(2021)', '(6)', '(1)'], {}), '(2021, 6, 1)\n', (5261, 5273), False, 'from datetime import datetime, timedelta\n'), ((5314, 5334), 'datetime.datetime', 'datetime', (['(2021)', '(6)', '(2)'], {}), '(2021, 6, 2)\n', (5322, 5334), False, 'from datetime import datetime, timedelta\n'), ((5375, 5395), 'datetime.datetime', 'datetime', (['(2021)', '(6)', '(3)'], {}), '(2021, 6, 3)\n', (5383, 5395), False, 'from datetime import datetime, timedelta\n'), ((20655, 20671), 'sqlmodel.select', 'select', (['WorkItem'], {}), '(WorkItem)\n', (20661, 20671), False, 'from sqlmodel import Session, select\n'), ((21343, 21360), 'datetime.timedelta', 'timedelta', ([], {'days': '(5)'}), '(days=5)\n', (21352, 21360), False, 'from datetime import datetime, timedelta\n'), ((22207, 22224), 'datetime.timedelta', 'timedelta', ([], {'days': '(5)'}), '(days=5)\n', (22216, 22224), False, 'from datetime import datetime, timedelta\n'), ((2723, 2742), 'datetime.timedelta', 'timedelta', ([], {'days': 'day'}), '(days=day)\n', (2732, 2742), False, 'from datetime import datetime, timedelta\n'), ((6007, 6028), 'datetime.datetime', 'datetime', (['(2021)', '(5)', '(31)'], {}), '(2021, 5, 31)\n', (6015, 6028), False, 'from datetime import datetime, timedelta\n'), ((6073, 6093), 'datetime.datetime', 'datetime', (['(2021)', '(6)', '(1)'], {}), '(2021, 6, 1)\n', (6081, 6093), False, 'from datetime import datetime, timedelta\n'), ((6138, 6158), 'datetime.datetime', 'datetime', (['(2021)', '(6)', '(2)'], {}), '(2021, 6, 2)\n', (6146, 6158), False, 'from datetime import datetime, timedelta\n'), ((6203, 6223), 'datetime.datetime', 'datetime', (['(2021)', '(6)', '(3)'], {}), '(2021, 6, 3)\n', (6211, 6223), False, 'from datetime import datetime, timedelta\n'), ((6289, 6310), 'datetime.datetime', 'datetime', (['(2021)', '(5)', '(31)'], {}), '(2021, 5, 31)\n', (6297, 6310), False, 'from datetime import datetime, timedelta\n'), ((6357, 6377), 'datetime.datetime', 'datetime', (['(2021)', '(6)', '(1)'], {}), '(2021, 6, 1)\n', (6365, 6377), False, 'from datetime import datetime, timedelta\n'), ((6424, 6444), 'datetime.datetime', 'datetime', (['(2021)', '(6)', '(2)'], {}), '(2021, 6, 2)\n', (6432, 6444), False, 'from datetime import datetime, timedelta\n'), ((6491, 6511), 'datetime.datetime', 'datetime', (['(2021)', '(6)', '(3)'], {}), '(2021, 6, 3)\n', (6499, 6511), False, 'from datetime import datetime, timedelta\n'), ((15915, 15930), 'sfm.routes.utilities.routes.random_sha', 'random_sha', (['day'], {}), '(day)\n', (15925, 15930), False, 'from sfm.routes.utilities.routes import random_sha\n'), ((3218, 3237), 'datetime.timedelta', 'timedelta', ([], {'days': 'day'}), '(days=day)\n', (3227, 3237), False, 'from datetime import datetime, timedelta\n'), ((16453, 16468), 'sfm.routes.utilities.routes.random_sha', 'random_sha', (['day'], {}), '(day)\n', (16463, 16468), False, 'from sfm.routes.utilities.routes import random_sha\n'), ((21519, 21540), 'datetime.datetime', 'datetime', (['(2021)', '(6)', '(10)'], {}), '(2021, 6, 10)\n', (21527, 21540), False, 'from datetime import datetime, timedelta\n'), ((21600, 21621), 'datetime.datetime', 'datetime', (['(2021)', '(6)', '(11)'], {}), '(2021, 6, 11)\n', (21608, 21621), False, 'from datetime import datetime, timedelta\n'), ((21677, 21698), 'datetime.datetime', 'datetime', (['(2021)', '(6)', '(12)'], {}), '(2021, 6, 12)\n', (21685, 21698), False, 'from datetime import datetime, timedelta\n'), ((21754, 21775), 'datetime.datetime', 'datetime', (['(2021)', '(6)', '(13)'], {}), '(2021, 6, 13)\n', (21762, 21775), False, 'from datetime import datetime, timedelta\n'), ((21831, 21852), 'datetime.datetime', 'datetime', (['(2021)', '(6)', '(14)'], {}), '(2021, 6, 14)\n', (21839, 21852), False, 'from datetime import datetime, timedelta\n'), ((22385, 22406), 'datetime.datetime', 'datetime', (['(2021)', '(6)', '(10)'], {}), '(2021, 6, 10)\n', (22393, 22406), False, 'from datetime import datetime, timedelta\n'), ((22466, 22487), 'datetime.datetime', 'datetime', (['(2021)', '(6)', '(11)'], {}), '(2021, 6, 11)\n', (22474, 22487), False, 'from datetime import datetime, timedelta\n'), ((22543, 22564), 'datetime.datetime', 'datetime', (['(2021)', '(6)', '(12)'], {}), '(2021, 6, 12)\n', (22551, 22564), False, 'from datetime import datetime, timedelta\n'), ((22620, 22641), 'datetime.datetime', 'datetime', (['(2021)', '(6)', '(13)'], {}), '(2021, 6, 13)\n', (22628, 22641), False, 'from datetime import datetime, timedelta\n'), ((22697, 22718), 'datetime.datetime', 'datetime', (['(2021)', '(6)', '(14)'], {}), '(2021, 6, 14)\n', (22705, 22718), False, 'from datetime import datetime, timedelta\n'), ((23680, 23700), 'datetime.datetime', 'datetime', (['(2021)', '(6)', '(3)'], {}), '(2021, 6, 3)\n', (23688, 23700), False, 'from datetime import datetime, timedelta\n'), ((23758, 23778), 'datetime.datetime', 'datetime', (['(2021)', '(6)', '(4)'], {}), '(2021, 6, 4)\n', (23766, 23778), False, 'from datetime import datetime, timedelta\n'), ((23834, 23854), 'datetime.datetime', 'datetime', (['(2021)', '(6)', '(5)'], {}), '(2021, 6, 5)\n', (23842, 23854), False, 'from datetime import datetime, timedelta\n'), ((3742, 3761), 'datetime.timedelta', 'timedelta', ([], {'days': 'day'}), '(days=day)\n', (3751, 3761), False, 'from datetime import datetime, timedelta\n'), ((17049, 17064), 'sfm.routes.utilities.routes.random_sha', 'random_sha', (['day'], {}), '(day)\n', (17059, 17064), False, 'from sfm.routes.utilities.routes import random_sha\n')]