Skip to content
This repository was archived by the owner on Jun 13, 2025. It is now read-only.

Commit 02a5361

Browse files
committed
more tests
1 parent 5b18f31 commit 02a5361

File tree

1 file changed

+302
-0
lines changed

1 file changed

+302
-0
lines changed

graphql_api/tests/test_branch.py

Lines changed: 302 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1275,3 +1275,305 @@ def test_fetch_path_contents_deprecated_paginated(
12751275
}
12761276
}
12771277
}
1278+
1279+
@override_settings(DEBUG=True)
1280+
@patch("shared.reports.api_report_service.build_report_from_commit")
1281+
def test_fetch_path_contents_deprecated_with_no_report(self, report_mock):
1282+
report_mock.return_value = None
1283+
commit_without_report = CommitFactory(repository=self.repo)
1284+
branch = BranchFactory(
1285+
repository=self.repo,
1286+
head=commit_without_report.commitid,
1287+
name="branch-two",
1288+
updatestamp=(datetime.now() + timedelta(1)),
1289+
)
1290+
variables = {
1291+
"org": self.org.username,
1292+
"repo": self.repo.name,
1293+
"branch": branch.name,
1294+
"path": "",
1295+
"filters": {},
1296+
}
1297+
data = self.gql_request(query_files_connection, variables=variables)
1298+
assert data == {
1299+
"owner": {
1300+
"repository": {
1301+
"branch": {
1302+
"head": {
1303+
"deprecatedPathContents": {
1304+
"__typename": "MissingHeadReport",
1305+
"message": "Missing head report",
1306+
}
1307+
}
1308+
}
1309+
}
1310+
}
1311+
}
1312+
1313+
@override_settings(DEBUG=True)
1314+
@patch("services.path.provider_path_exists")
1315+
@patch("services.path.ReportPaths.paths", new_callable=PropertyMock)
1316+
@patch("shared.reports.api_report_service.build_report_from_commit")
1317+
def test_fetch_path_contents_deprecated_missing_coverage(
1318+
self, report_mock, paths_mock, provider_path_exists_mock
1319+
):
1320+
report_mock.return_value = MockReport()
1321+
paths_mock.return_value = []
1322+
provider_path_exists_mock.return_value = True
1323+
1324+
data = self.gql_request(
1325+
query_files_connection,
1326+
variables={
1327+
"org": self.org.username,
1328+
"repo": self.repo.name,
1329+
"branch": self.branch.name,
1330+
"path": "invalid",
1331+
"filters": {},
1332+
},
1333+
)
1334+
assert data == {
1335+
"owner": {
1336+
"repository": {
1337+
"branch": {
1338+
"head": {
1339+
"deprecatedPathContents": {
1340+
"__typename": "MissingCoverage",
1341+
"message": "missing coverage for path: invalid",
1342+
}
1343+
}
1344+
}
1345+
}
1346+
}
1347+
}
1348+
1349+
@override_settings(DEBUG=True)
1350+
@patch("services.path.provider_path_exists")
1351+
@patch("services.path.ReportPaths.paths", new_callable=PropertyMock)
1352+
@patch("shared.reports.api_report_service.build_report_from_commit")
1353+
def test_fetch_path_contents_deprecated_unknown_path(
1354+
self, report_mock, paths_mock, provider_path_exists_mock
1355+
):
1356+
report_mock.return_value = MockReport()
1357+
paths_mock.return_value = []
1358+
provider_path_exists_mock.return_value = False
1359+
1360+
data = self.gql_request(
1361+
query_files_connection,
1362+
variables={
1363+
"org": self.org.username,
1364+
"repo": self.repo.name,
1365+
"branch": self.branch.name,
1366+
"path": "invalid",
1367+
"filters": {},
1368+
},
1369+
)
1370+
assert data == {
1371+
"owner": {
1372+
"repository": {
1373+
"branch": {
1374+
"head": {
1375+
"deprecatedPathContents": {
1376+
"__typename": "UnknownPath",
1377+
"message": "path does not exist: invalid",
1378+
}
1379+
}
1380+
}
1381+
}
1382+
}
1383+
}
1384+
1385+
@override_settings(DEBUG=True)
1386+
@patch("shared.reports.api_report_service.build_report_from_commit")
1387+
def test_fetch_path_contents_deprecated_unknown_flags_no_flags(self, report_mock):
1388+
report_mock.return_value = MockNoFlagsReport()
1389+
1390+
data = self.gql_request(
1391+
query_files_connection,
1392+
variables={
1393+
"org": self.org.username,
1394+
"repo": self.repo.name,
1395+
"branch": self.branch.name,
1396+
"path": "",
1397+
"filters": {"flags": ["test-123"]},
1398+
},
1399+
)
1400+
assert data == {
1401+
"owner": {
1402+
"repository": {
1403+
"branch": {
1404+
"head": {
1405+
"deprecatedPathContents": {
1406+
"__typename": "UnknownFlags",
1407+
"message": "No coverage with chosen flags: ['test-123']",
1408+
}
1409+
}
1410+
}
1411+
}
1412+
}
1413+
}
1414+
1415+
@override_settings(DEBUG=True)
1416+
@patch("services.components.commit_components")
1417+
@patch("shared.reports.api_report_service.build_report_from_commit")
1418+
def test_fetch_path_contents_deprecated_component_filter_missing_coverage(
1419+
self, report_mock, commit_components_mock
1420+
):
1421+
components = ["ComponentThree"]
1422+
variables = {
1423+
"org": self.org.username,
1424+
"repo": self.repo.name,
1425+
"branch": self.branch.name,
1426+
"path": "",
1427+
"filters": {"components": components},
1428+
}
1429+
1430+
report_mock.return_value = MockReport()
1431+
commit_components_mock.return_value = [
1432+
Component.from_dict(
1433+
{
1434+
"component_id": "c1",
1435+
"name": "ComponentOne",
1436+
"paths": ["fileA.py"],
1437+
}
1438+
),
1439+
Component.from_dict(
1440+
{
1441+
"component_id": "c2",
1442+
"name": "ComponentTwo",
1443+
"paths": ["fileB.py"],
1444+
}
1445+
),
1446+
Component.from_dict(
1447+
{
1448+
"component_id": "global",
1449+
"name": "Global",
1450+
"paths": ["(?s:.*/[^\\/]*\\.py.*)\\Z"],
1451+
}
1452+
),
1453+
]
1454+
1455+
data = self.gql_request(query_files_connection, variables=variables)
1456+
1457+
assert data == {
1458+
"owner": {
1459+
"repository": {
1460+
"branch": {
1461+
"head": {
1462+
"deprecatedPathContents": {
1463+
"__typename": "MissingCoverage",
1464+
"message": f"missing coverage for report with components: {components}",
1465+
}
1466+
}
1467+
}
1468+
}
1469+
}
1470+
}
1471+
1472+
@patch("shared.reports.api_report_service.build_report_from_commit")
1473+
def test_fetch_path_contents_deprecated_with_files_and_list_display_type(
1474+
self, report_mock
1475+
):
1476+
variables = {
1477+
"org": self.org.username,
1478+
"repo": self.repo.name,
1479+
"branch": self.branch.name,
1480+
"path": "",
1481+
"filters": {
1482+
"displayType": "LIST",
1483+
},
1484+
}
1485+
report_mock.return_value = MockReport()
1486+
1487+
data = self.gql_request(query_files_connection, variables=variables)
1488+
assert data == {
1489+
"owner": {
1490+
"repository": {
1491+
"branch": {
1492+
"head": {
1493+
"deprecatedPathContents": {
1494+
"__typename": "PathContentConnection",
1495+
"edges": [
1496+
{
1497+
"cursor": "0",
1498+
"node": {
1499+
"__typename": "PathContentFile",
1500+
"name": "fileA.py",
1501+
"path": "fileA.py",
1502+
"hits": 8,
1503+
"misses": 0,
1504+
"partials": 0,
1505+
"lines": 10,
1506+
"percentCovered": 80.0,
1507+
"isCriticalFile": False,
1508+
},
1509+
},
1510+
{
1511+
"cursor": "1",
1512+
"node": {
1513+
"__typename": "PathContentFile",
1514+
"name": "fileB.py",
1515+
"path": "fileB.py",
1516+
"hits": 8,
1517+
"misses": 0,
1518+
"partials": 0,
1519+
"lines": 10,
1520+
"percentCovered": 80.0,
1521+
"isCriticalFile": False,
1522+
},
1523+
},
1524+
{
1525+
"cursor": "2",
1526+
"node": {
1527+
"__typename": "PathContentFile",
1528+
"name": "fileB.py",
1529+
"path": "folder/fileB.py",
1530+
"hits": 8,
1531+
"misses": 0,
1532+
"partials": 0,
1533+
"lines": 10,
1534+
"percentCovered": 80.0,
1535+
"isCriticalFile": False,
1536+
},
1537+
},
1538+
{
1539+
"cursor": "3",
1540+
"node": {
1541+
"__typename": "PathContentFile",
1542+
"name": "fileC.py",
1543+
"path": "folder/subfolder/fileC.py",
1544+
"hits": 8,
1545+
"misses": 0,
1546+
"partials": 0,
1547+
"lines": 10,
1548+
"percentCovered": 80.0,
1549+
"isCriticalFile": False,
1550+
},
1551+
},
1552+
{
1553+
"cursor": "4",
1554+
"node": {
1555+
"__typename": "PathContentFile",
1556+
"name": "fileD.py",
1557+
"path": "folder/subfolder/fileD.py",
1558+
"hits": 8,
1559+
"misses": 0,
1560+
"partials": 0,
1561+
"lines": 10,
1562+
"percentCovered": 80.0,
1563+
"isCriticalFile": False,
1564+
},
1565+
},
1566+
],
1567+
"totalCount": 5,
1568+
"pageInfo": {
1569+
"hasNextPage": False,
1570+
"hasPreviousPage": False,
1571+
"startCursor": "0",
1572+
"endCursor": "4",
1573+
},
1574+
}
1575+
}
1576+
}
1577+
}
1578+
}
1579+
}

0 commit comments

Comments
 (0)