class UsernamePasswordAuthRequestTestCase(RequestTestCase):
    def setUp(self):
        self.username = "******"
        self.password = "******"
        self.account_name = "Account Name"
        self.hashed_credentials = "133e1b8eda335c4c7f7a508620ca7f10"
        self.req_obj = UsernamePasswordAuthRequest(self.username,
                                                   self.password,
                                                   self.account_name)

    def test_request_hits_correct_url(self):
        with mock.patch("requests.put") as mock_put:
            self.req_obj.execute("http://testserver")
            mock_put.assert_called_with("http://testserver/user_auth",
                                        headers=mock.ANY,
                                        data=mock.ANY)

    def test_request_sends_correct_data(self):
        with mock.patch('requests.put') as mock_put:
            expected_data = {
                "credentials": self.hashed_credentials,
                "account_name": self.account_name,
            }
            self.req_obj.execute("http://testserver")
            self.assert_data(mock_put, expected_data)
class UsernamePasswordAuthRequestTestCase(RequestTestCase):

    def setUp(self):
        self.username = "******"
        self.password = "******"
        self.account_name = "Account Name"
        self.hashed_credentials = "133e1b8eda335c4c7f7a508620ca7f10"
        self.req_obj = UsernamePasswordAuthRequest(
            self.username, self.password, self.account_name)

    def test_request_hits_correct_url(self):
        with mock.patch("requests.put") as mock_put:
            self.req_obj.execute("http://testserver")
            mock_put.assert_called_with("http://testserver/user_auth",
                                        headers=mock.ANY,
                                        data=mock.ANY)

    def test_request_sends_correct_data(self):
        with mock.patch('requests.put') as mock_put:
            expected_data = {
                "credentials": self.hashed_credentials,
                "account_name": self.account_name,
            }
            self.req_obj.execute("http://testserver")
            self.assert_data(mock_put, expected_data)
 def setUp(self):
     self.username = "******"
     self.password = "******"
     self.account_name = "Account Name"
     self.hashed_credentials = "133e1b8eda335c4c7f7a508620ca7f10"
     self.req_obj = UsernamePasswordAuthRequest(self.username,
                                                self.password,
                                                self.account_name)
 def setUp(self):
     self.username = "******"
     self.password = "******"
     self.account_name = "Account Name"
     self.hashed_credentials = "133e1b8eda335c4c7f7a508620ca7f10"
     self.req_obj = UsernamePasswordAuthRequest(
         self.username, self.password, self.account_name)
Beispiel #5
0
    def __init__(self,
                 api_key=None,
                 password=None,
                 account_name=None,
                 username=None):
        if not api_key and not password:
            raise RuntimeError("You must pass either an api_key or an "
                               "account name/password pair")

        if password or account_name or username:
            if not (password and account_name and username):
                raise RuntimeError("If using account name/password "
                                   "authentication then you must specify "
                                   "password, userame and account_name "
                                   "arguments")
            self.auth_request = UsernamePasswordAuthRequest(
                username, password, account_name)
        else:
            self.auth_request = ApiKeyAuthRequest(api_key)

        self.api_key = api_key
        self._authenticated = False
        self.auth_token = None