本文整理汇总了Python中core.model.ConfigurationSetting.for_library_and_externalintegration方法的典型用法代码示例。如果您正苦于以下问题:Python ConfigurationSetting.for_library_and_externalintegration方法的具体用法?Python ConfigurationSetting.for_library_and_externalintegration怎么用?Python ConfigurationSetting.for_library_and_externalintegration使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类core.model.ConfigurationSetting
的用法示例。
在下文中一共展示了ConfigurationSetting.for_library_and_externalintegration方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_domains
# 需要导入模块: from core.model import ConfigurationSetting [as 别名]
# 或者: from core.model.ConfigurationSetting import for_library_and_externalintegration [as 别名]
def test_domains(self):
super(TestGoogleOAuthAdminAuthenticationProvider, self).setup()
auth_integration, ignore = create(
self._db, ExternalIntegration,
protocol=ExternalIntegration.GOOGLE_OAUTH,
goal=ExternalIntegration.ADMIN_AUTH_GOAL
)
auth_integration.libraries += [self._default_library]
ConfigurationSetting.for_library_and_externalintegration(
self._db, "domains", self._default_library, auth_integration
).value = json.dumps(["nypl.org"])
google = GoogleOAuthAdminAuthenticationProvider(auth_integration, "", test_mode=True)
eq_(["nypl.org"], google.domains.keys())
eq_([self._default_library], google.domains["nypl.org"])
l2 = self._library()
auth_integration.libraries += [l2]
ConfigurationSetting.for_library_and_externalintegration(
self._db, "domains", l2, auth_integration
).value = json.dumps(["nypl.org", "l2.org"])
eq_(set([self._default_library, l2]), set(google.domains["nypl.org"]))
eq_([l2], google.domains["l2.org"])
开发者ID:NYPL-Simplified,项目名称:circulation,代码行数:27,代码来源:test_google_oauth_admin_authentication_provider.py
示例2: test_catalog_services_get_with_marc_exporter
# 需要导入模块: from core.model import ConfigurationSetting [as 别名]
# 或者: from core.model.ConfigurationSetting import for_library_and_externalintegration [as 别名]
def test_catalog_services_get_with_marc_exporter(self):
integration, ignore = create(
self._db, ExternalIntegration,
protocol=ExternalIntegration.MARC_EXPORT,
goal=ExternalIntegration.CATALOG_GOAL,
name="name",
)
integration.setting(MARCExporter.STORAGE_PROTOCOL).value = ExternalIntegration.S3
integration.libraries += [self._default_library]
ConfigurationSetting.for_library_and_externalintegration(
self._db, MARCExporter.MARC_ORGANIZATION_CODE,
self._default_library, integration).value = "US-MaBoDPL"
ConfigurationSetting.for_library_and_externalintegration(
self._db, MARCExporter.INCLUDE_SUMMARY,
self._default_library, integration).value = "false"
ConfigurationSetting.for_library_and_externalintegration(
self._db, MARCExporter.INCLUDE_SIMPLIFIED_GENRES,
self._default_library, integration).value = "true"
with self.request_context_with_admin("/"):
response = self.manager.admin_catalog_services_controller.process_catalog_services()
[service] = response.get("catalog_services")
eq_(integration.id, service.get("id"))
eq_(integration.name, service.get("name"))
eq_(integration.protocol, service.get("protocol"))
eq_(ExternalIntegration.S3, service.get("settings").get(MARCExporter.STORAGE_PROTOCOL))
[library] = service.get("libraries")
eq_(self._default_library.short_name, library.get("short_name"))
eq_("US-MaBoDPL", library.get(MARCExporter.MARC_ORGANIZATION_CODE))
eq_("false", library.get(MARCExporter.INCLUDE_SUMMARY))
eq_("true", library.get(MARCExporter.INCLUDE_SIMPLIFIED_GENRES))
示例3: test_catalog_services_post_create
# 需要导入模块: from core.model import ConfigurationSetting [as 别名]
# 或者: from core.model.ConfigurationSetting import for_library_and_externalintegration [as 别名]
def test_catalog_services_post_create(self):
ME = MARCExporter
s3, ignore = create(
self._db, ExternalIntegration,
protocol=ExternalIntegration.S3,
goal=ExternalIntegration.STORAGE_GOAL,
)
s3.setting(S3Uploader.MARC_BUCKET_KEY).value = "marc-files"
with self.request_context_with_admin("/", method="POST"):
flask.request.form = MultiDict([
("name", "exporter name"),
("protocol", ME.NAME),
(ME.STORAGE_PROTOCOL, ExternalIntegration.S3),
("libraries", json.dumps([{
"short_name": self._default_library.short_name,
ME.INCLUDE_SUMMARY: "false",
ME.INCLUDE_SIMPLIFIED_GENRES: "true",
}])),
])
response = self.manager.admin_catalog_services_controller.process_catalog_services()
eq_(response.status_code, 201)
service = get_one(self._db, ExternalIntegration, goal=ExternalIntegration.CATALOG_GOAL)
eq_(service.id, int(response.response[0]))
eq_(ME.NAME, service.protocol)
eq_("exporter name", service.name)
eq_(ExternalIntegration.S3, service.setting(ME.STORAGE_PROTOCOL).value)
eq_([self._default_library], service.libraries)
eq_("false", ConfigurationSetting.for_library_and_externalintegration(
self._db, ME.INCLUDE_SUMMARY, self._default_library, service).value)
eq_("true", ConfigurationSetting.for_library_and_externalintegration(
self._db, ME.INCLUDE_SIMPLIFIED_GENRES, self._default_library, service).value)
示例4: test_callback
# 需要导入模块: from core.model import ConfigurationSetting [as 别名]
# 或者: from core.model.ConfigurationSetting import for_library_and_externalintegration [as 别名]
def test_callback(self):
super(TestGoogleOAuthAdminAuthenticationProvider, self).setup()
auth_integration, ignore = create(
self._db, ExternalIntegration,
protocol=ExternalIntegration.GOOGLE_OAUTH,
goal=ExternalIntegration.ADMIN_AUTH_GOAL
)
self.google = GoogleOAuthAdminAuthenticationProvider(auth_integration, "", test_mode=True)
auth_integration.libraries += [self._default_library]
ConfigurationSetting.for_library_and_externalintegration(
self._db, "domains", self._default_library, auth_integration
).value = json.dumps(["nypl.org"])
# Returns a problem detail when Google returns an error.
error_response, redirect = self.google.callback(self._db, {'error' : 'access_denied'})
eq_(True, isinstance(error_response, ProblemDetail))
eq_(400, error_response.status_code)
eq_(True, error_response.detail.endswith('access_denied'))
eq_(None, redirect)
# Successful case creates a dict of admin details
success, redirect = self.google.callback(self._db, {'code' : 'abc'})
eq_('[email protected]', success['email'])
default_credentials = json.dumps({"id_token": {"email": "[email protected]", "hd": "nypl.org"}})
eq_(default_credentials, success['credentials'])
eq_(GoogleOAuthAdminAuthenticationProvider.NAME, success["type"])
[role] = success.get("roles")
eq_(AdminRole.LIBRARIAN, role.get("role"))
eq_(self._default_library.short_name, role.get("library"))
# If domains are set, the admin's domain must match one of the domains.
setting = ConfigurationSetting.for_library_and_externalintegration(
self._db, "domains", self._default_library, auth_integration)
setting.value = json.dumps(["otherlibrary.org"])
failure, ignore = self.google.callback(self._db, {'code' : 'abc'})
eq_(INVALID_ADMIN_CREDENTIALS, failure)
setting.value = json.dumps(["nypl.org"])
# Returns a problem detail when the oauth client library
# raises an exception.
class ExceptionRaisingClient(DummyGoogleClient):
def step2_exchange(self, auth_code):
raise GoogleClient.FlowExchangeError("mock error")
self.google.dummy_client = ExceptionRaisingClient()
error_response, redirect = self.google.callback(self._db, {'code' : 'abc'})
eq_(True, isinstance(error_response, ProblemDetail))
eq_(400, error_response.status_code)
eq_(True, error_response.detail.endswith('mock error'))
eq_(None, redirect)
开发者ID:NYPL-Simplified,项目名称:circulation,代码行数:51,代码来源:test_google_oauth_admin_authentication_provider.py
示例5: check_identifier_restriction
# 需要导入模块: from core.model import ConfigurationSetting [as 别名]
# 或者: from core.model.ConfigurationSetting import for_library_and_externalintegration [as 别名]
def check_identifier_restriction(self, library, auth_service):
"""Check whether the library's identifier restriction regular expression is set and
is supposed to be a regular expression; if so, check that it's valid."""
identifier_restriction_type = ConfigurationSetting.for_library_and_externalintegration(
self._db, AuthenticationProvider.LIBRARY_IDENTIFIER_RESTRICTION_TYPE,
library, auth_service).value
identifier_restriction = ConfigurationSetting.for_library_and_externalintegration(
self._db, AuthenticationProvider.LIBRARY_IDENTIFIER_RESTRICTION,
library, auth_service).value
if identifier_restriction and identifier_restriction_type == AuthenticationProvider.LIBRARY_IDENTIFIER_RESTRICTION_TYPE_REGEX:
try:
re.compile(identifier_restriction)
except Exception, e:
return INVALID_LIBRARY_IDENTIFIER_RESTRICTION_REGULAR_EXPRESSION
示例6: test_discovery_service_library_registrations_get
# 需要导入模块: from core.model import ConfigurationSetting [as 别名]
# 或者: from core.model.ConfigurationSetting import for_library_and_externalintegration [as 别名]
def test_discovery_service_library_registrations_get(self):
discovery_service, ignore = create(
self._db, ExternalIntegration,
protocol=ExternalIntegration.OPDS_REGISTRATION,
goal=ExternalIntegration.DISCOVERY_GOAL,
)
succeeded, ignore = create(
self._db, Library, name="Library 1", short_name="L1",
)
ConfigurationSetting.for_library_and_externalintegration(
self._db, "library-registration-status", succeeded, discovery_service,
).value = "success"
ConfigurationSetting.for_library_and_externalintegration(
self._db, "library-registration-stage", succeeded, discovery_service,
).value = "production"
failed, ignore = create(
self._db, Library, name="Library 2", short_name="L2",
)
ConfigurationSetting.for_library_and_externalintegration(
self._db, "library-registration-status", failed, discovery_service,
).value = "failure"
ConfigurationSetting.for_library_and_externalintegration(
self._db, "library-registration-stage", failed, discovery_service,
).value = "testing"
unregistered, ignore = create(
self._db, Library, name="Library 3", short_name="L3",
)
discovery_service.libraries = [succeeded, failed]
controller = self.manager.admin_discovery_service_library_registrations_controller
with self.request_context_with_admin("/", method="GET"):
response = controller.process_discovery_service_library_registrations()
serviceInfo = response.get("library_registrations")
eq_(1, len(serviceInfo))
eq_(discovery_service.id, serviceInfo[0].get("id"))
libraryInfo = serviceInfo[0].get("libraries")
expected = [
dict(short_name=succeeded.short_name, status="success", stage="production"),
dict(short_name=failed.short_name, status="failure", stage="testing"),
]
eq_(expected, libraryInfo)
self.admin.remove_role(AdminRole.SYSTEM_ADMIN)
self._db.flush()
assert_raises(AdminNotAuthorized,
controller.process_discovery_service_library_registrations)
示例7: test_admin_auth_services_get_with_google_oauth_service
# 需要导入模块: from core.model import ConfigurationSetting [as 别名]
# 或者: from core.model.ConfigurationSetting import for_library_and_externalintegration [as 别名]
def test_admin_auth_services_get_with_google_oauth_service(self):
auth_service, ignore = create(
self._db, ExternalIntegration,
protocol=ExternalIntegration.GOOGLE_OAUTH,
goal=ExternalIntegration.ADMIN_AUTH_GOAL
)
auth_service.url = "http://oauth.test"
auth_service.username = "user"
auth_service.password = "pass"
auth_service.libraries += [self._default_library]
ConfigurationSetting.for_library_and_externalintegration(
self._db, "domains", self._default_library, auth_service
).value = json.dumps(["nypl.org"])
with self.request_context_with_admin("/"):
response = self.manager.admin_auth_services_controller.process_admin_auth_services()
[service] = response.get("admin_auth_services")
eq_(auth_service.id, service.get("id"))
eq_(auth_service.name, service.get("name"))
eq_(auth_service.protocol, service.get("protocol"))
eq_(auth_service.url, service.get("settings").get("url"))
eq_(auth_service.username, service.get("settings").get("username"))
eq_(auth_service.password, service.get("settings").get("password"))
[library_info] = service.get("libraries")
eq_(self._default_library.short_name, library_info.get("short_name"))
eq_(["nypl.org"], library_info.get("domains"))
示例8: test_admin_auth_services_post_google_oauth_edit
# 需要导入模块: from core.model import ConfigurationSetting [as 别名]
# 或者: from core.model.ConfigurationSetting import for_library_and_externalintegration [as 别名]
def test_admin_auth_services_post_google_oauth_edit(self):
# The auth service exists.
auth_service, ignore = create(
self._db, ExternalIntegration,
protocol=ExternalIntegration.GOOGLE_OAUTH,
goal=ExternalIntegration.ADMIN_AUTH_GOAL
)
auth_service.url = "url"
auth_service.username = "user"
auth_service.password = "pass"
auth_service.libraries += [self._default_library]
setting = ConfigurationSetting.for_library_and_externalintegration(
self._db, "domains", self._default_library, auth_service)
setting.value = json.dumps(["library1.org"])
with self.request_context_with_admin("/", method="POST"):
flask.request.form = MultiDict([
("name", "oauth"),
("protocol", "Google OAuth"),
("url", "http://url2"),
("username", "user2"),
("password", "pass2"),
("libraries", json.dumps([{ "short_name": self._default_library.short_name,
"domains": ["library2.org"] }])),
])
response = self.manager.admin_auth_services_controller.process_admin_auth_services()
eq_(response.status_code, 200)
eq_(auth_service.protocol, response.response[0])
eq_("oauth", auth_service.name)
eq_("http://url2", auth_service.url)
eq_("user2", auth_service.username)
eq_("domains", setting.key)
eq_(["library2.org"], json.loads(setting.value))
示例9: test_admin_auth_services_post_create
# 需要导入模块: from core.model import ConfigurationSetting [as 别名]
# 或者: from core.model.ConfigurationSetting import for_library_and_externalintegration [as 别名]
def test_admin_auth_services_post_create(self):
with self.request_context_with_admin("/", method="POST"):
flask.request.form = MultiDict([
("name", "oauth"),
("protocol", "Google OAuth"),
("url", "http://url2"),
("username", "username"),
("password", "password"),
("libraries", json.dumps([{ "short_name": self._default_library.short_name,
"domains": ["nypl.org", "gmail.com"] }])),
])
response = self.manager.admin_auth_services_controller.process_admin_auth_services()
eq_(response.status_code, 201)
# The auth service was created and configured properly.
auth_service = ExternalIntegration.admin_authentication(self._db)
eq_(auth_service.protocol, response.response[0])
eq_("oauth", auth_service.name)
eq_("http://url2", auth_service.url)
eq_("username", auth_service.username)
eq_("password", auth_service.password)
eq_([self._default_library], auth_service.libraries)
setting = ConfigurationSetting.for_library_and_externalintegration(
self._db, "domains", self._default_library, auth_service
)
eq_("domains", setting.key)
eq_(["nypl.org", "gmail.com"], json.loads(setting.value))
示例10: test_staff_email
# 需要导入模块: from core.model import ConfigurationSetting [as 别名]
# 或者: from core.model.ConfigurationSetting import for_library_and_externalintegration [as 别名]
def test_staff_email(self):
super(TestGoogleOAuthAdminAuthenticationProvider, self).setup()
auth_integration, ignore = create(
self._db, ExternalIntegration,
protocol=ExternalIntegration.GOOGLE_OAUTH,
goal=ExternalIntegration.ADMIN_AUTH_GOAL
)
nypl_admin = create(self._db, Admin, email="[email protected]")
bpl_admin = create(self._db, Admin, email="[email protected]")
# If no domains are set, the admin must already exist in the db
# to be considered library staff.
google = GoogleOAuthAdminAuthenticationProvider(auth_integration, "", test_mode=True)
eq_(True, google.staff_email(self._db, "[email protected]"))
eq_(True, google.staff_email(self._db, "[email protected]"))
eq_(False, google.staff_email(self._db, "[email protected]"))
# If domains are set, the admin's domain can match one of the domains
# if the admin doesn't exist yet.
auth_integration.libraries += [self._default_library]
setting = ConfigurationSetting.for_library_and_externalintegration(
self._db, "domains", self._default_library, auth_integration)
setting.value = json.dumps(["nypl.org"])
eq_(True, google.staff_email(self._db, "[email protected]"))
eq_(True, google.staff_email(self._db, "[email protected]"))
eq_(True, google.staff_email(self._db, "[email protected]"))
eq_(False, google.staff_email(self._db, "[email protected]"))
setting.value = json.dumps(["nypl.org", "bklynlibrary.org"])
eq_(True, google.staff_email(self._db, "[email protected]"))
eq_(True, google.staff_email(self._db, "[email protected]"))
eq_(True, google.staff_email(self._db, "[email protected]"))
eq_(True, google.staff_email(self._db, "[email protected]"))
开发者ID:NYPL-Simplified,项目名称:circulation,代码行数:37,代码来源:test_google_oauth_admin_authentication_provider.py
示例11: enki_library_id
# 需要导入模块: from core.model import ConfigurationSetting [as 别名]
# 或者: from core.model.ConfigurationSetting import for_library_and_externalintegration [as 别名]
def enki_library_id(self, library):
"""Find the Enki library ID for the given library."""
_db = Session.object_session(library)
return ConfigurationSetting.for_library_and_externalintegration(
_db, self.ENKI_LIBRARY_ID_KEY, library,
self.external_integration(_db)
).value
示例12: test_analytics_services_post_edit
# 需要导入模块: from core.model import ConfigurationSetting [as 别名]
# 或者: from core.model.ConfigurationSetting import for_library_and_externalintegration [as 别名]
def test_analytics_services_post_edit(self):
l1, ignore = create(
self._db, Library, name="Library 1", short_name="L1",
)
l2, ignore = create(
self._db, Library, name="Library 2", short_name="L2",
)
ga_service, ignore = create(
self._db, ExternalIntegration,
protocol=GoogleAnalyticsProvider.__module__,
goal=ExternalIntegration.ANALYTICS_GOAL,
)
ga_service.url = "oldurl"
ga_service.libraries = [l1]
with self.request_context_with_admin("/", method="POST"):
flask.request.form = MultiDict([
("id", ga_service.id),
("name", "some other analytics name"),
("protocol", GoogleAnalyticsProvider.__module__),
(ExternalIntegration.URL, "http://test"),
("libraries", json.dumps([{"short_name": "L2", "tracking_id": "l2id"}])),
])
response = self.manager.admin_analytics_services_controller.process_analytics_services()
eq_(response.status_code, 200)
eq_(ga_service.id, int(response.response[0]))
eq_(GoogleAnalyticsProvider.__module__, ga_service.protocol)
eq_("http://test", ga_service.url)
eq_([l2], ga_service.libraries)
eq_("l2id", ConfigurationSetting.for_library_and_externalintegration(
self._db, GoogleAnalyticsProvider.TRACKING_ID, l2, ga_service).value)
示例13: test_analytics_services_post_create
# 需要导入模块: from core.model import ConfigurationSetting [as 别名]
# 或者: from core.model.ConfigurationSetting import for_library_and_externalintegration [as 别名]
def test_analytics_services_post_create(self):
library, ignore = create(
self._db, Library, name="Library", short_name="L",
)
with self.request_context_with_admin("/", method="POST"):
flask.request.form = MultiDict([
("name", "Google analytics name"),
("protocol", GoogleAnalyticsProvider.__module__),
(ExternalIntegration.URL, "http://test"),
("libraries", json.dumps([{"short_name": "L", "tracking_id": "trackingid"}])),
])
response = self.manager.admin_analytics_services_controller.process_analytics_services()
eq_(response.status_code, 201)
service = get_one(self._db, ExternalIntegration, goal=ExternalIntegration.ANALYTICS_GOAL)
eq_(service.id, int(response.response[0]))
eq_(GoogleAnalyticsProvider.__module__, service.protocol)
eq_("http://test", service.url)
eq_([library], service.libraries)
eq_("trackingid", ConfigurationSetting.for_library_and_externalintegration(
self._db, GoogleAnalyticsProvider.TRACKING_ID, library, service).value)
# Creating a local analytics service doesn't require a URL.
with self.request_context_with_admin("/", method="POST"):
flask.request.form = MultiDict([
("name", "local analytics name"),
("protocol", LocalAnalyticsProvider.__module__),
("libraries", json.dumps([{"short_name": "L", "tracking_id": "trackingid"}])),
])
response = self.manager.admin_analytics_services_controller.process_analytics_services()
eq_(response.status_code, 201)
示例14: test_patron_auth_services_get_with_sip2_auth_service
# 需要导入模块: from core.model import ConfigurationSetting [as 别名]
# 或者: from core.model.ConfigurationSetting import for_library_and_externalintegration [as 别名]
def test_patron_auth_services_get_with_sip2_auth_service(self):
auth_service, ignore = create(
self._db, ExternalIntegration,
protocol=SIP2AuthenticationProvider.__module__,
goal=ExternalIntegration.PATRON_AUTH_GOAL
)
auth_service.url = "url"
auth_service.setting(SIP2AuthenticationProvider.PORT).value = "1234"
auth_service.username = "user"
auth_service.password = "pass"
auth_service.setting(SIP2AuthenticationProvider.LOCATION_CODE).value = "5"
auth_service.setting(SIP2AuthenticationProvider.FIELD_SEPARATOR).value = ","
auth_service.libraries += [self._default_library]
ConfigurationSetting.for_library_and_externalintegration(
self._db, AuthenticationProvider.EXTERNAL_TYPE_REGULAR_EXPRESSION,
self._default_library, auth_service,
).value = "^(u)"
with self.request_context_with_admin("/"):
response = self.manager.admin_patron_auth_services_controller.process_patron_auth_services()
[service] = response.get("patron_auth_services")
eq_(auth_service.id, service.get("id"))
eq_(SIP2AuthenticationProvider.__module__, service.get("protocol"))
eq_("url", service.get("settings").get(ExternalIntegration.URL))
eq_("1234", service.get("settings").get(SIP2AuthenticationProvider.PORT))
eq_("user", service.get("settings").get(ExternalIntegration.USERNAME))
eq_("pass", service.get("settings").get(ExternalIntegration.PASSWORD))
eq_("5", service.get("settings").get(SIP2AuthenticationProvider.LOCATION_CODE))
eq_(",", service.get("settings").get(SIP2AuthenticationProvider.FIELD_SEPARATOR))
[library] = service.get("libraries")
eq_(self._default_library.short_name, library.get("short_name"))
eq_("^(u)", library.get(AuthenticationProvider.EXTERNAL_TYPE_REGULAR_EXPRESSION))
示例15: test_lane_loading
# 需要导入模块: from core.model import ConfigurationSetting [as 别名]
# 或者: from core.model.ConfigurationSetting import for_library_and_externalintegration [as 别名]
def test_lane_loading(self):
# The default setup loads lane IDs properly.
gate = COPPAGate(self._default_library, self.integration)
eq_(self.lane1.id, gate.yes_lane_id)
eq_(self.lane2.id, gate.no_lane_id)
# If a lane isn't associated with the right library, the
# COPPAGate is misconfigured and cannot be instantiated.
library = self._library()
self.lane1.library = library
self._db.commit()
assert_raises_regexp(
CannotLoadConfiguration,
"Lane .* is for the wrong library",
COPPAGate,
self._default_library, self.integration
)
self.lane1.library_id = self._default_library.id
# If the lane ID doesn't correspond to a real lane, the
# COPPAGate cannot be instantiated.
ConfigurationSetting.for_library_and_externalintegration(
self._db, COPPAGate.REQUIREMENT_MET_LANE, self._default_library,
self.integration
).value = -100
assert_raises_regexp(
CannotLoadConfiguration, "No lane with ID: -100",
COPPAGate, self._default_library, self.integration
)