|
16 | 16 |
|
17 | 17 | import json |
18 | 18 | import unittest |
| 19 | +import pytest |
19 | 20 |
|
20 | 21 | import endpoints.api_config as api_config |
21 | 22 |
|
22 | 23 | from protorpc import message_types |
23 | 24 | from protorpc import messages |
24 | 25 | from protorpc import remote |
25 | 26 |
|
| 27 | +import endpoints.api_exceptions as api_exceptions |
26 | 28 | import endpoints.resource_container as resource_container |
27 | 29 | import endpoints.openapi_generator as openapi_generator |
28 | 30 | import test_util |
@@ -154,7 +156,6 @@ def entries_post_audiences(self, unused_request): |
154 | 156 | 'description': 'Describes MyService.', |
155 | 157 | 'version': 'v1', |
156 | 158 | }, |
157 | | - 'x-google-api-name': 'root', |
158 | 159 | 'host': 'example.appspot.com', |
159 | 160 | 'consumes': ['application/json'], |
160 | 161 | 'produces': ['application/json'], |
@@ -481,7 +482,6 @@ def items_put_container(self, unused_request): |
481 | 482 | 'description': 'Describes MyService.', |
482 | 483 | 'version': 'v1', |
483 | 484 | }, |
484 | | - 'x-google-api-name': 'root', |
485 | 485 | 'host': 'example.appspot.com', |
486 | 486 | 'consumes': ['application/json'], |
487 | 487 | 'produces': ['application/json'], |
@@ -1033,7 +1033,6 @@ def get_airport_2(self, request): |
1033 | 1033 | 'title': 'iata', |
1034 | 1034 | 'version': 'v1', |
1035 | 1035 | }, |
1036 | | - 'x-google-api-name': 'iata', |
1037 | 1036 | 'host': None, |
1038 | 1037 | 'consumes': ['application/json'], |
1039 | 1038 | 'produces': ['application/json'], |
@@ -1127,7 +1126,6 @@ def noop_get(self, unused_request): |
1127 | 1126 | 'description': 'Describes MyService.', |
1128 | 1127 | 'version': 'v1', |
1129 | 1128 | }, |
1130 | | - 'x-google-api-name': 'root', |
1131 | 1129 | 'host': 'localhost:8080', |
1132 | 1130 | 'consumes': ['application/json'], |
1133 | 1131 | 'produces': ['application/json'], |
@@ -1191,7 +1189,6 @@ def noop_get(self, unused_request): |
1191 | 1189 | 'description': 'Describes MyService.', |
1192 | 1190 | 'version': 'v1', |
1193 | 1191 | }, |
1194 | | - 'x-google-api-name': 'root', |
1195 | 1192 | 'host': 'example.appspot.com', |
1196 | 1193 | 'consumes': ['application/json'], |
1197 | 1194 | 'produces': ['application/json'], |
@@ -1292,7 +1289,6 @@ def override_get(self, unused_request): |
1292 | 1289 | 'description': 'Describes MyService.', |
1293 | 1290 | 'version': 'v1', |
1294 | 1291 | }, |
1295 | | - 'x-google-api-name': 'root', |
1296 | 1292 | 'host': 'example.appspot.com', |
1297 | 1293 | 'consumes': ['application/json'], |
1298 | 1294 | 'produces': ['application/json'], |
@@ -1365,7 +1361,6 @@ def noop_get(self, unused_request): |
1365 | 1361 | 'description': 'Describes MyService.', |
1366 | 1362 | 'version': '1.3.4', |
1367 | 1363 | }, |
1368 | | - 'x-google-api-name': 'root', |
1369 | 1364 | 'host': 'example.appspot.com', |
1370 | 1365 | 'consumes': ['application/json'], |
1371 | 1366 | 'produces': ['application/json'], |
@@ -1418,7 +1413,6 @@ def noop_get(self, unused_request): |
1418 | 1413 | 'description': 'Describes MyService.', |
1419 | 1414 | 'version': 'v1', |
1420 | 1415 | }, |
1421 | | - 'x-google-api-name': 'root', |
1422 | 1416 | 'host': 'example.appspot.com', |
1423 | 1417 | 'consumes': ['application/json'], |
1424 | 1418 | 'produces': ['application/json'], |
@@ -1471,7 +1465,6 @@ def noop_get(self, unused_request): |
1471 | 1465 | 'description': 'Describes MyService.', |
1472 | 1466 | 'version': 'v1', |
1473 | 1467 | }, |
1474 | | - 'x-google-api-name': 'root', |
1475 | 1468 | 'host': 'example.appspot.com', |
1476 | 1469 | 'consumes': ['application/json'], |
1477 | 1470 | 'produces': ['application/json'], |
@@ -1524,7 +1517,6 @@ def toplevel(self, unused_request): |
1524 | 1517 | 'description': 'Testing repeated params', |
1525 | 1518 | 'version': 'v1', |
1526 | 1519 | }, |
1527 | | - 'x-google-api-name': 'root', |
1528 | 1520 | 'host': 'example.appspot.com', |
1529 | 1521 | 'consumes': ['application/json'], |
1530 | 1522 | 'produces': ['application/json'], |
@@ -1606,7 +1598,6 @@ def toplevel(self, unused_request): |
1606 | 1598 | 'description': 'Testing repeated simple field params', |
1607 | 1599 | 'version': 'v1', |
1608 | 1600 | }, |
1609 | | - 'x-google-api-name': 'root', |
1610 | 1601 | 'host': 'example.appspot.com', |
1611 | 1602 | 'consumes': ['application/json'], |
1612 | 1603 | 'produces': ['application/json'], |
@@ -1682,7 +1673,6 @@ def toplevel(self, unused_request): |
1682 | 1673 | 'description': 'Testing repeated Message params', |
1683 | 1674 | 'version': 'v1', |
1684 | 1675 | }, |
1685 | | - 'x-google-api-name': 'root', |
1686 | 1676 | 'host': 'example.appspot.com', |
1687 | 1677 | 'consumes': ['application/json'], |
1688 | 1678 | 'produces': ['application/json'], |
@@ -1749,6 +1739,35 @@ def toplevel(self, unused_request): |
1749 | 1739 |
|
1750 | 1740 | test_util.AssertDictEqual(expected_openapi, api, self) |
1751 | 1741 |
|
| 1742 | + def testApiNameRestrictions(self): |
| 1743 | + @api_config.api(name='coolservice', version='vX') |
| 1744 | + class MyDecoratedService(remote.Service): |
| 1745 | + pass |
| 1746 | + |
| 1747 | + api = json.loads(self.generator.pretty_print_config_to_json(MyDecoratedService)) |
| 1748 | + assert 'x-google-api-name' not in api |
| 1749 | + api = json.loads(self.generator.pretty_print_config_to_json(MyDecoratedService, x_google_api_name=True)) |
| 1750 | + assert 'x-google-api-name' in api |
| 1751 | + assert 'coolservice' == api['x-google-api-name'] |
| 1752 | + |
| 1753 | + @api_config.api('CoolService2', 'v2') |
| 1754 | + class MyDecoratedService(remote.Service): |
| 1755 | + pass |
| 1756 | + |
| 1757 | + api = json.loads(self.generator.pretty_print_config_to_json(MyDecoratedService)) |
| 1758 | + assert 'x-google-api-name' not in api |
| 1759 | + with pytest.raises(api_exceptions.InvalidApiNameException): |
| 1760 | + self.generator.pretty_print_config_to_json(MyDecoratedService, x_google_api_name=True) |
| 1761 | + |
| 1762 | + @api_config.api('c' + 'o'*40 + 'l', 'v2') |
| 1763 | + class MyDecoratedService(remote.Service): |
| 1764 | + pass |
| 1765 | + |
| 1766 | + api = json.loads(self.generator.pretty_print_config_to_json(MyDecoratedService)) |
| 1767 | + assert 'x-google-api-name' not in api |
| 1768 | + with pytest.raises(api_exceptions.InvalidApiNameException): |
| 1769 | + self.generator.pretty_print_config_to_json(MyDecoratedService, x_google_api_name=True) |
| 1770 | + |
1752 | 1771 |
|
1753 | 1772 | class DevServerOpenApiGeneratorTest(BaseOpenApiGeneratorTest, |
1754 | 1773 | test_util.DevServerTest): |
@@ -1780,7 +1799,6 @@ def noop_get(self, unused_request): |
1780 | 1799 | 'description': 'Describes MyService.', |
1781 | 1800 | 'version': 'v1', |
1782 | 1801 | }, |
1783 | | - 'x-google-api-name': 'root', |
1784 | 1802 | 'host': 'example.appspot.com', |
1785 | 1803 | 'consumes': ['application/json'], |
1786 | 1804 | 'produces': ['application/json'], |
@@ -1846,7 +1864,6 @@ def entries_post_audience(self, unused_request): |
1846 | 1864 | 'description': 'Describes MyService.', |
1847 | 1865 | 'version': 'v1', |
1848 | 1866 | }, |
1849 | | - 'x-google-api-name': 'root', |
1850 | 1867 | 'host': 'example.appspot.com', |
1851 | 1868 | 'consumes': ['application/json'], |
1852 | 1869 | 'produces': ['application/json'], |
@@ -2044,7 +2061,6 @@ def entries_post(self, unused_request): |
2044 | 2061 | 'description': 'Describes MyService.', |
2045 | 2062 | 'version': 'v1', |
2046 | 2063 | }, |
2047 | | - 'x-google-api-name': 'root', |
2048 | 2064 | 'host': 'example.appspot.com', |
2049 | 2065 | 'consumes': ['application/json'], |
2050 | 2066 | 'produces': ['application/json'], |
@@ -2131,7 +2147,6 @@ def entries_post(self, unused_request): |
2131 | 2147 | 'description': 'Describes MyService.', |
2132 | 2148 | 'version': 'v1', |
2133 | 2149 | }, |
2134 | | - 'x-google-api-name': 'root', |
2135 | 2150 | 'host': 'example.appspot.com', |
2136 | 2151 | 'consumes': ['application/json'], |
2137 | 2152 | 'produces': ['application/json'], |
|
0 commit comments