本文整理汇总了Python中integration.ggrc.Api.login_as_external方法的典型用法代码示例。如果您正苦于以下问题:Python Api.login_as_external方法的具体用法?Python Api.login_as_external怎么用?Python Api.login_as_external使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类integration.ggrc.Api
的用法示例。
在下文中一共展示了Api.login_as_external方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: TestFolderField
# 需要导入模块: from integration.ggrc import Api [as 别名]
# 或者: from integration.ggrc.Api import login_as_external [as 别名]
#.........这里部分代码省略.........
factories.FacilityFactory,
factories.IssueFactory,
factories.KeyReportFactory,
factories.MarketFactory,
factories.MetricFactory,
factories.ObjectiveFactory,
factories.OrgGroupFactory,
factories.PolicyFactory,
factories.ProcessFactory,
factories.ProductFactory,
factories.ProductGroupFactory,
factories.ProgramFactory,
factories.ProjectFactory,
factories.RegulationFactory,
factories.RequirementFactory,
factories.RiskFactory,
factories.StandardFactory,
factories.SystemFactory,
factories.TechnologyEnvironmentFactory,
factories.ThreatFactory,
factories.VendorFactory,
]
def setUp(self):
super(TestFolderField, self).setUp()
self.api = Api()
self.api.login_as_normal()
@ddt.data(*FOLDERABLE_FACTORIES)
def test_create_object(self, factory):
"""Test create folder field for {0._meta.model.__name__}."""
test_folder_name = "tmp_folder_create_name"
self.assertEqual(
test_folder_name,
factory(folder=test_folder_name).folder
)
@ddt.data(*FOLDERABLE_FACTORIES)
def test_get_object(self, factory):
"""Test get folder field for {0._meta.model.__name__}."""
test_folder_name = "tmp_folder_get_name"
obj = factory(folder=test_folder_name)
data = self.api.get(obj, obj.id).json
self.assertEqual(
test_folder_name,
data[obj._inflector.table_singular.lower()]["folder"]
)
NOT_PUTABLE_FACTORIES = NOT_POSTABLE_FACTORIES = [
factories.DirectiveFactory,
]
@ddt.data(*FOLDERABLE_FACTORIES)
def test_put_object(self, factory):
"""Test put folder field for {0._meta.model.__name__}."""
test_folder_name = "tmp_folder_put_name"
obj = factory(folder=test_folder_name)
update_test_folder_name = "upd_tmp_folder_put_name"
obj_id = obj.id
if factory in self.NOT_PUTABLE_FACTORIES:
with self.assertRaises(NotImplementedError):
self.api.put(obj, {"folder": update_test_folder_name})
else:
if isinstance(obj, Synchronizable):
# Currently external user can't modify folder field
# because of WithProtectedAttributes mixin
return
self.api.put(obj, {"folder": update_test_folder_name})
self.assertEqual(
update_test_folder_name,
obj.__class__.query.get(obj_id).folder
)
@ddt.data(*FOLDERABLE_FACTORIES)
def test_post_object(self, factory):
"""Test post folder field for {0._meta.model.__name__}."""
test_folder_name = "tmp_folder_put_name"
obj = factory(folder=test_folder_name)
obj_id = obj.id
key = obj._inflector.table_singular.lower()
post_data = self.api.get(obj, obj.id).json
model = obj.__class__
db.session.delete(obj)
db.session.commit()
del post_data[key]["id"]
if factory in self.NOT_POSTABLE_FACTORIES:
with self.assertRaises(NotImplementedError):
self.api.post(model, post_data)
else:
if isinstance(obj, Synchronizable):
self.api.login_as_external()
resp = self.api.post(model, post_data)
new_obj_id = resp.json[key]["id"]
self.assertNotEqual(obj_id, new_obj_id)
self.assertEqual(
test_folder_name,
model.query.get(new_obj_id).folder
)