changeset 535:72778dda34cf

some fixups in cache, added fallback and cache invalidation when key not found in cached repos list, added extra test, some other small fixes
author Marcin Kuzminski <marcin@python-works.com>
date Fri, 01 Oct 2010 03:04:52 +0200
parents 12c976209b2e
children 39203995f2c4
files celeryconfig.py pylons_app/lib/base.py pylons_app/lib/celerylib/tasks.py pylons_app/model/hg_model.py pylons_app/tests/__init__.py pylons_app/tests/functional/test_settings.py
diffstat 6 files changed, 37 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- a/celeryconfig.py	Fri Oct 01 02:19:34 2010 +0200
+++ b/celeryconfig.py	Fri Oct 01 03:04:52 2010 +0200
@@ -4,7 +4,7 @@
 import ConfigParser
 root = os.getcwd()
 
-PYLONS_CONFIG_NAME = 'test.ini'
+PYLONS_CONFIG_NAME = 'production.ini'
 
 sys.path.append(root)
 config = ConfigParser.ConfigParser({'here':root})
--- a/pylons_app/lib/base.py	Fri Oct 01 02:19:34 2010 +0200
+++ b/pylons_app/lib/base.py	Fri Oct 01 03:04:52 2010 +0200
@@ -22,8 +22,14 @@
         c.repo_switcher_list = _get_repos_switcher_cached(c.cached_repo_list)
         
         if c.repo_name:
-            c.repository_tags = c.cached_repo_list[c.repo_name].tags
-            c.repository_branches = c.cached_repo_list[c.repo_name].branches
+            cached_repo = c.cached_repo_list.get(c.repo_name)
+            
+            if cached_repo:
+                c.repository_tags = cached_repo.tags
+                c.repository_branches = cached_repo.branches
+            else:
+                c.repository_tags = {}
+                c.repository_branches = {}
                     
         self.sa = meta.Session
     
--- a/pylons_app/lib/celerylib/tasks.py	Fri Oct 01 02:19:34 2010 +0200
+++ b/pylons_app/lib/celerylib/tasks.py	Fri Oct 01 03:04:52 2010 +0200
@@ -274,7 +274,6 @@
 @task
 def create_repo_fork(form_data, cur_user):
     import os
-    from pylons_app.lib.utils import invalidate_cache
     from pylons_app.model.repo_model import RepoModel
     sa = get_session()
     rm = RepoModel(sa)
@@ -286,7 +285,6 @@
     repo_fork_path = os.path.join(repos_path, form_data['fork_name'])
     
     MercurialRepository(str(repo_fork_path), True, clone_url=str(repo_path))
-    #invalidate_cache('cached_repo_list')
 
     
 def __get_codes_stats(repo_name):
--- a/pylons_app/model/hg_model.py	Fri Oct 01 02:19:34 2010 +0200
+++ b/pylons_app/model/hg_model.py	Fri Oct 01 03:04:52 2010 +0200
@@ -26,12 +26,13 @@
 from mercurial import ui
 from mercurial.hgweb.hgwebdir_mod import findrepos
 from pylons.i18n.translation import _
+from pylons_app.lib import helpers as h
+from pylons_app.lib.utils import invalidate_cache
 from pylons_app.lib.auth import HasRepoPermissionAny
 from pylons_app.model import meta
 from pylons_app.model.db import Repository, User
-from pylons_app.lib import helpers as h
+from sqlalchemy.orm import joinedload
 from vcs.exceptions import RepositoryError, VCSError
-from sqlalchemy.orm import joinedload
 import logging
 import os
 import sys
@@ -123,6 +124,8 @@
                     
                     dbrepo = None
                     if not initial:
+                        #for initial scann on application first run we don't
+                        #have db repos yet.
                         dbrepo = sa.query(Repository)\
                             .options(joinedload(Repository.fork))\
                             .filter(Repository.repo_name == name)\
@@ -169,4 +172,15 @@
             yield tmp_d
 
     def get_repo(self, repo_name):
-        return _get_repos_cached()[repo_name]
+        try:
+            repo = _get_repos_cached()[repo_name]
+            return repo
+        except KeyError:
+            #i we're here and we got key errors let's try to invalidate the
+            #cahce and try again
+            invalidate_cache('cached_repo_list')
+            repo = _get_repos_cached()[repo_name]
+            return repo
+            
+        
+        
--- a/pylons_app/tests/__init__.py	Fri Oct 01 02:19:34 2010 +0200
+++ b/pylons_app/tests/__init__.py	Fri Oct 01 03:04:52 2010 +0200
@@ -28,6 +28,8 @@
 # Invoke websetup with the current config file
 #SetupCommand('setup-app').run([config_file])
 
+##RUNNING DESIRED TESTS
+#nosetests pylons_app.tests.functional.test_admin_settings:TestSettingsController.test_my_account
 
 environ = {}
 
--- a/pylons_app/tests/functional/test_settings.py	Fri Oct 01 02:19:34 2010 +0200
+++ b/pylons_app/tests/functional/test_settings.py	Fri Oct 01 03:04:52 2010 +0200
@@ -42,5 +42,14 @@
         
         #test if fork is visible in the list ?
         response = response.follow()
+
+
+        #check if fork is marked as fork
+        response = self.app.get(url(controller='summary', action='index',
+                                    repo_name=fork_name))
+        
         
         print response
+        
+        assert 'Fork of %s' % repo_name in response.body, 'no message about that this repo is a fork'
+