Example #1
0
def test_get_commits_error_handling_missing_response() -> None:
    """
    We should handle parsing errors without raising an exception.
    """
    pull_request_data = {"commitHistory": None}
    res = get_commits(pr=pull_request_data)
    assert res == []
Example #2
0
def test_get_commits_error_handling() -> None:
    """
    We should handle parsing errors without raising an exception.
    """
    pull_request_data = {
        "commitHistory": {
            "nodes": [
                {"commit": {"parents": {"totalCount": 1}, "author": {"user": None}}},
                {"commit": {"parents": {"totalCount": 1}, "author": None}},
                {
                    "commit": {
                        "parents": {"totalCount": 3},
                        "author": {
                            "user": {
                                "name": None,
                                "databaseId": 435453,
                                "login": "******",
                                "type": "Bot",
                            }
                        },
                    }
                },
                {
                    "commit": {
                        "parents": {"totalCount": 1},
                        "author": {
                            "user": {
                                "name": "Christopher Dignam",
                                "databaseId": 1929960,
                                "login": "******",
                                "type": "User",
                            }
                        },
                    }
                },
                {
                    "commit": {
                        "parents": {"totalCount": 2},
                        "author": {
                            "user": {
                                "name": None,
                                "databaseId": None,
                                "login": "******",
                                "type": "SomeGitActor",
                            }
                        },
                    }
                },
            ]
        }
    }
    res = get_commits(pr=pull_request_data)
    assert res == [
        Commit(parents=CommitConnection(totalCount=1), author=GitActor(user=None)),
        Commit(parents=CommitConnection(totalCount=1), author=None),
        create_commit(
            name=None, database_id=435453, login="******", type="Bot", parents=3
        ),
        create_commit(
            name="Christopher Dignam",
            database_id=1929960,
            login="******",
            type="User",
            parents=1,
        ),
        create_commit(
            name=None, database_id=None, login="******", type="SomeGitActor", parents=2
        ),
    ]
Example #3
0
def test_get_commits() -> None:
    """
    Verify we parse commit authors correctly. We should handle the nullability
    of name and databaseId.
    """
    pull_request_data = {
        "commitHistory": {
            "nodes": [
                {
                    "commit": {
                        "parents": {"totalCount": 1},
                        "author": {
                            "user": {
                                "name": "Christopher Dignam",
                                "databaseId": 1929960,
                                "login": "******",
                                "type": "User",
                            }
                        },
                    }
                },
                {
                    "commit": {
                        "parents": {"totalCount": 1},
                        "author": {
                            "user": {
                                "name": "b-lowe",
                                "databaseId": 5345234,
                                "login": "******",
                                "type": "User",
                            }
                        },
                    }
                },
                {
                    "commit": {
                        "parents": {"totalCount": 1},
                        "author": {
                            "user": {
                                "name": None,
                                "databaseId": 435453,
                                "login": "******",
                                "type": "Bot",
                            }
                        },
                    }
                },
                {"commit": {"parents": {"totalCount": 1}, "author": {"user": None}}},
                {
                    "commit": {
                        "parents": {"totalCount": 1},
                        "author": {
                            "user": {
                                "name": "Christopher Dignam",
                                "databaseId": 1929960,
                                "login": "******",
                                "type": "User",
                            }
                        },
                    }
                },
                {
                    "commit": {
                        "parents": {"totalCount": 1},
                        "author": {
                            "user": {
                                "name": None,
                                "databaseId": None,
                                "login": "******",
                                "type": "SomeGitActor",
                            }
                        },
                    }
                },
            ]
        }
    }
    res = get_commits(pr=pull_request_data)
    assert res == [
        create_commit(
            name="Christopher Dignam", database_id=1929960, login="******", type="User"
        ),
        create_commit(name="b-lowe", database_id=5345234, login="******", type="User"),
        create_commit(name=None, database_id=435453, login="******", type="Bot"),
        Commit(parents=CommitConnection(totalCount=1), author=GitActor(user=None)),
        create_commit(
            name="Christopher Dignam", database_id=1929960, login="******", type="User"
        ),
        create_commit(name=None, database_id=None, login="******", type="SomeGitActor"),
    ]