-
Notifications
You must be signed in to change notification settings - Fork 45
/
Copy pathtest_pull_requests.py
140 lines (128 loc) · 4.09 KB
/
test_pull_requests.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
from github_to_sqlite import utils
import pytest
import pathlib
import sqlite_utils
from sqlite_utils.db import ForeignKey
import json
@pytest.fixture
def pull_requests():
return json.load(open(pathlib.Path(__file__).parent / "pull_requests.json"))
@pytest.fixture
def db(pull_requests):
db = sqlite_utils.Database(memory=True)
db["repos"].insert(
{"id": 1},
pk="id",
columns={"organization": int, "topics": str, "name": str, "description": str},
)
utils.save_pull_requests(db, pull_requests, {"id": 1})
return db
def test_tables(db):
assert {"pull_requests", "users", "repos", "milestones"} == set(db.table_names())
assert set(db["pull_requests"].foreign_keys) == {
ForeignKey(
table="pull_requests",
column="merged_by",
other_table="users",
other_column="id",
),
ForeignKey(
table="pull_requests",
column="assignee",
other_table="users",
other_column="id",
),
ForeignKey(
table="pull_requests",
column="milestone",
other_table="milestones",
other_column="id",
),
ForeignKey(
table="pull_requests", column="repo", other_table="repos", other_column="id"
),
ForeignKey(
table="pull_requests", column="user", other_table="users", other_column="id"
),
}
def test_pull_requests(db):
pull_request_rows = list(db["pull_requests"].rows)
assert [
{
"id": 313384926,
"node_id": "MDExOlB1bGxSZXF1ZXN0MzEzMzg0OTI2",
"number": 571,
"state": "closed",
"locked": 0,
"title": "detect_fts now works with alternative table escaping",
"user": 9599,
"body": "Fixes #570",
"created_at": "2019-09-03T00:23:39Z",
"updated_at": "2019-09-03T00:32:28Z",
"closed_at": "2019-09-03T00:32:28Z",
"merged_at": "2019-09-03T00:32:28Z",
"merge_commit_sha": "2dc5c8dc259a0606162673d394ba8cc1c6f54428",
"assignee": None,
"milestone": None,
"draft": 0,
"head": "a85239f69261c10f1a9f90514c8b5d113cb94585",
"base": "f04deebec4f3842f7bd610cd5859de529f77d50e",
"author_association": "OWNER",
"merged": 1,
"mergeable": None,
"rebaseable": None,
"mergeable_state": "unknown",
"merged_by": 9599,
"comments": 0,
"review_comments": 0,
"maintainer_can_modify": 0,
"commits": 1,
"additions": 7,
"deletions": 3,
"changed_files": 2,
"repo": 1,
"url": "https://github.com/simonw/datasette/pull/571",
}
] == pull_request_rows
def test_users(db):
user_rows = list(db["users"].rows)
assert [
{
"login": "simonw",
"id": 9599,
"node_id": "MDQ6VXNlcjk1OTk=",
"avatar_url": "https://avatars0.githubusercontent.com/u/9599?v=4",
"gravatar_id": "",
"html_url": "https://github.com/simonw",
"type": "User",
"site_admin": 0,
"name": "simonw",
}
] == user_rows
def test_foreign_keys(db):
assert db["pull_requests"].foreign_keys == [
ForeignKey(
table="pull_requests", column="repo", other_table="repos", other_column="id"
),
ForeignKey(
table="pull_requests",
column="merged_by",
other_table="users",
other_column="id",
),
ForeignKey(
table="pull_requests",
column="milestone",
other_table="milestones",
other_column="id",
),
ForeignKey(
table="pull_requests",
column="assignee",
other_table="users",
other_column="id",
),
ForeignKey(
table="pull_requests", column="user", other_table="users", other_column="id"
),
]