本文整理汇总了Python中core.model.ConfigurationSetting类的典型用法代码示例。如果您正苦于以下问题:Python ConfigurationSetting类的具体用法?Python ConfigurationSetting怎么用?Python ConfigurationSetting使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了ConfigurationSetting类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_sitewide_settings_get
def test_sitewide_settings_get(self):
with self.request_context_with_admin("/"):
response = self.manager.admin_sitewide_configuration_settings_controller.process_get()
settings = response.get("settings")
all_settings = response.get("all_settings")
eq_([], settings)
keys = [s.get("key") for s in all_settings]
assert AcquisitionFeed.GROUPED_MAX_AGE_POLICY in keys
assert AcquisitionFeed.NONGROUPED_MAX_AGE_POLICY in keys
assert Configuration.SECRET_KEY in keys
ConfigurationSetting.sitewide(self._db, AcquisitionFeed.GROUPED_MAX_AGE_POLICY).value = 0
ConfigurationSetting.sitewide(self._db, Configuration.SECRET_KEY).value = "secret"
self._db.flush()
with self.request_context_with_admin("/"):
response = self.manager.admin_sitewide_configuration_settings_controller.process_get()
settings = response.get("settings")
all_settings = response.get("all_settings")
eq_(2, len(settings))
settings_by_key = { s.get("key") : s.get("value") for s in settings }
eq_("0", settings_by_key.get(AcquisitionFeed.GROUPED_MAX_AGE_POLICY))
eq_("secret", settings_by_key.get(Configuration.SECRET_KEY))
keys = [s.get("key") for s in all_settings]
assert AcquisitionFeed.GROUPED_MAX_AGE_POLICY in keys
assert AcquisitionFeed.NONGROUPED_MAX_AGE_POLICY in keys
assert Configuration.SECRET_KEY in keys
self.admin.remove_role(AdminRole.SYSTEM_ADMIN)
self._db.flush()
assert_raises(AdminNotAuthorized,
self.manager.admin_sitewide_configuration_settings_controller.process_get)
示例2: test_catalog_services_post_create
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)
示例3: test_domains
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,代码行数:25,代码来源:test_google_oauth_admin_authentication_provider.py
示例4: test_catalog_services_get_with_marc_exporter
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))
示例5: process_post
def process_post(self):
self.require_system_admin()
setting = ConfigurationSetting.sitewide(self._db, flask.request.form.get("key"))
error = self.validate_form_fields(setting, flask.request.form.keys())
if error:
return error
setting = ConfigurationSetting.sitewide(self._db, flask.request.form.get("key"))
setting.value = flask.request.form.get("value")
return Response(unicode(setting.key), 200)
示例6: __init__
def __init__(self, integration, library=None):
_db = Session.object_session(integration)
if not library:
raise CannotLoadConfiguration("Google Analytics can't be configured without a library.")
url_setting = ConfigurationSetting.for_externalintegration(ExternalIntegration.URL, integration)
self.url = url_setting.value or self.DEFAULT_URL
self.tracking_id = ConfigurationSetting.for_library_and_externalintegration(
_db, self.TRACKING_ID, library, integration,
).value
if not self.tracking_id:
raise CannotLoadConfiguration("Missing tracking id for library %s" % library.short_name)
示例7: setup
def setup(self):
super(TestLaneScript, self).setup()
base_url_setting = ConfigurationSetting.sitewide(
self._db, Configuration.BASE_URL_KEY)
base_url_setting.value = u'http://test-circulation-manager/'
for k, v in [
(Configuration.LARGE_COLLECTION_LANGUAGES, []),
(Configuration.SMALL_COLLECTION_LANGUAGES, []),
(Configuration.TINY_COLLECTION_LANGUAGES, ['eng', 'fre'])
]:
ConfigurationSetting.for_library(
k, self._default_library).value = json.dumps(v)
示例8: test_callback
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,代码行数:49,代码来源:test_google_oauth_admin_authentication_provider.py
示例9: check_identifier_restriction
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
示例10: test_libraries_get_with_multiple_libraries
def test_libraries_get_with_multiple_libraries(self):
# Delete any existing library created by the controller test setup.
library = get_one(self._db, Library)
if library:
self._db.delete(library)
l1 = self._library("Library 1", "L1")
l2 = self._library("Library 2", "L2")
l3 = self._library("Library 3", "L3")
# L2 has some additional library-wide settings.
ConfigurationSetting.for_library(Configuration.FEATURED_LANE_SIZE, l2).value = 5
ConfigurationSetting.for_library(
Configuration.DEFAULT_FACET_KEY_PREFIX + FacetConstants.ORDER_FACET_GROUP_NAME, l2
).value = FacetConstants.ORDER_RANDOM
ConfigurationSetting.for_library(
Configuration.ENABLED_FACETS_KEY_PREFIX + FacetConstants.ORDER_FACET_GROUP_NAME, l2
).value = json.dumps([FacetConstants.ORDER_TITLE, FacetConstants.ORDER_RANDOM])
ConfigurationSetting.for_library(
Configuration.LARGE_COLLECTION_LANGUAGES, l2
).value = json.dumps(["French"])
# The admin only has access to L1 and L2.
self.admin.remove_role(AdminRole.SYSTEM_ADMIN)
self.admin.add_role(AdminRole.LIBRARIAN, l1)
self.admin.add_role(AdminRole.LIBRARY_MANAGER, l2)
with self.request_context_with_admin("/"):
response = self.manager.admin_library_settings_controller.process_get()
libraries = response.get("libraries")
eq_(2, len(libraries))
eq_(l1.uuid, libraries[0].get("uuid"))
eq_(l2.uuid, libraries[1].get("uuid"))
eq_(l1.name, libraries[0].get("name"))
eq_(l2.name, libraries[1].get("name"))
eq_(l1.short_name, libraries[0].get("short_name"))
eq_(l2.short_name, libraries[1].get("short_name"))
eq_({}, libraries[0].get("settings"))
eq_(4, len(libraries[1].get("settings").keys()))
settings = libraries[1].get("settings")
eq_("5", settings.get(Configuration.FEATURED_LANE_SIZE))
eq_(FacetConstants.ORDER_RANDOM,
settings.get(Configuration.DEFAULT_FACET_KEY_PREFIX + FacetConstants.ORDER_FACET_GROUP_NAME))
eq_([FacetConstants.ORDER_TITLE, FacetConstants.ORDER_RANDOM],
settings.get(Configuration.ENABLED_FACETS_KEY_PREFIX + FacetConstants.ORDER_FACET_GROUP_NAME))
eq_(["French"], settings.get(Configuration.LARGE_COLLECTION_LANGUAGES))
示例11: test_discovery_service_library_registrations_get
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)
示例12: test_patron_auth_services_get_with_millenium_auth_service
def test_patron_auth_services_get_with_millenium_auth_service(self):
auth_service, ignore = create(
self._db, ExternalIntegration,
protocol=MilleniumPatronAPI.__module__,
goal=ExternalIntegration.PATRON_AUTH_GOAL
)
auth_service.setting(BasicAuthenticationProvider.TEST_IDENTIFIER).value = "user"
auth_service.setting(BasicAuthenticationProvider.TEST_PASSWORD).value = "pass"
auth_service.setting(BasicAuthenticationProvider.IDENTIFIER_REGULAR_EXPRESSION).value = "u*"
auth_service.setting(BasicAuthenticationProvider.PASSWORD_REGULAR_EXPRESSION).value = "p*"
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_(MilleniumPatronAPI.__module__, service.get("protocol"))
eq_("user", service.get("settings").get(BasicAuthenticationProvider.TEST_IDENTIFIER))
eq_("pass", service.get("settings").get(BasicAuthenticationProvider.TEST_PASSWORD))
eq_("u*", service.get("settings").get(BasicAuthenticationProvider.IDENTIFIER_REGULAR_EXPRESSION))
eq_("p*", service.get("settings").get(BasicAuthenticationProvider.PASSWORD_REGULAR_EXPRESSION))
[library] = service.get("libraries")
eq_(self._default_library.short_name, library.get("short_name"))
eq_("^(u)", library.get(AuthenticationProvider.EXTERNAL_TYPE_REGULAR_EXPRESSION))
示例13: test_borrow_with_outstanding_fines
def test_borrow_with_outstanding_fines(self):
# This checkout would succeed...
now = datetime.now()
loaninfo = LoanInfo(
self.pool.collection, self.pool.data_source,
self.pool.identifier.type,
self.pool.identifier.identifier,
now, now + timedelta(seconds=3600),
)
self.remote.queue_checkout(loaninfo)
# ...except the patron has too many fines.
old_fines = self.patron.fines
self.patron.fines = 1000
setting = ConfigurationSetting.for_library(
Configuration.MAX_OUTSTANDING_FINES,
self._default_library
)
setting.value = "$0.50"
assert_raises(OutstandingFines, self.borrow)
# Test the case where any amount of fines are too much.
setting.value = "$0"
assert_raises(OutstandingFines, self.borrow)
# Remove the fine policy, and borrow succeeds.
setting.value = None
loan, i1, i2 = self.borrow()
assert isinstance(loan, Loan)
self.patron.fines = old_fines
示例14: test_analytics_services_post_create
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)
示例15: test_analytics_services_post_edit
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)