Exemple #1
0
 def cw_clear_all_caches(self):
     super(NonPeriodicTimeSeries, self).cw_clear_all_caches()
     if 'start_date' in vars(self):
         del self.start_date
     if 'timestamps_array' in vars(self):
         del self.timestamps_array
     clear_cache(self, 'timestamped_array')
Exemple #2
0
 def del_subject_relation(self, rtype):
     try:
         del self.subjrels[rtype]
         clear_cache(self, 'ordered_relations')
         clear_cache(self, 'meta_attributes')
     except KeyError:
         pass
Exemple #3
0
 def helper_clear_cache(self):
     if self.dbcnx is not None:
         self.dbcnx.commit()
         self.dbcnx.close()
         del self._cnx
         clear_cache(self, 'cursor')
     clear_cache(self, 'helper')
Exemple #4
0
 def upgrade_instance(self, appid):
     print('\n' + underline_title('Upgrading the instance %s' % appid))
     from logilab.common.changelog import Version
     config = cwcfg.config_for(appid)
     config.repairing = True  # notice we're not starting the server
     config.verbosity = self.config.verbosity
     set_sources_mode = getattr(config, 'set_sources_mode', None)
     if set_sources_mode is not None:
         set_sources_mode(self.config.ext_sources or ('migration', ))
     # get instance and installed versions for the server and the componants
     mih = config.migration_handler()
     repo = mih.repo
     vcconf = repo.get_versions()
     helper = self.config_helper(config, required=False)
     if self.config.force_cube_version:
         for cube, version in self.config.force_cube_version.items():
             vcconf[cube] = Version(version)
     toupgrade = []
     for cube in config.cubes():
         installedversion = config.cube_version(cube)
         try:
             applversion = vcconf[cube]
         except KeyError:
             config.error('no version information for %s' % cube)
             continue
         if installedversion > applversion:
             toupgrade.append((cube, applversion, installedversion))
     cubicwebversion = config.cubicweb_version()
     if self.config.force_cubicweb_version:
         applcubicwebversion = Version(self.config.force_cubicweb_version)
         vcconf['cubicweb'] = applcubicwebversion
     else:
         applcubicwebversion = vcconf.get('cubicweb')
     if cubicwebversion > applcubicwebversion:
         toupgrade.append(
             ('cubicweb', applcubicwebversion, cubicwebversion))
     # run cubicweb/componants migration scripts
     if self.config.fs_only or toupgrade:
         for cube, fromversion, toversion in toupgrade:
             print('-> migration needed from %s to %s for %s' %
                   (fromversion, toversion, cube))
         with mih.cnx:
             with mih.cnx.security_enabled(False, False):
                 mih.migrate(vcconf, reversed(toupgrade), self.config)
         clear_cache(config, 'instance_md5_version')
     else:
         print('-> no data migration needed for instance %s.' % appid)
     # rewrite main configuration file
     if not self.config.no_config_update:
         mih.rewrite_configuration()
     mih.shutdown()
     # handle i18n upgrade
     if not self.i18nupgrade(config):
         return
     print()
     if helper:
         helper.postupgrade(repo)
     print('-> instance migrated.')
     print()
 def _reset_cookie(self, req):
     # preparing the suite of the test
     # set session id in cookie
     cookie = SimpleCookie()
     sessioncookie = self.app.session_handler.session_cookie(req)
     cookie[sessioncookie] = req.session.sessionid
     req.set_request_header('Cookie',
                            cookie[sessioncookie].OutputString(),
                            raw=True)
     clear_cache(req, 'get_authorization')
Exemple #6
0
 def test_cached_keyarg_cache(self):
     class Foo(object):
         @cached(cacheattr=u'_foo', keyarg=1)
         def foo(self, other, args):
             """ what's up doc ? """
     foo = Foo()
     foo.foo(2, 1)
     self.assertEqual(foo._foo, {2: None})
     clear_cache(foo, 'foo')
     self.assertFalse(hasattr(foo, '_foo'))
Exemple #7
0
 def test_cached_multi_cache(self):
     class Foo(object):
         @cached(cacheattr=u'_foo')
         def foo(self, args):
             """ what's up doc ? """
     foo = Foo()
     foo.foo(1)
     self.assertEqual(foo._foo, {(1,): None})
     clear_cache(foo, 'foo')
     self.assertFalse(hasattr(foo, '_foo'))
 def test_cached_multi_cache(self):
     class Foo(object):
         @cached(cacheattr=u'_foo')
         def foo(self, args):
             """ what's up doc ? """
     foo = Foo()
     foo.foo(1)
     self.assertEqual(foo._foo, {(1,): None})
     clear_cache(foo, 'foo')
     self.assertFalse(hasattr(foo, '_foo'))
 def test_cached_keyarg_cache(self):
     class Foo(object):
         @cached(cacheattr=u'_foo', keyarg=1)
         def foo(self, other, args):
             """ what's up doc ? """
     foo = Foo()
     foo.foo(2, 1)
     self.assertEqual(foo._foo, {2: None})
     clear_cache(foo, 'foo')
     self.assertFalse(hasattr(foo, '_foo'))
 def test_cached_single_cache(self):
     class Foo(object):
         @cached(cacheattr=u'_foo')
         def foo(self):
             """ what's up doc ? """
     foo = Foo()
     foo.foo()
     self.assertTrue(hasattr(foo, '_foo'))
     clear_cache(foo, 'foo')
     self.assertFalse(hasattr(foo, '_foo'))
Exemple #11
0
 def test_cached_single_cache(self):
     class Foo(object):
         @cached(cacheattr=u'_foo')
         def foo(self):
             """ what's up doc ? """
     foo = Foo()
     foo.foo()
     self.assertTrue(hasattr(foo, '_foo'))
     clear_cache(foo, 'foo')
     self.assertFalse(hasattr(foo, '_foo'))
 def test_cached_property(self):
     class Foo(object):
         @property
         @cached(cacheattr=u'_foo')
         def foo(self):
             """ what's up doc ? """
     foo = Foo()
     foo.foo
     self.assertEqual(foo._foo, None)
     clear_cache(foo, 'foo')
     self.assertFalse(hasattr(foo, '_foo'))
Exemple #13
0
 def test_cached_property(self):
     class Foo(object):
         @property
         @cached(cacheattr=u'_foo')
         def foo(self):
             """ what's up doc ? """
     foo = Foo()
     foo.foo
     self.assertEqual(foo._foo, None)
     clear_cache(foo, 'foo')
     self.assertFalse(hasattr(foo, '_foo'))
Exemple #14
0
 def set_schema(self, schema):
     """set instance'schema and load application objects"""
     self._set_schema(schema)
     # now we can load application's web objects
     self.reload(self.config.appobjects_modnames(), force_reload=False)
     # map lowered entity type names to their actual name
     self.case_insensitive_etypes = {}
     for eschema in self.schema.entities():
         etype = str(eschema)
         self.case_insensitive_etypes[etype.lower()] = etype
         clear_cache(eschema, 'ordered_relations')
         clear_cache(eschema, 'meta_attributes')
 def test_http_auth_no_anon(self):
     req = self.init_authentication('http')
     self.assertAuthFailure(req)
     self.app.handle_request(req)
     self.assertEqual(401, req.status_out)
     clear_cache(req, 'get_authorization')
     authstr = base64.encodestring(
         ('%s:%s' % (self.admlogin, self.admpassword)).encode('ascii'))
     req.set_request_header('Authorization',
                            'basic %s' % authstr.decode('ascii'))
     self.assertAuthSuccess(req)
     req._url = 'logout'
     self.assertRaises(LogOut, self.app_handle_request, req)
     self.assertEqual(len(self.open_sessions), 0)
 def test_cookie_auth_no_anon(self):
     req = self.init_authentication('cookie')
     self.assertAuthFailure(req)
     try:
         form = self.app.handle_request(req)
     except Redirect:
         self.fail('anonymous user should get login form')
     clear_cache(req, 'get_authorization')
     self.assertIn(b'__login', form)
     self.assertIn(b'__password', form)
     self.assertFalse(req.cnx)  # Mock cnx are False
     req.form['__login'] = self.admlogin
     req.form['__password'] = self.admpassword
     self.assertAuthSuccess(req)
     req._url = 'logout'
     self.assertRaises(LogOut, self.app_handle_request, req)
     self.assertEqual(len(self.open_sessions), 0)
Exemple #17
0
    def limit(self, limit, offset=0, inplace=False):
        """limit the result set to the given number of rows optionally starting
        from an index different than 0

        :type limit: int
        :param limit: the maximum number of results

        :type offset: int
        :param offset: the offset index

        :type inplace: bool
        :param inplace:
          if true, the result set is modified in place, else a new result set
          is returned and the original is left unmodified

        :rtype: `ResultSet`
        """
        stop = limit + offset
        rows = self.rows[offset:stop]
        descr = self.description[offset:stop]
        if inplace:
            rset = self
            rset.rows, rset.description = rows, descr
            rset.rowcount = len(rows)
            clear_cache(rset, 'description_struct')
            if offset:
                clear_cache(rset, 'get_entity')
            # we also have to fix/remove from the request entity cache entities
            # which get a wrong rset reference by this limit call
            for entity in self.req.cached_entities():
                if entity.cw_rset is self:
                    if offset <= entity.cw_row < stop:
                        entity.cw_row = entity.cw_row - offset
                    else:
                        entity.cw_rset = entity.as_rset()
                        entity.cw_row = entity.cw_col = 0
        else:
            rset = self.copy(rows, descr)
            if not offset:
                # can copy built entity caches
                copy_cache(rset, 'get_entity', self)
        rset.limited = (limit, offset)
        return rset
Exemple #18
0
    def test_is_in_state(self):
        with self.statefull_stuff() as (req, wf_entity, rset, adapter):
            for state in ('created', 'validated', 'abandoned'):
                selector = is_in_state(state)
                self.assertEqual(selector(None, req, rset=rset),
                                 state == "created")

            adapter.fire_transition('validate')
            req.cnx.commit()
            wf_entity.cw_clear_all_caches()
            self.assertEqual(adapter.state, 'validated')

            clear_cache(rset, 'get_entity')

            selector = is_in_state('created')
            self.assertEqual(selector(None, req, rset=rset), 0)
            selector = is_in_state('validated')
            self.assertEqual(selector(None, req, rset=rset), 1)
            selector = is_in_state('validated', 'abandoned')
            self.assertEqual(selector(None, req, rset=rset), 1)
            selector = is_in_state('abandoned')
            self.assertEqual(selector(None, req, rset=rset), 0)

            adapter.fire_transition('forsake')
            req.cnx.commit()
            wf_entity.cw_clear_all_caches()
            self.assertEqual(adapter.state, 'abandoned')

            clear_cache(rset, 'get_entity')

            selector = is_in_state('created')
            self.assertEqual(selector(None, req, rset=rset), 0)
            selector = is_in_state('validated')
            self.assertEqual(selector(None, req, rset=rset), 0)
            selector = is_in_state('validated', 'abandoned')
            self.assertEqual(selector(None, req, rset=rset), 1)
            self.assertEqual(adapter.state, 'abandoned')
            self.assertEqual(selector(None, req, rset=rset), 1)
Exemple #19
0
 def cw_clear_all_caches(self):
     super(WorkflowTransition, self).cw_clear_all_caches()
     clear_cache(self, 'exit_points')
Exemple #20
0
 def select_eclass(self, etype):
     # clear selector cache
     clear_cache(self.vreg['etypes'], 'etype_class')
     return self.vreg['etypes'].etype_class(etype)
Exemple #21
0
 def _set_schema(self, schema):
     """set instance'schema"""
     self.schema = schema
     clear_cache(self, 'rqlhelper')
Exemple #22
0
 def clear_caches(self):
     clear_cache(self, 'etype_class')
     clear_cache(self, 'parent_classes')
     _reset_is_instance_cache(self.vreg)
Exemple #23
0
 def add_subject_relation(self, rschema):
     """register the relation schema as possible subject relation"""
     self.subjrels[rschema] = rschema
     clear_cache(self, 'ordered_relations')
     clear_cache(self, 'meta_attributes')
Exemple #24
0
 def _clear_source_defs_caches(self):
     clear_cache(self, 'source_defs')
Exemple #25
0
 def assertAuthFailure(self, req, nbsessions=0):
     with self.assertRaises(AuthenticationError):
         self.app.get_session(req)
     # +0 since we do not track the opened session
     self.assertEqual(len(self.open_sessions), nbsessions)
     clear_cache(req, 'get_authorization')