Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions tb_rest_client/rest_client_pe.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ def token_login(self, token, refresh_token=None):
super(RestClientPE, self).token_login(token=token, refresh_token=refresh_token)
self.__load_controllers()

def api_key_login(self, api_key: str):
super(RestClientPE, self).api_key_login(api_key=api_key)
self.__load_controllers()

# Self Registration Controller
def get_privacy_policy(self, ) -> str:
return self.self_registration_controller.get_privacy_policy_using_get()
Expand Down
38 changes: 38 additions & 0 deletions test/test_rest_client_pe_api_key_login.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# Copyright 2026. ThingsBoard
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import unittest

from tb_rest_client.api.api_ce.device_controller_api import DeviceControllerApi as CEDeviceControllerApi
from tb_rest_client.api.api_pe.device_controller_api import DeviceControllerApi
from tb_rest_client.api.api_pe.self_registration_controller_api import SelfRegistrationControllerApi
from tb_rest_client.rest_client_pe import RestClientPE


class RestClientPEApiKeyLoginTests(unittest.TestCase):

def test_api_key_login_loads_pe_controllers(self):
client = RestClientPE("http://localhost:8080")

client.api_key_login("test-api-key")

self.assertEqual("ApiKey", client.configuration.api_key_prefix["X-Authorization"])
self.assertEqual("test-api-key", client.configuration.api_key["X-Authorization"])
self.assertIsInstance(client.device_controller, DeviceControllerApi)
self.assertNotIsInstance(client.device_controller, CEDeviceControllerApi)
self.assertIsInstance(client.self_registration_controller, SelfRegistrationControllerApi)


if __name__ == '__main__':
unittest.main()