コード例 #1
0
ファイル: test_auth.py プロジェクト: code42/py42
 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"
コード例 #2
0
 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
コード例 #3
0
 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"
コード例 #4
0
 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
コード例 #5
0
 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"},
     )
コード例 #6
0
 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)