def test_get_storage_url_returns_expected_value( self, mock_tmp_auth_conn, mock_storage_auth_token_conn ): auth = FileArchiveAuth( mock_tmp_auth_conn, TEST_USER_ID, TEST_DEVICE_GUID, TEST_DESTINATION_GUID ) assert auth.get_storage_url() == "testhost.com"
def test_clear_credentials_causes_auth_api_to_be_called_on_subsequent_calls( self, mock_tmp_auth_conn, mock_request, mock_storage_auth_token_conn): auth = FileArchiveAuth(mock_tmp_auth_conn, TEST_USER_ID, TEST_DEVICE_GUID, TEST_DESTINATION_GUID) auth(mock_request) assert mock_tmp_auth_conn.post.call_count == 1 assert mock_storage_auth_token_conn.post.call_count == 1 auth.clear_credentials() auth(mock_request) assert mock_tmp_auth_conn.post.call_count == 2 assert mock_storage_auth_token_conn.post.call_count == 2
def test_call_returns_request_with_expected_header( self, mock_tmp_auth_conn, mock_request, mock_storage_auth_token_conn): auth = FileArchiveAuth(mock_tmp_auth_conn, TEST_USER_ID, TEST_DEVICE_GUID, TEST_DESTINATION_GUID) request = auth(mock_request) assert request.headers["Authorization"] == "token TEST_V1-TOKEN_VALUE"
def test_call_only_calls_auth_apis_first_time( self, mock_tmp_auth_conn, mock_request, mock_storage_auth_token_conn): auth = FileArchiveAuth(mock_tmp_auth_conn, TEST_USER_ID, TEST_DEVICE_GUID, TEST_DESTINATION_GUID) auth(mock_request) assert mock_tmp_auth_conn.post.call_count == 1 assert mock_storage_auth_token_conn.post.call_count == 1 auth(mock_request) assert mock_tmp_auth_conn.post.call_count == 1 assert mock_storage_auth_token_conn.post.call_count == 1
def test_call_calls_auth_apis_with_expected_urls( self, mock_tmp_auth_conn, mock_request, mock_storage_auth_token_conn): auth = FileArchiveAuth(mock_tmp_auth_conn, TEST_USER_ID, TEST_DEVICE_GUID, TEST_DESTINATION_GUID) auth(mock_request) data = { u"userId": TEST_USER_ID, u"sourceGuid": TEST_DEVICE_GUID, u"destinationGuid": TEST_DESTINATION_GUID, } mock_tmp_auth_conn.post.assert_called_once_with("/api/LoginToken", json=data) mock_storage_auth_token_conn.post.assert_called_once_with( "api/AuthToken", headers={"Authorization": "login_token TEST_TMP_TOKEN_VALUE"}, )
def create_archive_service(self, device_guid, destination_guid): auth = FileArchiveAuth(self._connection, u"my", device_guid, destination_guid) conn = self._connection_manager.get_storage_connection(auth) return StorageArchiveService(conn)