Skip to content
This repository was archived by the owner on Oct 24, 2018. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
4bafc95
better runner, use wsgidav.config_file param instead of env var
inkhey May 21, 2018
40aa603
convert webdav as plaster pastedeploy app
inkhey May 21, 2018
6941b04
fix renaming of main function
inkhey May 24, 2018
a701fd8
add tests for user, permission and controller models
inkhey May 24, 2018
8d6247f
Merge branch 'feature/51_restore_mail_notifier' into fix/few_more_tests
inkhey May 24, 2018
f32874f
add better test for commandes
inkhey May 24, 2018
fdc6dd8
Refactor WebdavFactory + test config initialisation for wsgidav
inkhey May 25, 2018
de19c9e
better tests for user commands + tests for group_api + some fixe in g…
inkhey May 28, 2018
6f399a4
Merge branch 'fix/better_runner' of github.com:tracim/tracim_backend …
inkhey May 28, 2018
13d06d1
Merge branch 'develop' of github.com:tracim/tracim_backend into fix/f…
inkhey May 28, 2018
ce7da76
Merge branch 'fix/59_global_exception_handling' of github.com:tracim/…
inkhey May 28, 2018
fee8ec3
Merge branch 'feature/578_add_api_for_workspace/apps' of github.com:t…
inkhey May 28, 2018
9f40425
force LEVEL warning for tests
inkhey May 28, 2018
16284fd
remove uneeded id of profil/role + better schema with description/exa…
inkhey May 29, 2018
7435df0
merge with Feature/578
inkhey Jun 11, 2018
adb6e8d
merge with better_api_doc
inkhey Jun 11, 2018
4567eee
merge with upstream
inkhey Jun 11, 2018
5fc4c05
Merge branch 'feature/578_add_api_for_workspace/apps' of github.com:t…
inkhey Jun 11, 2018
1522357
Merge branch 'feature/578_add_api_for_workspace/apps' of github.com:t…
inkhey Jun 14, 2018
3eba208
Merge branch 'fix/better_api_doc' of github.com:tracim/tracim_backend…
inkhey Jun 14, 2018
d6663b1
Merge branch 'develop' into fix/better_api_doc
inkhey Jun 18, 2018
8f086d4
repair test post-merge
inkhey Jun 18, 2018
6cda69f
Merge branch 'fix/better_api_doc' of github.com:tracim/tracim_backend…
inkhey Jun 18, 2018
b5dedb4
remove temp file
inkhey Jun 18, 2018
302ad90
code style
buxx Jun 18, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,11 @@ run wsgidav server:

tracimcli webdav start


## Run Tests and others checks ##

### Run Tests ###

Before running some functional test related to email, you need a local working *MailHog*
see here : https://github.com/mailhog/MailHog

Expand Down
10 changes: 9 additions & 1 deletion tests_configs.ini
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,14 @@ depot_storage_dir = /tmp/test/depot
user.auth_token.validity = 604800
preview_cache_dir = /tmp/test/preview_cache

[app:command_test]
use = egg:tracim_backend
sqlalchemy.url = sqlite:///tracim_test.sqlite
depot_storage_name = test
depot_storage_dir = /tmp/test/depot
user.auth_token.validity = 604800
preview_cache_dir = /tmp/test/preview_cache

[mail_test]
sqlalchemy.url = sqlite:///:memory:
depot_storage_name = test
Expand Down Expand Up @@ -54,4 +62,4 @@ email.processing_mode = async
email.notification.smtp.server = 127.0.0.1
email.notification.smtp.port = 1025
email.notification.smtp.user = test_user
email.notification.smtp.password = just_a_password
email.notification.smtp.password = just_a_password
3 changes: 2 additions & 1 deletion tracim/command/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

from pyramid.paster import bootstrap
from pyramid.scripting import AppEnvironment
from tracim.exceptions import CommandAbortedError
from tracim.exceptions import BadCommandError
from tracim.lib.utils.utils import DEFAULT_TRACIM_CONFIG_FILE


Expand Down Expand Up @@ -56,6 +56,7 @@ def take_action(self, parsed_args: argparse.Namespace) -> None:
with app_context['request'].tm:
self.take_app_action(parsed_args, app_context)


def get_parser(self, prog_name: str) -> argparse.ArgumentParser:
parser = super(AppContextCommand, self).get_parser(prog_name)

Expand Down
31 changes: 19 additions & 12 deletions tracim/command/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,15 @@
from pyramid.scripting import AppEnvironment
import transaction
from sqlalchemy.exc import IntegrityError
from sqlalchemy.orm.exc import NoResultFound

from tracim import CFG
from tracim.command import AppContextCommand
from tracim.command import Extender
#from tracim.lib.auth.ldap import LDAPAuth
#from tracim.lib.daemons import DaemonsManager
#from tracim.lib.daemons import RadicaleDaemon
#from tracim.lib.email import get_email_manager
from tracim.exceptions import AlreadyExistError
from tracim.exceptions import UserAlreadyExistError
from tracim.exceptions import GroupDoesNotExist
from tracim.exceptions import NotificationNotSend
from tracim.exceptions import CommandAbortedError
from tracim.exceptions import BadCommandError
from tracim.lib.core.group import GroupApi
from tracim.lib.core.user import UserApi
from tracim.models import User
Expand Down Expand Up @@ -85,13 +83,22 @@ def _user_exist(self, login: str) -> User:
return self._user_api.user_with_email_exists(login)

def _get_group(self, name: str) -> Group:
groups_availables = [group.group_name
for group in self._group_api.get_all()]
if name not in groups_availables:
msg = "Group '{}' does not exist, choose a group name in : ".format(name) # nopep8
for group in groups_availables:
msg+= "'{}',".format(group)
self._session.rollback()
raise GroupDoesNotExist(msg)
return self._group_api.get_one_with_name(name)

def _add_user_to_named_group(
self,
user: str,
group_name: str
) -> None:

group = self._get_group(group_name)
if user not in group.users:
group.users.append(user)
Expand All @@ -116,7 +123,7 @@ def _create_user(
) -> User:
if not password:
if self._password_required():
raise CommandAbortedError(
raise BadCommandError(
"You must provide -p/--password parameter"
)
password = ''
Expand All @@ -135,7 +142,7 @@ def _create_user(
self._user_api.execute_created_user_actions(user)
except IntegrityError:
self._session.rollback()
raise AlreadyExistError()
raise UserAlreadyExistError()
except NotificationNotSend as exception:
self._session.rollback()
raise exception
Expand Down Expand Up @@ -182,10 +189,10 @@ def _proceed_user(self, parsed_args: argparse.Namespace) -> User:
password=parsed_args.password,
do_notify=parsed_args.send_email,
)
except AlreadyExistError:
raise CommandAbortedError("Error: User already exist (use `user update` command instead)")
except UserAlreadyExistError:
raise UserAlreadyExistError("Error: User already exist (use `user update` command instead)")
except NotificationNotSend:
raise CommandAbortedError("Error: Cannot send email notification, user not created.")
raise NotificationNotSend("Error: Cannot send email notification, user not created.")
# TODO - G.M - 04-04-2018 - [Email] Check this code
# if parsed_args.send_email:
# email_manager = get_email_manager()
Expand Down Expand Up @@ -243,5 +250,5 @@ class UpdateUserCommand(UserCommand):
action = UserCommand.ACTION_UPDATE


class LDAPUserUnknown(CommandAbortedError):
class LDAPUserUnknown(BadCommandError):
pass
18 changes: 9 additions & 9 deletions tracim/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,11 @@ class ConfigurationError(TracimError):
pass


class AlreadyExistError(TracimError):
class UserAlreadyExistError(TracimError):
pass


class CommandError(TracimError):
pass


class CommandAbortedError(CommandError):
class BadCommandError(TracimError):
pass


Expand Down Expand Up @@ -93,13 +89,17 @@ class WrongUserPassword(TracimException):
pass


class UserDoesNotExist(TracimException):
class NotificationNotSend(TracimException):
pass


class UserNotFoundInTracimRequest(TracimException):
class GroupDoesNotExist(TracimError):
pass


class NotificationNotSend(TracimException):
class UserDoesNotExist(TracimException):
pass


class UserNotFoundInTracimRequest(TracimException):
pass
19 changes: 17 additions & 2 deletions tracim/lib/core/group.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
# -*- coding: utf-8 -*-
import typing

from sqlalchemy.orm.exc import NoResultFound

from tracim.exceptions import GroupDoesNotExist
from tracim import CFG


__author__ = 'damien'

from tracim.models.auth import Group, User
Expand All @@ -26,7 +30,18 @@ def _base_query(self) -> Query:
return self._session.query(Group)

def get_one(self, group_id) -> Group:
return self._base_query().filter(Group.group_id == group_id).one()
try:
group = self._base_query().filter(Group.group_id == group_id).one()
return group
except NoResultFound:
raise GroupDoesNotExist()

def get_one_with_name(self, group_name) -> Group:
return self._base_query().filter(Group.group_name == group_name).one()
try:
group = self._base_query().filter(Group.group_name == group_name).one()
return group
except NoResultFound:
raise GroupDoesNotExist()

def get_all(self):
return self._base_query().order_by(Group.group_id).all()
31 changes: 22 additions & 9 deletions tracim/tests/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,9 @@ class FunctionalTest(unittest.TestCase):
sqlalchemy_url = 'sqlite:///tracim_test.sqlite'

def setUp(self):
logger._logger.setLevel('WARNING')
DepotManager._clear()
settings = {
self.settings = {
'sqlalchemy.url': self.sqlalchemy_url,
'user.auth_token.validity': '604800',
'depot_storage_dir': '/tmp/test/depot',
Expand All @@ -45,19 +46,24 @@ def setUp(self):

}
hapic.reset_context()
app = web({}, **settings)
self.init_database(settings)
self.engine = get_engine(self.settings)
DeclarativeBase.metadata.create_all(self.engine)
self.session_factory = get_session_factory(self.engine)
self.app_config = CFG(self.settings)
self.app_config.configure_filedepot()
self.init_database(self.settings)
DepotManager._clear()
self.run_app()

def run_app(self):
app = web({}, **self.settings)
self.testapp = TestApp(app)

def init_database(self, settings):
self.engine = get_engine(settings)
DeclarativeBase.metadata.create_all(self.engine)
session_factory = get_session_factory(self.engine)
app_config = CFG(settings)
with transaction.manager:
dbsession = get_tm_session(session_factory, transaction.manager)
dbsession = get_tm_session(self.session_factory, transaction.manager)
try:
fixtures_loader = FixturesLoader(dbsession, app_config)
fixtures_loader = FixturesLoader(dbsession, self.app_config)
fixtures_loader.loads(self.fixtures)
transaction.commit()
print("Database initialized.")
Expand Down Expand Up @@ -90,6 +96,12 @@ def init_database(self, settings):
self.engine = get_engine(settings)


class CommandFunctionalTest(FunctionalTest):

def run_app(self):
self.session = get_tm_session(self.session_factory, transaction.manager)


class BaseTest(unittest.TestCase):
"""
Pyramid default test.
Expand All @@ -99,6 +111,7 @@ class BaseTest(unittest.TestCase):
config_section = 'base_test'

def setUp(self):
logger._logger.setLevel('WARNING')
logger.debug(self, 'Setup Test...')
self.settings = plaster.get_settings(
self.config_uri,
Expand Down
Loading