Changeset - 53aa1ee1af86
[Not reviewed]
default
0 6 0
Marcin Kuzminski - 15 years ago 2010-10-01 02:04:32
marcin@python-works.com
updated tests for new version 6char password etc...
6 files changed with 64 insertions and 15 deletions:
0 comments (0 inline, 0 general)
celeryconfig.py
Show inline comments
 
# List of modules to import when celery starts.
 
import sys
 
import os
 
import ConfigParser
 
root = os.getcwd()
 

	
 
PYLONS_CONFIG_NAME = 'production.ini'
 
PYLONS_CONFIG_NAME = 'test.ini'
 

	
 
sys.path.append(root)
 
config = ConfigParser.ConfigParser({'here':root})
 
config.read('%s/%s' % (root, PYLONS_CONFIG_NAME))
 
PYLONS_CONFIG = config
 

	
 
CELERY_IMPORTS = ("pylons_app.lib.celerylib.tasks",)
 

	
 
## Result store settings.
 
CELERY_RESULT_BACKEND = "database"
 
CELERY_RESULT_DBURI = dict(config.items('app:main'))['sqlalchemy.db1.url']
 
CELERY_RESULT_SERIALIZER = 'json'
 
@@ -31,24 +31,27 @@ BROKER_PASSWORD = "qweqwe"
 
## Worker settings
 
## If you're doing mostly I/O you can have more processes,
 
## but if mostly spending CPU, try to keep it close to the
 
## number of CPUs on your machine. If not set, the number of CPUs/cores
 
## available will be used.
 
CELERYD_CONCURRENCY = 2
 
# CELERYD_LOG_FILE = "celeryd.log"
 
CELERYD_LOG_LEVEL = "DEBUG"
 
CELERYD_MAX_TASKS_PER_CHILD = 3
 

	
 
#Tasks will never be sent to the queue, but executed locally instead.
 
CELERY_ALWAYS_EAGER = False
 
if PYLONS_CONFIG_NAME == 'test.ini':
 
    #auto eager for tests
 
    CELERY_ALWAYS_EAGER = True
 

	
 
#===============================================================================
 
# EMAIL SETTINGS
 
#===============================================================================
 
pylons_email_config = dict(config.items('DEFAULT'))
 

	
 
CELERY_SEND_TASK_ERROR_EMAILS = True
 

	
 
#List of (name, email_address) tuples for the admins that should receive error e-mails.
 
ADMINS = [('Administrator', pylons_email_config.get('email_to'))]
 

	
 
#The e-mail address this worker sends e-mails from. Default is "celery@localhost".
pylons_app/lib/db_manage.py
Show inline comments
 
@@ -79,27 +79,27 @@ class DbManage(object):
 
        meta.Base.metadata.create_all(checkfirst=checkfirst)
 
        log.info('Created tables for %s', self.dbname)
 
    
 
    def admin_prompt(self):
 
        if not self.tests:
 
            import getpass
 
            username = raw_input('Specify admin username:')
 
            password = getpass.getpass('Specify admin password:')
 
            email = raw_input('Specify admin email:')
 
            self.create_user(username, password, email, True)
 
        else:
 
            log.info('creating admin and regular test users')
 
            self.create_user('test_admin', 'test', 'test_admin@mail.com', True)
 
            self.create_user('test_regular', 'test', 'test_regular@mail.com', False)
 
            self.create_user('test_regular2', 'test', 'test_regular2@mail.com', False)
 
            self.create_user('test_admin', 'test12', 'test_admin@mail.com', True)
 
            self.create_user('test_regular', 'test12', 'test_regular@mail.com', False)
 
            self.create_user('test_regular2', 'test12', 'test_regular2@mail.com', False)
 
            
 
        
 
    
 
    def config_prompt(self, test_repo_path=''):
 
        log.info('Setting up repositories config')
 
        
 
        if not self.tests and not test_repo_path:
 
            path = raw_input('Specify valid full path to your repositories'
 
                        ' you can change this later in application settings:')
 
        else:
 
            path = test_repo_path
 
            
pylons_app/tests/__init__.py
Show inline comments
 
@@ -33,19 +33,19 @@ environ = {}
 

	
 
class TestController(TestCase):
 

	
 
    def __init__(self, *args, **kwargs):
 
        wsgiapp = pylons.test.pylonsapp
 
        config = wsgiapp.config
 
        self.app = TestApp(wsgiapp)
 
        url._push_object(URLGenerator(config['routes.map'], environ))
 
        self.sa = meta.Session
 

	
 
        TestCase.__init__(self, *args, **kwargs)
 
    
 
    def log_user(self, username='test_admin', password='test'):
 
    def log_user(self, username='test_admin', password='test12'):
 
        response = self.app.post(url(controller='login', action='index'),
 
                                 {'username':username,
 
                                  'password':password})
 
        assert response.status == '302 Found', 'Wrong response code from login got %s' % response.status
 
        assert response.session['hg_app_user'].username == 'test_admin', 'wrong logged in user'
 
        assert response.session['hg_app_user'].username == username, 'wrong logged in user got %s expected %s' % (response.session['hg_app_user'].username, username)
 
        return response.follow()
pylons_app/tests/functional/test_admin_settings.py
Show inline comments
 
@@ -69,48 +69,48 @@ class TestSettingsController(TestControl
 
        print response.session
 
        assert 'Your account was updated succesfully' in response.session['flash'][0][1], 'no flash message about success of change'
 
        user = self.sa.query(User).filter(User.username == 'test_admin').one()
 
        assert user.email == new_email , 'incorrect user email after update got %s vs %s' % (user.email, new_email)
 
    
 
    def test_my_account_update_own_email_ok(self):
 
        self.log_user()
 
                
 
        new_email = 'new@mail.pl'
 
        response = self.app.post(url('admin_settings_my_account_update'), params=dict(
 
                                                            _method='put',
 
                                                            username='test_admin',
 
                                                            new_password='test',
 
                                                            new_password='test12',
 
                                                            name='NewName',
 
                                                            lastname='NewLastname',
 
                                                            email=new_email,))
 
        print response
 
                
 
    def test_my_account_update_err_email_exists(self):
 
        self.log_user()
 
                
 
        new_email = 'test_regular@mail.com'#already exisitn email
 
        response = self.app.post(url('admin_settings_my_account_update'), params=dict(
 
                                                            _method='put',
 
                                                            username='test_admin',
 
                                                            new_password='test',
 
                                                            new_password='test12',
 
                                                            name='NewName',
 
                                                            lastname='NewLastname',
 
                                                            email=new_email,))
 
        print response
 
        
 
        assert 'That e-mail address is already taken' in response.body, 'Missing error message about existing email'
 
        
 
        
 
    def test_my_account_update_err(self):
 
        self.log_user()
 
        self.log_user('test_regular2', 'test12')
 
                
 
        new_email = 'newmail.pl'
 
        response = self.app.post(url('admin_settings_my_account_update'), params=dict(
 
                                                            _method='put',
 
                                                            username='test_regular2',
 
                                                            new_password='test',
 
                                                            username='test_admin',
 
                                                            new_password='test12',
 
                                                            name='NewName',
 
                                                            lastname='NewLastname',
 
                                                            email=new_email,))
 
        print response
 
        assert 'An email address must contain a single @' in response.body, 'Missing error message about wrong email'
 
        assert 'This username already exists' in response.body, 'Missing error message about existing user'
pylons_app/tests/functional/test_login.py
Show inline comments
 
@@ -14,51 +14,60 @@ class TestLoginController(TestController
 
        response = self.app.post(url(controller='login', action='index'),
 
                                 {'username':'test_admin',
 
                                  'password':'test'})
 
        assert response.status == '302 Found', 'Wrong response code from login got %s' % response.status
 
        assert response.session['hg_app_user'].username == 'test_admin', 'wrong logged in user'
 
        response = response.follow()
 
        assert 'auto description for vcs_test' in response.body
 
    
 
    def test_login_regular_ok(self):
 
        response = self.app.post(url(controller='login', action='index'),
 
                                 {'username':'test_regular',
 
                                  'password':'test'})
 
        print response
 
        assert response.status == '302 Found', 'Wrong response code from login got %s' % response.status
 
        assert response.session['hg_app_user'].username == 'test_regular', 'wrong logged in user'
 
        response = response.follow()
 
        assert 'auto description for vcs_test' 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),
 
                                 {'username':'test_admin',
 
                                  'password':'test'})
 
        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_wrong(self):
 
    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'
 

	
 
    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):
 
        response = self.app.get(url(controller='login', action='register'))
 
        assert 'Sign Up to hg-app' 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',
 
                                             'password':'test',
 
                                             'email':'goodmail@domain.com',
 
                                             'name':'test',
 
                                             'lastname':'test'})
 
@@ -67,26 +76,25 @@ class TestLoginController(TestController
 
        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',
 
                                             'password':'',
 
                                             '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 'Enter a value 3 characters long or more' in response.body
 
        assert 'Please enter a value<' 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,
pylons_app/tests/functional/test_settings.py
Show inline comments
 
from pylons_app.model.db import Repository
 
from pylons_app.tests import *
 

	
 
class TestSettingsController(TestController):
 

	
 
    def test_index(self):
 
        self.log_user()
 
        response = self.app.get(url(controller='settings', action='index',
 
                                    repo_name='vcs_test'))
 
        # Test response...
 
    
 
    def test_fork(self):
 
        self.log_user()
 
        response = self.app.get(url(controller='settings', action='fork',
 
                                    repo_name='vcs_test'))
 
        
 

	
 
    def test_fork_create(self):
 
        self.log_user()
 
        fork_name = 'vcs_test_fork'
 
        description = 'fork of vcs test'
 
        repo_name = 'vcs_test'
 
        response = self.app.post(url(controller='settings', action='fork_create',
 
                                    repo_name=repo_name),
 
                                    {'fork_name':fork_name,
 
                                     'description':description,
 
                                     'private':'False'})
 
        
 
        
 
        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'
 
        
 
        
 
        #test if fork is visible in the list ?
 
        response.follow()
 
        
 
        print response
 
        assert False
0 comments (0 inline, 0 general)