Revision bbf20a4c snf-astakos-app/astakos/im/tests/api.py
b/snf-astakos-app/astakos/im/tests/api.py | ||
---|---|---|
39 | 39 |
from django.test import TestCase |
40 | 40 |
from django.core.urlresolvers import reverse |
41 | 41 |
|
42 |
from datetime import date |
|
43 |
|
|
42 | 44 |
#from xml.dom import minidom |
43 | 45 |
|
44 | 46 |
import json |
... | ... | |
588 | 590 |
# self.fail(e) |
589 | 591 |
|
590 | 592 |
|
593 |
class UserCatalogsTest(TestCase): |
|
594 |
def test_get_uuid_displayname_catalogs(self): |
|
595 |
self.user = AstakosUser.objects.create( |
|
596 |
email='test1', email_verified=True, moderated=True, |
|
597 |
is_rejected=False) |
|
598 |
|
|
599 |
client = Client() |
|
600 |
url = reverse('astakos.api.user.get_uuid_displayname_catalogs') |
|
601 |
d = dict(uuids=[self.user.uuid], displaynames=[self.user.username]) |
|
602 |
|
|
603 |
# assert Unauthorized: missing authentication token |
|
604 |
r = client.post(url, |
|
605 |
data=json.dumps(d), |
|
606 |
content_type='application/json') |
|
607 |
self.assertEqual(r.status_code, 401) |
|
608 |
|
|
609 |
# assert Unauthorized: invalid authentication token |
|
610 |
r = client.post(url, |
|
611 |
data=json.dumps(d), |
|
612 |
content_type='application/json', |
|
613 |
HTTP_X_AUTH_TOKEN='1234') |
|
614 |
self.assertEqual(r.status_code, 401) |
|
615 |
|
|
616 |
# assert Unauthorized: inactive token holder |
|
617 |
r = client.post(url, |
|
618 |
data=json.dumps(d), |
|
619 |
content_type='application/json', |
|
620 |
HTTP_X_AUTH_TOKEN=self.user.auth_token) |
|
621 |
self.assertEqual(r.status_code, 401) |
|
622 |
|
|
623 |
backend = activation_backends.get_backend() |
|
624 |
backend.activate_user(self.user) |
|
625 |
assert self.user.is_active is True |
|
626 |
|
|
627 |
r = client.post(url, |
|
628 |
data=json.dumps(d), |
|
629 |
content_type='application/json', |
|
630 |
HTTP_X_AUTH_TOKEN=self.user.auth_token) |
|
631 |
self.assertEqual(r.status_code, 200) |
|
632 |
try: |
|
633 |
data = json.loads(r.content) |
|
634 |
except: |
|
635 |
self.fail('Response body should be json formatted') |
|
636 |
else: |
|
637 |
if not isinstance(data, dict): |
|
638 |
self.fail('Response body should be json formatted dictionary') |
|
639 |
|
|
640 |
self.assertTrue('uuid_catalog' in data) |
|
641 |
self.assertEqual(data['uuid_catalog'], |
|
642 |
{self.user.uuid: self.user.username}) |
|
643 |
|
|
644 |
self.assertTrue('displayname_catalog' in data) |
|
645 |
self.assertEqual(data['displayname_catalog'], |
|
646 |
{self.user.username: self.user.uuid}) |
|
647 |
|
|
648 |
# assert Unauthorized: expired token |
|
649 |
self.user.auth_token_expires = date.today() - timedelta(1) |
|
650 |
self.user.save() |
|
651 |
|
|
652 |
r = client.post(url, |
|
653 |
data=json.dumps(d), |
|
654 |
content_type='application/json', |
|
655 |
HTTP_X_AUTH_TOKEN=self.user.auth_token) |
|
656 |
self.assertEqual(r.status_code, 401) |
|
657 |
|
|
658 |
# assert Unauthorized: expired token |
|
659 |
self.user.auth_token_expires = date.today() + timedelta(1) |
|
660 |
self.user.save() |
|
661 |
|
|
662 |
# assert badRequest |
|
663 |
r = client.post(url, |
|
664 |
data=json.dumps(str(d)), |
|
665 |
content_type='application/json', |
|
666 |
HTTP_X_AUTH_TOKEN=self.user.auth_token) |
|
667 |
self.assertEqual(r.status_code, 400) |
|
668 |
|
|
669 |
|
|
591 | 670 |
class WrongPathAPITest(TestCase): |
592 | 671 |
def test_catch_wrong_account_paths(self, *args): |
593 | 672 |
path = get_service_path(astakos_services, 'account', 'v1.0') |
Also available in: Unified diff