Revision 8cb96389 snf-astakos-app/astakos/im/tests/api.py

b/snf-astakos-app/astakos/im/tests/api.py
34 34
from astakos.im.tests.common import *
35 35

  
36 36
from django.test import TestCase
37
from django.core.urlresolvers import reverse
38

  
37 39

  
38 40
from urllib import quote
39 41
from urlparse import urlparse, parse_qs
40
from xml.dom import minidom
42
#from xml.dom import minidom
41 43

  
42 44
import json
43 45

  
......
391 393
        backend.activate_user(self.user2)
392 394
        assert self.user2.is_active is True
393 395

  
394
        Service(name='service1', url='http://localhost/service1',
395
                api_url='http://localhost/api/service1',
396
                type='service1').save()
397
        Service(name='service2', url='http://localhost/service2',
398
                api_url='http://localhost/api/service2',
399
                type='service2').save()
400
        Service(name='service3', url='http://localhost/service3',
401
                api_url='http://localhost/api/service3',
402
                type='service3').save()
396
        c1 = Component(name='component1', url='http://localhost/component1')
397
        c1.save()
398
        s1 = Service(component=c1, type='type1', name='service1')
399
        s1.save()
400
        e1 = Endpoint(service=s1)
401
        e1.save()
402
        e1.data.create(key='versionId', value='v1.0')
403
        e1.data.create(key='publicURL', value='http://localhost:8000/s1/v1.0')
404

  
405
        s2 = Service(component=c1, type='type2', name='service2')
406
        s2.save()
407
        e2 = Endpoint(service=s2)
408
        e2.save()
409
        e2.data.create(key='versionId', value='v1.0')
410
        e2.data.create(key='publicURL', value='http://localhost:8000/s2/v1.0')
411

  
412
        c2 = Component(name='component2', url='http://localhost/component2')
413
        c2.save()
414
        s3 = Service(component=c2, type='type3', name='service3')
415
        s3.save()
416
        e3 = Endpoint(service=s3)
417
        e3.save()
418
        e3.data.create(key='versionId', value='v2.0')
419
        e3.data.create(key='publicURL', value='http://localhost:8000/s3/v2.0')
403 420

  
404 421
    def test_authenticate(self):
405 422
        client = Client()
406 423

  
407 424
        # Check not allowed method
408
        url = '/astakos/api/tokens'
425
        url = reverse('astakos.api.tokens.authenticate')
409 426
        r = client.get(url, post_data={})
410 427
        self.assertEqual(r.status_code, 400)
411 428

  
412 429
        # Malformed request
413
        url = '/astakos/api/tokens'
430
        url = reverse('astakos.api.tokens.authenticate')
414 431
        r = client.post(url, post_data={})
415 432
        self.assertEqual(r.status_code, 400)
416 433

  
417 434
        # Check unsupported xml input
418
        url = '/astakos/api/tokens'
435
        url = reverse('astakos.api.tokens.authenticate')
419 436
        post_data = """
420 437
            <?xml version="1.0" encoding="UTF-8"?>
421 438
                <auth xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
......
431 448
                         "Unsupported Content-type: 'application/xml'")
432 449

  
433 450
        # Check malformed request: missing password
434
        url = '/astakos/api/tokens'
451
        url = reverse('astakos.api.tokens.authenticate')
435 452
        post_data = """{"auth":{"passwordCredentials":{"username":"%s"},
436 453
                                "tenantName":"%s"}}""" % (
437 454
            self.user1.uuid, self.user1.uuid)
......
442 459
                         'Malformed request')
443 460

  
444 461
        # Check malformed request: missing username
445
        url = '/astakos/api/tokens'
462
        url = reverse('astakos.api.tokens.authenticate')
446 463
        post_data = """{"auth":{"passwordCredentials":{"password":"%s"},
447 464
                                "tenantName":"%s"}}""" % (
448 465
            self.user1.auth_token, self.user1.uuid)
......
453 470
                         'Malformed request')
454 471

  
455 472
        # Check invalid pass
456
        url = '/astakos/api/tokens'
473
        url = reverse('astakos.api.tokens.authenticate')
457 474
        post_data = """{"auth":{"passwordCredentials":{"username":"%s",
458 475
                                                       "password":"%s"},
459 476
                                "tenantName":"%s"}}""" % (
......
465 482
                         'Invalid token')
466 483

  
467 484
        # Check inconsistent pass
468
        url = '/astakos/api/tokens'
485
        url = reverse('astakos.api.tokens.authenticate')
469 486
        post_data = """{"auth":{"passwordCredentials":{"username":"%s",
470 487
                                                       "password":"%s"},
471 488
                                "tenantName":"%s"}}""" % (
......
477 494
                         'Invalid credentials')
478 495

  
479 496
        # Check invalid json data
480
        url = '/astakos/api/tokens'
497
        url = reverse('astakos.api.tokens.authenticate')
481 498
        r = client.post(url, "not json", content_type='application/json')
482 499
        self.assertEqual(r.status_code, 400)
483 500
        body = json.loads(r.content)
484 501
        self.assertEqual(body['badRequest']['message'], 'Invalid JSON data')
485 502

  
486 503
        # Check auth with token
487
        url = '/astakos/api/tokens'
504
        url = reverse('astakos.api.tokens.authenticate')
488 505
        post_data = """{"auth":{"token": {"id":"%s"},
489 506
                        "tenantName":"%s"}}""" % (
490 507
            self.user1.auth_token, self.user1.uuid)
......
497 514
            self.fail(e)
498 515

  
499 516
        # Check successful json response
500
        url = '/astakos/api/tokens'
517
        url = reverse('astakos.api.tokens.authenticate')
501 518
        post_data = """{"auth":{"passwordCredentials":{"username":"%s",
502 519
                                                       "password":"%s"},
503 520
                                "tenantName":"%s"}}""" % (
......
511 528
            self.fail(e)
512 529

  
513 530
        try:
514
            token = body['token']['id']
515
            user = body['user']['id']
516
            service_catalog = body['serviceCatalog']
531
            token = body['access']['token']['id']
532
            user = body['access']['user']['id']
533
            service_catalog = body['access']['serviceCatalog']
517 534
        except KeyError:
518 535
            self.fail('Invalid response')
519 536

  
......
522 539
        self.assertEqual(len(service_catalog), 3)
523 540

  
524 541
        # Check successful xml response
525
        url = '/astakos/api/tokens'
542
        url = reverse('astakos.api.tokens.authenticate')
526 543
        headers = {'HTTP_ACCEPT': 'application/xml'}
527 544
        post_data = """{"auth":{"passwordCredentials":{"username":"%s",
528 545
                                                       "password":"%s"},

Also available in: Unified diff