本文整理汇总了Python中website.addons.googledrive.tests.factories.GoogleDriveNodeSettingsFactory.serialize_waterbutler_credentials方法的典型用法代码示例。如果您正苦于以下问题:Python GoogleDriveNodeSettingsFactory.serialize_waterbutler_credentials方法的具体用法?Python GoogleDriveNodeSettingsFactory.serialize_waterbutler_credentials怎么用?Python GoogleDriveNodeSettingsFactory.serialize_waterbutler_credentials使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类website.addons.googledrive.tests.factories.GoogleDriveNodeSettingsFactory
的用法示例。
在下文中一共展示了GoogleDriveNodeSettingsFactory.serialize_waterbutler_credentials方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: TestGoogleDriveNodeSettingsModel
# 需要导入模块: from website.addons.googledrive.tests.factories import GoogleDriveNodeSettingsFactory [as 别名]
# 或者: from website.addons.googledrive.tests.factories.GoogleDriveNodeSettingsFactory import serialize_waterbutler_credentials [as 别名]
#.........这里部分代码省略.........
assert_is(self.node_settings.folder_id, None)
assert_is(self.node_settings.user_settings, None)
last_log = self.project.logs[-1]
params = last_log.params
assert_in('node', params)
assert_in('folder', params)
assert_in('project', params)
assert_equal(last_log.action, 'googledrive_node_deauthorized')
def test_set_folder(self):
folder_name = {
'id': '1234',
'name': 'freddie',
'path': 'queen/freddie',
}
self.node_settings.set_folder(folder_name, auth=Auth(self.user))
self.node_settings.save()
# Folder was set
assert_equal(self.node_settings.folder_name, folder_name['name'])
# Log was saved
last_log = self.project.logs[-1]
assert_equal(last_log.action, 'googledrive_folder_selected')
def test_set_user_auth(self):
node_settings = GoogleDriveNodeSettingsFactory()
user_settings = GoogleDriveUserSettingsFactory()
node_settings.set_user_auth(user_settings)
node_settings.save()
assert_true(node_settings.has_auth)
assert_equal(node_settings.user_settings, user_settings)
# A log was saved
last_log = node_settings.owner.logs[-1]
log_params = last_log.params
assert_equal(last_log.user, user_settings.owner)
assert_equal(log_params['folder'], node_settings.folder_path)
assert_equal(last_log.action, 'googledrive_node_authorized')
assert_equal(log_params['node'], node_settings.owner._primary_key)
def test_serialize_credentials(self):
self.user_settings.access_token = 'secret'
self.user_settings.save()
credentials = self.node_settings.serialize_waterbutler_credentials()
expected = {'token': self.node_settings.user_settings.access_token}
assert_equal(credentials, expected)
def test_serialize_credentials_not_authorized(self):
self.node_settings.user_settings = None
self.node_settings.save()
with assert_raises(exceptions.AddonError):
self.node_settings.serialize_waterbutler_credentials()
def test_serialize_settings(self):
self.node_settings.folder_path = 'camera uploads/pizza.nii'
self.node_settings.save()
settings = self.node_settings.serialize_waterbutler_settings()
expected = {
'folder': {
'id': '12345',
'name': 'pizza.nii',
'path': 'camera uploads/pizza.nii',
}
}
assert_equal(settings, expected)
def test_serialize_settings_not_configured(self):
self.node_settings.folder_id = None
self.node_settings.save()
with assert_raises(exceptions.AddonError):
self.node_settings.serialize_waterbutler_settings()
def test_create_log(self):
action = 'file_added'
path = '12345/camera uploads/pizza.nii'
nlog = len(self.project.logs)
self.node_settings.create_waterbutler_log(
auth=Auth(user=self.user),
action=action,
metadata={'path': path},
)
self.project.reload()
assert_equal(len(self.project.logs), nlog + 1)
assert_equal(
self.project.logs[-1].action,
'googledrive_{0}'.format(action),
)
assert_equal(self.project.logs[-1].params['path'], path)