|
35 | 35 | from django.core import mail
|
36 | 36 | from django.test import TestCase
|
37 | 37 | from django.urls import URLResolver, resolve, Resolver404, get_resolver
|
| 38 | +from rest_framework.test import APIClient |
38 | 39 |
|
39 | 40 | from alto.server.components.db import (data_broker_manager,
|
40 | 41 | Match,
|
|
50 | 51 | ALTO_CONTENT_TYPE_PROPMAP,
|
51 | 52 | ALTO_CONTENT_TYPE_TIPS,
|
52 | 53 | ALTO_CONTENT_TYPE_TIPS_VIEW,
|
| 54 | + ALTO_CONTENT_TYPE_ERROR, |
53 | 55 | ALTO_PARAMETER_TYPE_ECS,
|
54 | 56 | ALTO_PARAMETER_TYPE_PROPMAP,
|
55 | 57 | ALTO_PARAMETER_TYPE_TIPS)
|
@@ -174,6 +176,10 @@ def setUpTestData(cls) -> None:
|
174 | 176 | db_trans.commit()
|
175 | 177 |
|
176 | 178 |
|
| 179 | + def setUp(self): |
| 180 | + self.client = APIClient(raise_request_exception=False) |
| 181 | + |
| 182 | + |
177 | 183 | def test_northbound_routes(self):
|
178 | 184 | resources = self.config.get_configured_resources()
|
179 | 185 | tips_resources = [r for r in resources if resources[r]['type'] == 'tips']
|
@@ -275,6 +281,7 @@ def test_view_geodist(self):
|
275 | 281 | self.assertEqual(response.has_header('Content-Type'), True)
|
276 | 282 | self.assertEqual(response.get('Content-Type'), ALTO_CONTENT_TYPE_ECS)
|
277 | 283 |
|
| 284 | + |
278 | 285 | def test_view_perfsonar(self):
|
279 | 286 | response = self.client.post('/endpointcost/ps',
|
280 | 287 | data=json.dumps({
|
@@ -343,3 +350,43 @@ def test_view_tips(self):
|
343 | 350 | self.assertEqual(response.status_code, 200)
|
344 | 351 | self.assertEqual(response.has_header('Content-Type'), True)
|
345 | 352 | self.assertEqual(response.get('Content-Type'), 'application/merge-patch+json')
|
| 353 | + |
| 354 | + |
| 355 | + def test_error_unsupported_media_type(self): |
| 356 | + response = self.client.post('/entityprop/geoip', |
| 357 | + data=json.dumps({ |
| 358 | + 'entities': [ |
| 359 | + 'ipv4:10.1.0.2', |
| 360 | + 'ipv4:10.2.0.2', |
| 361 | + 'ipv4:10.3.0.2' |
| 362 | + ] |
| 363 | + }), |
| 364 | + content_type="application/json", |
| 365 | + accepts=ALTO_CONTENT_TYPE_PROPMAP) |
| 366 | + self.assertEqual(response.status_code, 415) |
| 367 | + self.assertEqual(response.has_header('Content-Type'), True) |
| 368 | + self.assertEqual(response.get('Content-Type'), ALTO_CONTENT_TYPE_ERROR) |
| 369 | + |
| 370 | + |
| 371 | + def test_error_not_found(self): |
| 372 | + response = self.client.get('/not_exist', |
| 373 | + accepts=ALTO_CONTENT_TYPE_IRD) |
| 374 | + self.assertEqual(response.status_code, 404) |
| 375 | + self.assertEqual(response.has_header('Content-Type'), True) |
| 376 | + self.assertEqual(response.get('Content-Type'), ALTO_CONTENT_TYPE_ERROR) |
| 377 | + |
| 378 | + |
| 379 | + def test_error_internal_error(self): |
| 380 | + response = self.client.post('/entityprop/geoip-misconfig', |
| 381 | + data=json.dumps({ |
| 382 | + 'entities': [ |
| 383 | + 'ipv4:10.1.0.2', |
| 384 | + 'ipv4:10.2.0.2', |
| 385 | + 'ipv4:10.3.0.2' |
| 386 | + ] |
| 387 | + }), |
| 388 | + content_type=ALTO_PARAMETER_TYPE_PROPMAP, |
| 389 | + accepts=ALTO_CONTENT_TYPE_PROPMAP) |
| 390 | + self.assertEqual(response.status_code, 500) |
| 391 | + self.assertEqual(response.has_header('Content-Type'), True) |
| 392 | + self.assertEqual(response.get('Content-Type'), ALTO_CONTENT_TYPE_ERROR) |
0 commit comments