from __future__ import unicode_literals

from alexia.test import APITestCase

from ..common import format_authorization


class AuthorizationTest(APITestCase):
    def test_authorization_list_empty(self):
        """
        Test the authorization.list call with no authorizations.
        """
        self.send_and_compare_request('authorization.list', [], [])
        self.send_and_compare_request('authorization.list', [self.data['user1'].username], [])
        self.send_and_compare_request('authorization.list', [self.data['user2'].username], [])

    def test_authorization_list(self):
        """
        Test the authorization.list call.
        """
        self.load_billing_data()

        auth = self.data['authorization1']
        auth_json = format_authorization(auth)

        self.send_and_compare_request('authorization.list', [], [auth_json])
        self.send_and_compare_request('authorization.list', [self.data['user1'].username], [auth_json])
        self.send_and_compare_request('authorization.list', [self.data['user2'].username], [])

    def test_authorization_list_invalid_user(self):
        """
        Test the authorization.list call with invalid username.
        """
        # Invalid user
        self.send_and_compare_request_error('authorization.list', ['invalidusername'],
                                            status_code=404,
                                            error_code=404,
                                            error_name='ObjectNotFoundError',
                                            error_message='ObjectNotFoundError: User with provided ' +
                                                          'radius_username does not exists',
                                            )

@@ -1356,26 +1356,26 @@
 tatus_code=4
-04
+22
 ,%0A          
@@ -1423,11 +1423,14 @@
 ode=
-404
+-32602
 ,%0A  
@@ -1483,30 +1483,29 @@
 r_name='
-ObjectNotFound
+InvalidParams
 Error',%0A
@@ -1567,22 +1567,21 @@
 ge='
-ObjectNotFound
+InvalidParams
 Erro
@@ -1669,15 +1669,8 @@
    '
-radius_
 user

Fix authorization test