Changeset - 80dc0a23edf7
[Not reviewed]
default
0 7 0
Marcin Kuzminski - 15 years ago 2010-10-10 01:42:08
marcin@python-works.com
fixed whoosh failure on new repository
added few tests
7 files changed with 65 insertions and 7 deletions:
0 comments (0 inline, 0 general)
rhodecode/lib/indexers/daemon.py
Show inline comments
 
@@ -31,25 +31,25 @@ from os.path import join as jn
 
#to get the rhodecode import
 
project_path = dn(dn(dn(dn(os.path.realpath(__file__)))))
 
sys.path.append(project_path)
 

	
 
from rhodecode.lib.pidlock import LockHeld, DaemonLock
 
from rhodecode.model.hg_model import HgModel
 
from rhodecode.lib.helpers import safe_unicode
 
from whoosh.index import create_in, open_dir
 
from shutil import rmtree
 
from rhodecode.lib.indexers import INDEX_EXTENSIONS, IDX_LOCATION, SCHEMA, IDX_NAME
 

	
 
from time import mktime
 
from vcs.exceptions import ChangesetError
 
from vcs.exceptions import ChangesetError, RepositoryError
 

	
 
import logging
 

	
 
log = logging.getLogger('whooshIndexer')
 
# create logger
 
log.setLevel(logging.DEBUG)
 
log.propagate = False
 
# create console handler and set level to debug
 
ch = logging.StreamHandler()
 
ch.setLevel(logging.DEBUG)
 

	
 
# create formatter
 
@@ -77,31 +77,34 @@ class WhooshIndexingDaemon(object):
 
        if not os.path.isdir(IDX_LOCATION):
 
            os.mkdir(IDX_LOCATION)
 
            log.info('Cannot run incremental index since it does not'
 
                     ' yet exist running full build')
 
            self.initial = True
 
        
 
    def get_paths(self, repo):
 
        """
 
        recursive walk in root dir and return a set of all path in that dir
 
        based on repository walk function
 
        """
 
        index_paths_ = set()
 
        try:
 
        for topnode, dirs, files in repo.walk('/', 'tip'):
 
            for f in files:
 
                index_paths_.add(jn(repo.path, f.path))
 
            for dir in dirs:
 
                for f in files:
 
                    index_paths_.add(jn(repo.path, f.path))
 
            
 
        except RepositoryError:
 
            pass
 
        return index_paths_        
 
    
 
    def get_node(self, repo, path):
 
        n_path = path[len(repo.path) + 1:]
 
        node = repo.get_changeset().get_node(n_path)
 
        return node
 
    
 
    def get_node_mtime(self, node):
 
        return mktime(node.last_changeset.date.timetuple())
 
    
 
    def add_doc(self, writer, path, repo):
 
        """Adding doc to writer"""
rhodecode/lib/utils.py
Show inline comments
 
@@ -458,26 +458,26 @@ def create_test_env(repos_test_path, con
 
    ch.setLevel(logging.DEBUG)
 
    
 
    # create formatter
 
    formatter = logging.Formatter("%(asctime)s - %(name)s - %(levelname)s - %(message)s")
 
    
 
    # add formatter to ch
 
    ch.setFormatter(formatter)
 
    
 
    # add ch to logger
 
    log.addHandler(ch)
 
    
 
    #PART ONE create db
 
    log.debug('making test db in %s', repos_test_path)
 
    dbname = config['sqlalchemy.db1.url'].split('/')[-1]
 
    log.debug('making test db %s', dbname)
 
    
 
    dbmanage = DbManage(log_sql=True, dbname=dbname, root=config['here'],
 
                        tests=True)
 
    dbmanage.create_tables(override=True)
 
    dbmanage.config_prompt(repos_test_path)
 
    dbmanage.create_default_user()
 
    dbmanage.admin_prompt()
 
    dbmanage.create_permissions()
 
    dbmanage.populate_default_permissions()
 
    
 
    #PART TWO make test repo
 
    log.debug('making test vcs repo')
rhodecode/tests/functional/test_changelog.py
Show inline comments
 
from rhodecode.tests import *
 

	
 
class TestChangelogController(TestController):
 

	
 
    def test_index(self):
 
        self.log_user()
 
        response = self.app.get(url(controller='changelog', action='index',repo_name='vcs_test'))
 
        # Test response...
 
        
 
        print response
 
        assert """<div id="chg_20" class="container">""" in response.body, 'wrong info about number ofchanges'
 
        assert """Small update at simplevcs app""" in response.body, 'missing info about commit message'
 
        assert """<span class="removed" title="removed">0</span>""" in response.body, 'wrong info about removed nodes'
 
        assert """<span class="changed" title="changed">2</span>""" in response.body, 'wrong info about changed nodes'
 
        assert """<span class="added" title="added">1</span>""" in response.body, 'wrong info about added nodes'
 
        
 
        #pagination
 
        
 
        response = self.app.get(url(controller='changelog', action='index', repo_name='vcs_test'), {'page':1})
 
        response = self.app.get(url(controller='changelog', action='index', repo_name='vcs_test'), {'page':2})
 
        response = self.app.get(url(controller='changelog', action='index', repo_name='vcs_test'), {'page':3})
 
        response = self.app.get(url(controller='changelog', action='index', repo_name='vcs_test'), {'page':4})
 
        response = self.app.get(url(controller='changelog', action='index', repo_name='vcs_test'), {'page':5})
 
        response = self.app.get(url(controller='changelog', action='index', repo_name='vcs_test'), {'page':6})
 
        # Test response after pagination...
 

	
 
        assert """<span class="removed" title="removed">20</span>"""in response.body, 'wrong info about number of removed'
 
        assert """<span class="changed" title="changed">1</span>"""in response.body, 'wrong info about number of changes'
 
        assert """<span class="added" title="added">0</span>"""in response.body, 'wrong info about number of added'
 
        assert """<div class="date">commit 64: 46ad32a4f974@2010-04-20 00:33:21</div>"""in response.body, 'wrong info about commit 64'
 
        assert """<div class="message"><a href="/vcs_test/changeset/46ad32a4f974">Merge with 2e6a2bf9356ca56df08807f4ad86d480da72a8f4</a></div>"""in response.body, 'wrong info about commit 64 is a merge'
 
        
rhodecode/tests/functional/test_login.py
Show inline comments
 
@@ -38,26 +38,26 @@ class TestLoginController(TestController
 
        assert response.status == '302 Found', 'Wrong response code from came from redirection'
 
        response = response.follow()
 
        
 
        assert response.status == '200 OK', 'Wrong response from login page got %s' % response.status
 
        assert 'Users administration' in response.body, 'No proper title in response'
 
        
 
                
 
    def test_login_short_password(self):
 
        response = self.app.post(url(controller='login', action='index'),
 
                                 {'username':'error',
 
                                  'password':'test'})
 
        assert response.status == '200 OK', 'Wrong response from login page'
 
        
 
        assert 'Enter a value 6 characters long or more' in response.body, 'No error password message in response'
 
        print response.body
 
        assert 'Enter 6 characters or more' in response.body, 'No error password message in response'
 

	
 
    def test_login_wrong_username_password(self):
 
        response = self.app.post(url(controller='login', action='index'),
 
                                 {'username':'error',
 
                                  'password':'test12'})
 
        assert response.status == '200 OK', 'Wrong response from login page'
 
        
 
        assert 'invalid user name' in response.body, 'No error username message in response'
 
        assert 'invalid password' in response.body, 'No error password message in response'
 
                
 
        
 
    def test_register(self):
rhodecode/tests/functional/test_repos.py
Show inline comments
 
from rhodecode.model.db import Repository
 
from rhodecode.tests import *
 

	
 
class TestReposController(TestController):
 

	
 
    def test_index(self):
 
        self.log_user()
 
        response = self.app.get(url('repos'))
 
        # Test response...
 

	
 
    def test_index_as_xml(self):
 
        response = self.app.get(url('formatted_repos', format='xml'))
 

	
 
    def test_create(self):
 
        response = self.app.post(url('repos'))
 
        self.log_user()
 
        repo_name = 'vcs_test_new'
 
        description = 'description for newly created repo'
 
        private = False
 
        response = self.app.post(url('repos'), {'repo_name':repo_name,
 
                                               'description':description,
 
                                               'private':private})
 

	
 
        print response
 
        
 
        #test if we have a message that fork is ok
 
        assert '''created repository %s''' % (repo_name) in response.session['flash'][0], 'No flash message about new repo'
 
                      
 
        #test if the fork was created in the database
 
        new_repo = self.sa.query(Repository).filter(Repository.repo_name == repo_name).one()
 
        
 
        assert new_repo.repo_name == repo_name, 'wrong name of repo name in db'
 
        assert new_repo.description == description, 'wrong description'
 
        
 
        #test if repository is visible in the list ?
 
        response = response.follow()
 
        
 
        assert repo_name in response.body, 'missing new repo from the main repos list'
 
        
 
                
 

	
 

	
 
    def test_new(self):
 
        self.log_user()
 
        response = self.app.get(url('new_repo'))
 

	
 
    def test_new_as_xml(self):
 
        response = self.app.get(url('formatted_new_repo', format='xml'))
 

	
 
    def test_update(self):
 
        response = self.app.put(url('repo', repo_name='vcs_test'))
 

	
 
    def test_update_browser_fakeout(self):
 
        response = self.app.post(url('repo', repo_name='vcs_test'), params=dict(_method='put'))
 

	
 
    def test_delete(self):
 
        response = self.app.delete(url('repo', repo_name='vcs_test'))
 

	
 
    def test_delete_browser_fakeout(self):
 
        response = self.app.post(url('repo', repo_name='vcs_test'), params=dict(_method='delete'))
 

	
 
    def test_show(self):
 
        self.log_user()
 
        response = self.app.get(url('repo', repo_name='vcs_test'))
 

	
 
    def test_show_as_xml(self):
 
        response = self.app.get(url('formatted_repo', repo_name='vcs_test', format='xml'))
 

	
 
    def test_edit(self):
 
        response = self.app.get(url('edit_repo', repo_name='vcs_test'))
 

	
 
    def test_edit_as_xml(self):
 
        response = self.app.get(url('formatted_edit_repo', repo_name='vcs_test', format='xml'))
rhodecode/tests/functional/test_settings.py
Show inline comments
 
@@ -28,25 +28,25 @@ class TestSettingsController(TestControl
 
        
 
        
 
        print response
 
        
 
        #test if we have a message that fork is ok
 
        assert 'fork %s repository as %s task added' \
 
                      % (repo_name, fork_name) in response.session['flash'][0], 'No flash message about fork'
 
                      
 
        #test if the fork was created in the database
 
        fork_repo = self.sa.query(Repository).filter(Repository.repo_name == fork_name).one()
 
        
 
        assert fork_repo.repo_name == fork_name, 'wrong name of repo name in new db fork repo'
 
        assert fork_repo.fork.repo_name == repo_name, 'wron fork parrent'
 
        assert fork_repo.fork.repo_name == repo_name, 'wrong fork parrent'
 
        
 
        
 
        #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
rhodecode/tests/functional/test_summary.py
Show inline comments
 
from rhodecode.tests import *
 

	
 
class TestSummaryController(TestController):
 

	
 
    def test_index(self):
 
        self.log_user()
 
        response = self.app.get(url(controller='summary', action='index',repo_name='vcs_test'))
 
        print response
 
        assert """<img style="margin-bottom:2px" class="icon" title="public repository" alt="public" src="/images/icons/lock_open.png"/>""" in response.body
 
        
 
        # Test response...
0 comments (0 inline, 0 general)