Skip to content

Commit ddec0f6

Browse files
Karan Goeldstufft
Karan Goel
authored andcommitted
Trove classifiers API endpoint (#1243)
1 parent 32b27e7 commit ddec0f6

File tree

4 files changed

+40
-0
lines changed

4 files changed

+40
-0
lines changed

tests/unit/legacy/api/test_pypi.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717

1818
from warehouse.legacy.api import pypi
1919

20+
from ....common.db.classifiers import ClassifierFactory
21+
2022

2123
def test_exc_with_message():
2224
exc = pypi._exc_with_message(HTTPBadRequest, "My Test Message.")
@@ -67,3 +69,14 @@ def test_forbidden_legacy():
6769
exc, request = pretend.stub(), pretend.stub()
6870
resp = pypi.forbidden_legacy(exc, request)
6971
assert resp is exc
72+
73+
74+
def test_list_classifiers(db_request):
75+
ClassifierFactory.create(classifier="foo :: bar")
76+
ClassifierFactory.create(classifier="foo :: baz")
77+
ClassifierFactory.create(classifier="fiz :: buz")
78+
79+
resp = pypi.list_classifiers(db_request)
80+
81+
assert resp.status_code == 200
82+
assert resp.text == "fiz :: buz\nfoo :: bar\nfoo :: baz"

tests/unit/test_routes.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,11 @@ def add_xmlrpc_endpoint(endpoint, pattern, header, domain=None):
187187
domain=warehouse,
188188
),
189189
pretend.call("legacy.api.pypi.doap", "doap", domain=warehouse),
190+
pretend.call(
191+
"legacy.api.pypi.list_classifiers",
192+
"list_classifiers",
193+
domain=warehouse,
194+
),
190195
]
191196

192197
assert config.add_pypi_action_redirect.calls == [

warehouse/legacy/api/pypi.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,11 @@
1111
# limitations under the License.
1212

1313
from pyramid.httpexceptions import HTTPGone
14+
from pyramid.response import Response
1415
from pyramid.view import forbidden_view_config, view_config
1516

17+
from warehouse.classifiers.models import Classifier
18+
1619

1720
def _exc_with_message(exc, message):
1821
# The crappy old API that PyPI offered uses the status to pass down
@@ -72,3 +75,17 @@ def forbidden_legacy(exc, request):
7275
# the default forbidden handler we have which does redirects to the login
7376
# view, which we do not want on this API.
7477
return exc
78+
79+
80+
@view_config(route_name="legacy.api.pypi.list_classifiers")
81+
def list_classifiers(request):
82+
classifiers = (
83+
request.db.query(Classifier.classifier)
84+
.order_by(Classifier.classifier)
85+
.all()
86+
)
87+
88+
return Response(
89+
text='\n'.join(c[0] for c in classifiers),
90+
content_type='text/plain; charset=utf-8'
91+
)

warehouse/routes.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,11 @@ def includeme(config):
145145
"doap",
146146
domain=warehouse,
147147
)
148+
config.add_pypi_action_route(
149+
"legacy.api.pypi.list_classifiers",
150+
"list_classifiers",
151+
domain=warehouse,
152+
)
148153

149154
# Legacy XMLRPC
150155
config.add_xmlrpc_endpoint(

0 commit comments

Comments
 (0)