Changeset - 758f64f3fbda
[Not reviewed]
beta
0 11 0
Marcin Kuzminski - 15 years ago 2010-11-05 21:55:30
marcin@python-works.com
extended repo creation by repo type. fixed fork creation to maintain repo type.
11 files changed with 92 insertions and 55 deletions:
0 comments (0 inline, 0 general)
rhodecode/controllers/settings.py
Show inline comments
 
@@ -151,7 +151,7 @@ class SettingsController(BaseController)
 
    def fork_create(self, repo_name):
 
        repo_model = RepoModel()
 
        c.repo_info = repo_model.get(repo_name)
 
        _form = RepoForkForm()()
 
        _form = RepoForkForm(old_data={'repo_type':c.repo_info.repo_type})()
 
        form_result = {}
 
        try:
 
            form_result = _form.to_python(dict(request.POST))
rhodecode/lib/base.py
Show inline comments
 
@@ -11,28 +11,28 @@ from rhodecode.lib.utils import get_repo
 
from rhodecode.model import meta
 
from rhodecode.model.hg import _get_repos_cached, \
 
    _get_repos_switcher_cached
 

	
 
from vcs import BACKENDS
 
class BaseController(WSGIController):
 
    
 

	
 
    def __before__(self):
 
        c.rhodecode_version = __version__
 
        c.rhodecode_name = config['rhodecode_title']
 
        c.repo_name = get_repo_slug(request)
 
        c.cached_repo_list = _get_repos_cached()
 
        c.repo_switcher_list = _get_repos_switcher_cached(c.cached_repo_list)
 
        
 
        c.backends = BACKENDS.keys()
 
        if c.repo_name:
 
            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()
 
    
 

	
 
    def __call__(self, environ, start_response):
 
        """Invoke the Controller"""
 
        # WSGIController.__call__ dispatches to the Controller method
rhodecode/lib/celerylib/tasks.py
Show inline comments
 
@@ -289,18 +289,20 @@ def send_email(recipients, subject, body
 

	
 
@task
 
def create_repo_fork(form_data, cur_user):
 
    import os
 
    from rhodecode.model.repo import RepoModel
 

	
 
    from vcs import get_backend
 
    log = create_repo_fork.get_logger()
 
    repo_model = RepoModel(get_session())
 
    repo_model.create(form_data, cur_user, just_db=True, fork=True)
 

	
 
    repos_path = get_hg_ui_settings()['paths_root_path'].replace('*', '')
 
    repo_path = os.path.join(repos_path, form_data['repo_name'])
 
    repo_name = form_data['repo_name']
 
    repos_path = get_hg_ui_settings()['paths_root_path']
 
    repo_path = os.path.join(repos_path, repo_name)
 
    repo_fork_path = os.path.join(repos_path, form_data['fork_name'])
 
    alias = form_data['repo_type']
 

	
 
    MercurialRepository(str(repo_fork_path), True, clone_url=str(repo_path))
 

	
 
    log.info('creating repo fork %s as %s', repo_name, repo_path)
 
    backend = get_backend(alias)
 
    backend(str(repo_fork_path), create=True, src_url=str(repo_path))
 

	
 
def __get_codes_stats(repo_name):
 
    LANGUAGES_EXTENSIONS = ['action', 'adp', 'ashx', 'asmx',
rhodecode/lib/utils.py
Show inline comments
 
@@ -345,8 +345,9 @@ def repo2db_mapper(initial_repo_list, re
 
            form_data = {
 
                         'repo_name':name,
 
                         'repo_type':repo.alias,
 
                         'description':repo.description if repo.description != 'unknown' else \
 
                                        'auto description for %s' % name,
 
                         'description':repo.description \
 
                            if repo.description != 'unknown' else \
 
                                        '%s repository' % name,
 
                         'private':False
 
                         }
 
            rm.create(form_data, user, just_db=True)
rhodecode/model/forms.py
Show inline comments
 
@@ -30,6 +30,7 @@ from rhodecode.model.user import UserMod
 
from rhodecode.model.repo import RepoModel
 
from rhodecode.model.db import User
 
from webhelpers.pylonslib.secure_form import authentication_token
 
from vcs import BACKENDS
 
import formencode
 
import logging
 
import os
 
@@ -147,6 +148,15 @@ def ValidRepoName(edit, old_data):
 

	
 
    return _ValidRepoName
 

	
 
def ValidForkType(old_data):
 
    class _ValidForkType(formencode.validators.FancyValidator):
 

	
 
        def to_python(self, value, state):
 
            if old_data['repo_type'] != value:
 
                raise formencode.Invalid(_('Fork have to be the same type as original'), value, state)
 
            return value
 
    return _ValidForkType
 

	
 
class ValidPerms(formencode.validators.FancyValidator):
 
    messages = {'perm_new_user_name':_('This username is not valid')}
 

	
 
@@ -292,7 +302,7 @@ def RepoForm(edit=False, old_data={}):
 
        repo_name = All(UnicodeString(strip=True, min=1, not_empty=True), ValidRepoName(edit, old_data))
 
        description = UnicodeString(strip=True, min=1, not_empty=True)
 
        private = StringBoolean(if_missing=False)
 

	
 
        repo_type = OneOf(BACKENDS.keys())
 
        if edit:
 
            user = All(Int(not_empty=True), ValidRepoUser)
 

	
 
@@ -306,7 +316,7 @@ def RepoForkForm(edit=False, old_data={}
 
        fork_name = All(UnicodeString(strip=True, min=1, not_empty=True), ValidRepoName(edit, old_data))
 
        description = UnicodeString(strip=True, min=1, not_empty=True)
 
        private = StringBoolean(if_missing=False)
 

	
 
        repo_type = All(ValidForkType(old_data), OneOf(BACKENDS.keys()))
 
    return _RepoForkForm
 

	
 
def RepoSettingsForm(edit=False, old_data={}):
rhodecode/model/repo.py
Show inline comments
 
@@ -21,7 +21,7 @@ Created on Jun 5, 2010
 
model for handling repositories actions
 
:author: marcink
 
"""
 

	
 
from vcs.backends import get_repo, get_backend
 
from datetime import datetime
 
from pylons import app_globals as g
 
from rhodecode.model.db import Repository, RepoToPerm, User, Permission
 
@@ -151,7 +151,7 @@ class RepoModel(object):
 
            self.sa.add(repo_to_perm)
 
            self.sa.commit()
 
            if not just_db:
 
                self.__create_repo(repo_name)
 
                self.__create_repo(repo_name, form_data['repo_type'])
 
        except:
 
            log.error(traceback.format_exc())
 
            self.sa.rollback()
 
@@ -182,13 +182,13 @@ class RepoModel(object):
 
            self.sa.rollback()
 
            raise
 

	
 
    def __create_repo(self, repo_name):
 
    def __create_repo(self, repo_name, alias):
 
        from rhodecode.lib.utils import check_repo
 
        repo_path = os.path.join(g.base_path, repo_name)
 
        if check_repo(repo_name, g.base_path):
 
            log.info('creating repo %s in %s', repo_name, repo_path)
 
            from vcs.backends.hg import MercurialRepository
 
            MercurialRepository(repo_path, create=True)
 
            backend = get_backend(alias)
 
            backend(repo_path, create=True)
 

	
 
    def __rename_repo(self, old, new):
 
        log.info('renaming repo from %s to %s', old, new)
rhodecode/templates/admin/repos/repo_add.html
Show inline comments
 
@@ -35,6 +35,14 @@
 
	            </div>
 
             </div>
 
            <div class="field">
 
                <div class="label">
 
                    <label for="repo_type">${_('Type')}:</label>
 
                </div>
 
                <div class="input">
 
                    ${h.select('repo_type','hg',c.backends,class_="small")}
 
                </div>
 
             </div>             
 
            <div class="field">
 
                <div class="label label-textarea">
 
                    <label for="description">${_('Description')}:</label>
 
                </div>
rhodecode/templates/admin/repos/repo_add_create_repository.html
Show inline comments
 
@@ -32,6 +32,14 @@
 
	            </div>
 
             </div>
 
            <div class="field">
 
                <div class="label">
 
                    <label for="repo_type">${_('Type')}:</label>
 
                </div>
 
                <div class="input">
 
                    ${h.select('repo_type','hg',c.backends,class_="small")}
 
                </div>
 
             </div>             
 
            <div class="field">
 
                <div class="label label-textarea">
 
                    <label for="description">${_('Description')}:</label>
 
                </div>
rhodecode/templates/admin/repos/repo_edit.html
Show inline comments
 
@@ -35,7 +35,14 @@
 
                    ${h.text('repo_name',class_="small")}
 
                </div>
 
             </div>
 
             
 
            <div class="field">
 
                <div class="label">
 
                    <label for="repo_type">${_('Type')}:</label>
 
                </div>
 
                <div class="input">
 
                    ${h.select('repo_type','hg',c.backends,class_="small")}
 
                </div>
 
             </div>             
 
            <div class="field">
 
                <div class="label label-textarea">
 
                    <label for="description">${_('Description')}:</label>
rhodecode/templates/settings/repo_fork.html
Show inline comments
 
@@ -30,6 +30,7 @@
 
	            </div>
 
	            <div class="input">
 
	                ${h.text('fork_name',class_="small")}
 
	                ${h.hidden('repo_type',c.repo_info.repo_type)}
 
	            </div>
 
             </div>
 
            <div class="field">
rhodecode/tests/functional/test_login.py
Show inline comments
 
@@ -17,8 +17,8 @@ class TestLoginController(TestController
 
        assert response.status == '302 Found', 'Wrong response code from login got %s' % response.status
 
        assert response.session['rhodecode_user'].username == 'test_admin', 'wrong logged in user'
 
        response = response.follow()
 
        assert 'auto description for vcs_test' in response.body
 
    
 
        assert 'vcs_test repository' in response.body
 

	
 
    def test_login_regular_ok(self):
 
        response = self.app.post(url(controller='login', action='index'),
 
                                 {'username':'test_regular',
 
@@ -27,9 +27,9 @@ class TestLoginController(TestController
 
        assert response.status == '302 Found', 'Wrong response code from login got %s' % response.status
 
        assert response.session['rhodecode_user'].username == 'test_regular', 'wrong logged in user'
 
        response = response.follow()
 
        assert 'auto description for vcs_test' in response.body
 
        assert 'vcs_test repository' in response.body
 
        assert '<a title="Admin" href="/_admin">' not in response.body
 
    
 

	
 
    def test_login_ok_came_from(self):
 
        test_came_from = '/_admin/users'
 
        response = self.app.post(url(controller='login', action='index', came_from=test_came_from),
 
@@ -37,11 +37,11 @@ class TestLoginController(TestController
 
                                  'password':'test12'})
 
        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',
 
@@ -55,15 +55,15 @@ class TestLoginController(TestController
 
                                 {'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):
 
        response = self.app.get(url(controller='login', action='register'))
 
        assert 'Sign Up to rhodecode' in response.body, 'wrong page for user registration'
 
        
 

	
 
    def test_register_err_same_username(self):
 
        response = self.app.post(url(controller='login', action='register'),
 
                                            {'username':'test_admin',
 
@@ -71,10 +71,10 @@ class TestLoginController(TestController
 
                                             'email':'goodmail@domain.com',
 
                                             'name':'test',
 
                                             'lastname':'test'})
 
        
 

	
 
        assert response.status == '200 OK', 'Wrong response from register page got %s' % response.status
 
        assert 'This username already exists' in response.body 
 
        
 
        assert 'This username already exists' in response.body
 

	
 
    def test_register_err_wrong_data(self):
 
        response = self.app.post(url(controller='login', action='register'),
 
                                            {'username':'xs',
 
@@ -82,20 +82,20 @@ class TestLoginController(TestController
 
                                             'email':'goodmailm',
 
                                             'name':'test',
 
                                             'lastname':'test'})
 
        
 

	
 
        assert response.status == '200 OK', 'Wrong response from register page got %s' % response.status
 
        assert 'An email address must contain a single @' in response.body
 
        assert 'Please enter a value' in response.body
 
        
 
        
 
        
 

	
 

	
 

	
 
    def test_register_ok(self):
 
        username = 'test_regular4'
 
        password = 'qweqwe'
 
        email = 'marcin@test.com'
 
        name = 'testname'
 
        lastname = 'testlastname'
 
        
 

	
 
        response = self.app.post(url(controller='login', action='register'),
 
                                            {'username':username,
 
                                             'password':password,
 
@@ -103,23 +103,23 @@ class TestLoginController(TestController
 
                                             'name':name,
 
                                             'lastname':lastname})
 
        print response.body
 
        assert response.status == '302 Found', 'Wrong response from register page got %s' % response.status        
 
        assert response.status == '302 Found', 'Wrong response from register page got %s' % response.status
 
        assert 'You have successfully registered into rhodecode' in response.session['flash'][0], 'No flash message about user registration'
 
        
 

	
 
        ret = self.sa.query(User).filter(User.username == 'test_regular4').one()
 
        assert ret.username == username , 'field mismatch %s %s' % (ret.username, username)
 
        assert check_password(password, ret.password) == True , 'password mismatch'
 
        assert ret.email == email , 'field mismatch %s %s' % (ret.email, email)
 
        assert ret.name == name , 'field mismatch %s %s' % (ret.name, name)
 
        assert ret.lastname == lastname , 'field mismatch %s %s' % (ret.lastname, lastname)
 
    
 
        
 
    def test_forgot_password_wrong_mail(self):    
 

	
 

	
 
    def test_forgot_password_wrong_mail(self):
 
        response = self.app.post(url(controller='login', action='password_reset'),
 
                                            {'email':'marcin@wrongmail.org', })
 
        
 

	
 
        assert "That e-mail address doesn't exist" in response.body, 'Missing error message about wrong email'
 
                
 

	
 
    def test_forgot_password(self):
 
        response = self.app.get(url(controller='login', action='password_reset'))
 
        assert response.status == '200 OK', 'Wrong response from login page got %s' % response.status
 
@@ -129,19 +129,19 @@ class TestLoginController(TestController
 
        email = 'marcin@python-works.com'
 
        name = 'passwd'
 
        lastname = 'reset'
 
                
 

	
 
        response = self.app.post(url(controller='login', action='register'),
 
                                            {'username':username,
 
                                             'password':password,
 
                                             'email':email,
 
                                             'name':name,
 
                                             'lastname':lastname})        
 
                                             'lastname':lastname})
 
        #register new user for email test
 
        response = self.app.post(url(controller='login', action='password_reset'),
 
                                            {'email':email, })
 
        print response.session['flash']
 
        assert 'You have successfully registered into rhodecode' in response.session['flash'][0], 'No flash message about user registration'
 
        assert 'Your new password was sent' in response.session['flash'][1], 'No flash message about password reset'
 
        
 
        
 
        
 

	
 

	
 

	
0 comments (0 inline, 0 general)