Revision 9b12caae

b/snf-astakos-app/astakos/im/tests/api.py
594 594
#        except Exception, e:
595 595
#            self.fail(e)
596 596

  
597
        # Check belongsTo BadRequest
598
        url = '/astakos/api/tokens/%s/endpoints?belongsTo=%s' % (
599
            quote(self.user1.auth_token), quote(self.user2.uuid))
600
        headers = {'HTTP_X_AUTH_TOKEN': self.user1.auth_token}
601
        r = client.get(url, **headers)
602
        self.assertEqual(r.status_code, 400)
603

  
604
        # Check successful request
605
        url = '/astakos/api/tokens/%s/endpoints' % quote(self.user1.auth_token)
606
        headers = {'HTTP_X_AUTH_TOKEN': self.user1.auth_token}
607
        r = client.get(url, **headers)
608
        self.assertEqual(r.status_code, 200)
609
        self.assertEqual(r['Content-Type'], 'application/json; charset=UTF-8')
610
        try:
611
            body = json.loads(r.content)
612
        except:
613
            self.fail('json format expected')
614
        endpoints = body.get('endpoints')
615
        self.assertEqual(len(endpoints), 3)
616

  
617
         # Check xml serialization
618
        url = '/astakos/api/tokens/%s/endpoints?format=xml' %\
619
            quote(self.user1.auth_token)
620
        headers = {'HTTP_X_AUTH_TOKEN': self.user1.auth_token}
621
        r = client.get(url, **headers)
622
        self.assertEqual(r.status_code, 200)
623
        self.assertEqual(r['Content-Type'], 'application/xml; charset=UTF-8')
624
#        try:
625
#            body = minidom.parseString(r.content)
626
#        except Exception, e:
627
#            self.fail('xml format expected')
628
        endpoints = body.get('endpoints')
629
        self.assertEqual(len(endpoints), 3)
630

  
631
        # Check limit
632
        url = '/astakos/api/tokens/%s/endpoints?limit=2' %\
633
            quote(self.user1.auth_token)
634
        headers = {'HTTP_X_AUTH_TOKEN': self.user1.auth_token}
635
        r = client.get(url, **headers)
636
        self.assertEqual(r.status_code, 200)
637
        body = json.loads(r.content)
638
        endpoints = body.get('endpoints')
639
        self.assertEqual(len(endpoints), 2)
640

  
641
        endpoint_link = body.get('endpoint_links', [])[0]
642
        next = endpoint_link.get('href')
643
        p = urlparse(next)
644
        params = parse_qs(p.query)
645
        self.assertTrue('limit' in params)
646
        self.assertTrue('marker' in params)
647
        self.assertEqual(params['marker'][0], '2')
648

  
649
        # Check marker
650
        headers = {'HTTP_X_AUTH_TOKEN': self.user1.auth_token}
651
        r = client.get(next, **headers)
652
        self.assertEqual(r.status_code, 200)
653
        body = json.loads(r.content)
654
        endpoints = body.get('endpoints')
655
        self.assertEqual(len(endpoints), 1)
656

  
597 657

  
598 658
class WrongPathAPITest(TestCase):
599 659
    def test_catch_wrong_account_paths(self, *args):
......
612 672
        response = self.client.get(path)
613 673
        self.assertEqual(response.status_code, 400)
614 674
        try:
615
            error = json.loads(response.content)
675
            json.loads(response.content)
616 676
        except ValueError:
617 677
            self.assertTrue(False)

Also available in: Unified diff