本文整理汇总了Python中settings.Settings.set_device_token方法的典型用法代码示例。如果您正苦于以下问题:Python Settings.set_device_token方法的具体用法?Python Settings.set_device_token怎么用?Python Settings.set_device_token使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类settings.Settings
的用法示例。
在下文中一共展示了Settings.set_device_token方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_device_token_expired
# 需要导入模块: from settings import Settings [as 别名]
# 或者: from settings.Settings import set_device_token [as 别名]
def test_device_token_expired(self):
settings = Settings(TestBase.US_app_id)
settings.set_device_token({"accessToken": "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJleHAiOiIyMDE1LTExLTExVDAzOjM0OjU4LjE2Mjg2NzlaIiwibCI6ImJiYmJ2LnJwZGJ2eGJnR3JNZyIsImEiOiJiYmJiYmMueGdqYnZQZHdrbGx3IiwidSI6bnVsbCwiZCI6ImJsai5sRHBGd0tNc2dGRk0ifQ.l4ob5liSYfgI25mnysjRHpgCYr1yCzayC4XjHJOv4v0",
"accessTokenExpires": self.past_javascript_access_token_expires()})
client = buddy.init(TestBase.US_app_id, TestBase.US_app_key, "test_device_token_expired")
buddy.post("/metrics/events/key", {})
self.assertIsNotNone(client.get_access_token_string())
示例2: test_bad_device_token
# 需要导入模块: from settings import Settings [as 别名]
# 或者: from settings.Settings import set_device_token [as 别名]
def test_bad_device_token(self):
settings = Settings(TestBase.US_app_id)
settings.set_device_token({"accessToken": "bad device token",
"accessTokenExpires": self.future_javascript_access_token_expires()})
client = buddy.init(TestBase.US_app_id, TestBase.US_app_key, "test_bad_device_token")
buddy.post("/metrics/events/key", {})
self.assertIsNotNone(client.get_access_token_string())
示例3: test_Settings_access_token_expired
# 需要导入模块: from settings import Settings [as 别名]
# 或者: from settings.Settings import set_device_token [as 别名]
def test_Settings_access_token_expired(self):
settings = Settings(Test3._app_id)
json = {"accessToken": Test3._access_token,
"accessTokenExpires": self.past_javascript_access_token_expires(),
"serviceRoot": Test3._service_root}
settings.set_device_token(json)
self.assertEqual(settings.access_token_string, None)
示例4: BuddyClient
# 需要导入模块: from settings import Settings [as 别名]
# 或者: from settings.Settings import set_device_token [as 别名]
class BuddyClient(object):
exception_name = u"exception"
_result_name = u"result"
_hardware_info_file_name = "/proc/cpuinfo"
def __init__(self, app_id, app_key):
self._app_id = app_id
self._app_key = app_key
self._settings = Settings(self._app_id)
self._session = requests.Session()
self._session.auth = Auth(self, self._settings)
self._last_location = None
self._service_exception = Events()
self._authentication_needed = Events()
self._connection_changed = Events()
self._connection_retry = Thread(target=self.__connection_retry_method)
self._connection_level = Connection.on
@property
def app_id(self):
return self._app_id
@property
def app_key(self):
return self._app_key
@property
def last_location(self):
return self._last_location
@last_location.setter
def last_location(self, value):
self._last_location = value
@property
def current_user_id(self):
return self._settings.user_id
@property
def service_exception(self):
return self._service_exception
@property
def authentication_needed(self):
return self._authentication_needed
@property
def connection_changed(self):
return self._connection_changed
def get_access_token_string(self):
if self._settings.access_token_string is None:
self.__register_device()
return self._settings.access_token_string
def __register_device(self):
response = self.__handle_dictionary_request(requests.post, "/devices", {
"appId": self.app_id,
"appKey": self.app_key,
"platform": BuddyClient.__get_platform(),
"model": BuddyClient.__get_model(),
"osVersion": BuddyClient.__get_os_version(),
"uniqueId": self.__get_unique_id(),
})
if response[BuddyClient.exception_name] is None:
self._settings.set_device_token(response[BuddyClient._result_name])
@staticmethod
def __get_platform():
return sys.platform
@staticmethod
def __get_model():
hardware = BuddyClient.__get_cpuinfo("Hardware")
revision = BuddyClient.__get_cpuinfo("Revision")
if hardware is None:
return "Hardware info not available"
else:
return hardware + "-" + revision
@staticmethod
def __get_os_version():
return platform.release()
def __get_unique_id(self):
unique_id = BuddyClient.__get_cpuinfo("Serial")
if unique_id is None:
unique_id = uuid.getnode()
return unique_id
@staticmethod
def __get_cpuinfo(key):
try:
with open(BuddyClient._hardware_info_file_name, "r") as hardware_file:
for line in hardware_file:
if line.startswith(key):
#.........这里部分代码省略.........