def test_can_update_keys(self): default_values = { 'some.random.key': { 'value': 100, 'description': 'my description' } } # Insert key and category keys = {'some.random.key': {'category': 'SEO'}} Key.insert_keys(self.db, keys, default_values) loaded_key = self.db.query(Key).one() expect(keys).to_include(loaded_key.name) expect(loaded_key.name).to_equal('some.random.key') expect(loaded_key.category.name).to_equal('SEO') # Update category keys = {'some.random.key': {'category': 'HTTP'}} Key.insert_keys(self.db, keys, default_values) loaded_key = self.db.query(Key).one() expect(keys).to_include(loaded_key.name) expect(loaded_key.name).to_equal('some.random.key') expect(loaded_key.category.name).to_equal('HTTP')
def test_can_insert_keys(self): default_values = {} keys = {} for x in range(3): key_name = 'key.%d' % x keys[key_name] = {'category': 'cat.%d' % x} description = 'description %s' % key_name value = 'value %s' % key_name default_values[key_name] = { 'value': value, 'description': description } Key.insert_keys(self.db, keys, default_values) loaded_keys = self.db.query(Key).all() expect(loaded_keys).to_length(3) for key in loaded_keys: expect(keys).to_include(key.name) expect(key.to_dict()).to_equal(keys[key.name]['key'].to_dict()) expect(key.category.name).to_be_like(keys[key.name]['category']) expect(keys[key.name]['default_value_description']).to_equal( 'description %s' % key.name) expect(keys[key.name]['default_value']).to_equal('value %s' % key.name)
def test_can_update_keys(self): default_values = {'some.random.key': { 'value': 100, 'description': 'my description'} } # Insert key and category keys = {'some.random.key': {'category': 'SEO'}} Key.insert_keys(self.db, keys, default_values) loaded_key = self.db.query(Key).one() expect(keys).to_include(loaded_key.name) expect(loaded_key.name).to_equal('some.random.key') expect(loaded_key.category.name).to_equal('SEO') # Update category keys = {'some.random.key': {'category': 'HTTP'}} Key.insert_keys(self.db, keys, default_values) loaded_key = self.db.query(Key).one() expect(keys).to_include(loaded_key.name) expect(loaded_key.name).to_equal('some.random.key') expect(loaded_key.category.name).to_equal('HTTP')
def test_can_insert_keys(self): default_values = {} keys = {} for x in range(3): key_name = 'key.%d' % x keys[key_name] = {'category': 'cat.%d' % x} description = 'description %s' % key_name value = 'value %s' % key_name default_values[key_name] = { 'value': value, 'description': description } Key.insert_keys(self.db, keys, default_values) loaded_keys = self.db.query(Key).all() expect(loaded_keys).to_length(3) for key in loaded_keys: expect(keys).to_include(key.name) expect(key.to_dict()).to_equal(keys[key.name]['key'].to_dict()) expect(key.category.name).to_be_like(keys[key.name]['category']) expect(keys[key.name]['default_value_description']).to_equal( 'description %s' % key.name ) expect(keys[key.name]['default_value']).to_equal( 'value %s' % key.name )
def initialize(self): self.uuid = uuid4().hex self.working_url = None self.domain_name = None self.last_ping = None self.last_update_pages_score = None authnz_wrapper_class = self.load_authnz_wrapper() if authnz_wrapper_class: self.authnz_wrapper = authnz_wrapper_class(self.config) else: self.authnz_wrapper = None self.facters = self._load_facters() self.validators = self._load_validators() self.error_handlers = [handler(self.config) for handler in self.load_error_handlers()] self.connect_sqlalchemy() self.search_provider = self.load_search_provider()( config=self.config, db=self.db, authnz_wrapper=self.authnz_wrapper ) self.connect_to_redis() self.start_otto() self.fact_definitions = {} self.violation_definitions = {} self.default_violations_values = {} for facter in self.facters: self.fact_definitions.update(facter.get_fact_definitions()) Key.insert_keys(self.db, self.fact_definitions) for validator in self.validators: self.violation_definitions.update(validator.get_violation_definitions()) self.default_violations_values.update( validator.get_default_violations_values(self.config) ) Key.insert_keys( self.db, self.violation_definitions, self.default_violations_values ) self.configure_material_girl() DomainsViolationsPrefs.insert_default_violations_values_for_all_domains( self.db, self.default_violations_values, self.violation_definitions, self.cache ) self.load_all_domains_violations_prefs()
def initialize(self): self.uuid = uuid4().hex self.working_url = None self.domain_name = None self.last_ping = None authnz_wrapper_class = self.load_authnz_wrapper() if authnz_wrapper_class: self.authnz_wrapper = authnz_wrapper_class(self.config) else: self.authnz_wrapper = None self.facters = self._load_facters() self.validators = self._load_validators() self.error_handlers = [ handler(self.config) for handler in self.load_error_handlers() ] self.connect_sqlalchemy() self.search_provider = self.load_search_provider()( config=self.config, db=self.db, authnz_wrapper=self.authnz_wrapper) self.connect_to_redis() self.start_otto() self.fact_definitions = {} self.violation_definitions = {} self.default_violations_values = {} for facter in self.facters: self.fact_definitions.update(facter.get_fact_definitions()) Key.insert_keys(self.db, self.fact_definitions) for validator in self.validators: self.violation_definitions.update( validator.get_violation_definitions()) self.default_violations_values.update( validator.get_default_violations_values(self.config)) Key.insert_keys(self.db, self.violation_definitions, self.default_violations_values) self.configure_material_girl() DomainsViolationsPrefs.insert_default_violations_values_for_all_domains( self.db, self.default_violations_values, self.violation_definitions, self.cache) self.load_all_domains_violations_prefs()
def after_start(self, io_loop): if self.db is not None: self.application.db = self.db else: self.application.db = self.application.get_sqlalchemy_session() if self.debug: from sqltap import sqltap self.sqltap = sqltap.start() authnz_wrapper_class = self._load_authnz_wrapper() if authnz_wrapper_class: self.application.authnz_wrapper = authnz_wrapper_class(self.application.config) else: self.application.authnz_wrapper = None self.application.facters = self._load_facters() self.application.validators = self._load_validators() self.application.error_handlers = [handler(self.application.config) for handler in self._load_error_handlers()] self.application.search_provider = self._load_search_provider()( config=self.application.config, db=self.application.db, authnz_wrapper=self.application.authnz_wrapper, io_loop=io_loop ) self.application.fact_definitions = {} self.application.violation_definitions = {} self.application.default_violations_values = {} for facter in self.application.facters: self.application.fact_definitions.update(facter.get_fact_definitions()) Key.insert_keys(self.application.db, self.application.fact_definitions) for validator in self.application.validators: self.application.violation_definitions.update(validator.get_violation_definitions()) self.application.default_violations_values.update( validator.get_default_violations_values(self.application.config) ) Key.insert_keys( self.application.db, self.application.violation_definitions, self.application.default_violations_values ) self.application.event_bus = EventBus(self.application) self.application.http_client = AsyncHTTPClient(io_loop=io_loop) self.application.cache = Cache(self.application) self.configure_material_girl() self.configure_i18n() DomainsViolationsPrefs.insert_default_violations_values_for_all_domains( self.application.db, self.application.default_violations_values, self.application.violation_definitions, self.application.cache )
def after_start(self, io_loop): if self.db is not None: self.application.db = self.db else: self.application.db = self.application.get_sqlalchemy_session() if self.debug: from sqltap import sqltap self.sqltap = sqltap.start() authnz_wrapper_class = self._load_authnz_wrapper() if authnz_wrapper_class: self.application.authnz_wrapper = authnz_wrapper_class( self.application.config) else: self.application.authnz_wrapper = None self.application.facters = self._load_facters() self.application.validators = self._load_validators() self.application.error_handlers = [ handler(self.application.config) for handler in self._load_error_handlers() ] self.application.search_provider = self._load_search_provider()( config=self.application.config, db=self.application.db, authnz_wrapper=self.application.authnz_wrapper, io_loop=io_loop) self.application.fact_definitions = {} self.application.violation_definitions = {} self.application.default_violations_values = {} for facter in self.application.facters: self.application.fact_definitions.update( facter.get_fact_definitions()) Key.insert_keys(self.application.db, self.application.fact_definitions) for validator in self.application.validators: self.application.violation_definitions.update( validator.get_violation_definitions()) self.application.default_violations_values.update( validator.get_default_violations_values( self.application.config)) Key.insert_keys(self.application.db, self.application.violation_definitions, self.application.default_violations_values) self.application.event_bus = EventBus(self.application) self.application.http_client = AsyncHTTPClient(io_loop=io_loop) self.application.cache = Cache(self.application) self.configure_material_girl() self.configure_i18n() DomainsViolationsPrefs.insert_default_violations_values_for_all_domains( self.application.db, self.application.default_violations_values, self.application.violation_definitions, self.application.cache)