示例#1
0
def set_authentications(methods):
    saved_methods = config.get('session', 'authentications')
    config.set('session', 'authentications', methods)
    try:
        yield
    finally:
        config.set('session', 'authentications', saved_methods)
示例#2
0
    def test_authentication_option_ip_address(self):
        "Test authentication with ip_address option"
        pool = Pool()
        User = pool.get('res.user')

        user = User(login='******')
        user.save()

        ip_network = config.get('session',
                                'authentication_ip_network',
                                default='')
        config.set('session', 'authentication_ip_network',
                   '192.168.0.0/16,127.0.0.0/8')
        self.addCleanup(config.set, 'session', 'authentication_ip_network',
                        ip_network)

        with patch.object(User, '_login_always', create=True) as always, \
                patch.object(User, '_login_never', create=True) as never:
            always.return_value = user.id
            never.return_value = None

            with set_authentications('always+never?ip_address'):
                for address, result in [
                    ('192.168.0.1', user.id),
                    ('172.17.0.1', None),
                    ('127.0.0.1', user.id),
                ]:
                    with self.subTest(address=address):
                        with Transaction().set_context(_request={
                                'remote_addr': address,
                        }):
                            self.assertEqual(User.get_login('user', {}),
                                             result)
    def setUp(self):
        super().setUp()
        activate_module('company')

        methods = config.get('session', 'authentications', default='')
        config.set('session', 'authentications', 'totp')
        self.addCleanup(config.set, 'session', 'authentications', methods)
 def setUp(self):
     super(LDAPAuthenticationTestCase, self).setUp()
     methods = config.get('session', 'authentications')
     config.set('session', 'authentications', 'ldap')
     self.addCleanup(config.set, 'session', 'authentications', methods)
     config.add_section(section)
     config.set(section, 'uri', 'ldap://localhost/dc=tryton,dc=org')
     self.addCleanup(config.remove_section, section)
 def setUp(self):
     super(LDAPAuthenticationTestCase, self).setUp()
     methods = config.get('session', 'authentications')
     config.set('session', 'authentications', 'ldap')
     self.addCleanup(config.set, 'session', 'authentications', methods)
     config.add_section(section)
     config.set(section, 'uri', 'ldap://localhost/dc=tryton,dc=org')
     self.addCleanup(config.remove_section, section)
示例#6
0
    def run(self):
        from trytond.config import config
        config.set('database', 'uri',
                   'postgresql://*****:*****@localhost:5432/')

        os.environ['DB_NAME'] = 'test_' + str(int(time.time()))

        from tests import suite
        test_result = unittest.TextTestRunner(verbosity=3).run(suite())

        if test_result.wasSuccessful():
            sys.exit(0)
        sys.exit(-1)
    def run(self):
        from trytond.config import config

        config.set("database", "uri", "postgresql://*****:*****@localhost:5432/")

        os.environ["DB_NAME"] = "test_" + str(int(time.time()))

        from tests import suite

        test_result = unittest.TextTestRunner(verbosity=3).run(suite())

        if test_result.wasSuccessful():
            sys.exit(0)
        sys.exit(-1)
示例#8
0
    def run(self):
        from trytond.config import config
        config.set(
            'database', 'uri', 'postgresql://*****:*****@localhost:5432/'
        )

        os.environ['DB_NAME'] = 'test_' + str(int(time.time()))

        from tests import suite
        test_result = unittest.TextTestRunner(verbosity=3).run(suite())

        if test_result.wasSuccessful():
            sys.exit(0)
        sys.exit(-1)
    def run(self):
        if self.distribution.tests_require:
            self.distribution.fetch_build_eggs(self.distribution.tests_require)

        from trytond.config import config
        os.environ['TRYTOND_DATABASE_URI'] = 'sqlite://'
        config.set('email', 'from', '*****@*****.**')
        os.environ['DB_NAME'] = ':memory:'

        from tests import suite
        test_result = unittest.TextTestRunner(verbosity=3).run(suite())

        if test_result.wasSuccessful():
            sys.exit(0)
        sys.exit(-1)
    def run(self):
        if self.distribution.tests_require:
            self.distribution.fetch_build_eggs(self.distribution.tests_require)

        from trytond.config import config

        os.environ["TRYTOND_DATABASE_URI"] = "sqlite://"
        config.set("email", "from", "*****@*****.**")
        os.environ["DB_NAME"] = ":memory:"

        from tests import suite

        test_result = unittest.TextTestRunner(verbosity=3).run(suite())

        if test_result.wasSuccessful():
            sys.exit(0)
        sys.exit(-1)
def install_module(request):
    """Install tryton module in specified database.
     """
    reuse_db = request.config.getoption("--reuse-db")

    if request.config.getoption("--db") == 'sqlite':
        os.environ['TRYTOND_DATABASE_URI'] = "sqlite://"
        if reuse_db:
            # A hack to check if the database exists and if it
            # does, load that and run tests.
            Database = backend.get('Database')

            # cursor.test forgets to set flavor!
            # no time to report a bug!
            Flavor.set(Database.flavor)
            os.environ['DB_NAME'] = 'fulfilio'
        else:
            os.environ['DB_NAME'] = ':memory:'

    elif request.config.getoption("--db") == 'postgres':
        os.environ['TRYTOND_DATABASE_URI'] = "postgresql://"
        if reuse_db:
            os.environ['DB_NAME'] = 'test_fulfilio'
        else:
            os.environ['DB_NAME'] = 'test_' + str(int(time.time()))

    if reuse_db:
        Database = backend.get('Database')
        database = Database().connect()
        cursor = database.cursor()
        databases = database.list(cursor)
        cursor.close()
        if os.environ['DB_NAME'] in databases:
            if request.config.getoption("--reset-db"):
                cursor = database.cursor()
                databases = database.drop(cursor, os.environ['DB_NAME'])
                cursor.close()
            else:
                # tryton test forgets to init the pool
                # for existing database
                Pool(os.environ['DB_NAME']).init()

    config.set('database', 'uri', os.environ['TRYTOND_DATABASE_URI'])
    from trytond.tests import test_tryton
    test_tryton.install_module('payment_gateway_stripe')
def install_module(request):
    """Install tryton module in specified database.
     """
    reuse_db = request.config.getoption("--reuse-db")

    if request.config.getoption("--db") == 'sqlite':
        os.environ['TRYTOND_DATABASE_URI'] = "sqlite://"
        if reuse_db:
            # A hack to check if the database exists and if it
            # does, load that and run tests.
            Database = backend.get('Database')

            # cursor.test forgets to set flavor!
            # no time to report a bug!
            Flavor.set(Database.flavor)
            os.environ['DB_NAME'] = 'fulfilio'
        else:
            os.environ['DB_NAME'] = ':memory:'

    elif request.config.getoption("--db") == 'postgres':
        os.environ['TRYTOND_DATABASE_URI'] = "postgresql://"
        if reuse_db:
            os.environ['DB_NAME'] = 'test_fulfilio'
        else:
            os.environ['DB_NAME'] = 'test_' + str(int(time.time()))

    if reuse_db:
        Database = backend.get('Database')
        database = Database().connect()
        cursor = database.cursor()
        databases = database.list(cursor)
        cursor.close()
        if os.environ['DB_NAME'] in databases:
            if request.config.getoption("--reset-db"):
                    cursor = database.cursor()
                    databases = database.drop(cursor, os.environ['DB_NAME'])
                    cursor.close()
            else:
                # tryton test forgets to init the pool
                # for existing database
                Pool(os.environ['DB_NAME']).init()

    config.set('database', 'uri', os.environ['TRYTOND_DATABASE_URI'])
    from trytond.tests import test_tryton
    test_tryton.install_module('payment_gateway_stripe')
    def run(self):
        if self.distribution.tests_require:
            self.distribution.fetch_build_eggs(self.distribution.tests_require)

        os.environ['TRYTOND_DATABASE_URI'] = 'postgresql://'
        os.environ['DB_NAME'] = 'test_' + str(int(time.time()))

        from trytond.config import config
        # Add elastic search test configuration
        config.add_section('elastic_search')
        config.set('elastic_search', 'server_uri', 'localhost:9200')

        from tests import suite
        test_result = unittest.TextTestRunner(verbosity=3).run(suite())

        if test_result.wasSuccessful():
            sys.exit(0)
        sys.exit(-1)
示例#14
0
    def run(self):
        if self.distribution.tests_require:
            self.distribution.fetch_build_eggs(self.distribution.tests_require)

        os.environ['TRYTOND_DATABASE_URI'] = 'postgresql://'
        os.environ['DB_NAME'] = 'test_' + str(int(time.time()))

        from trytond.config import config
        # Add elastic search test configuration
        config.add_section('elastic_search')
        config.set('elastic_search', 'server_uri', 'localhost:9200')

        from tests import suite
        test_result = unittest.TextTestRunner(verbosity=3).run(suite())

        if test_result.wasSuccessful():
            sys.exit(0)
        sys.exit(-1)
    def test_user_get_login(self):
        'Test User.get_login'
        pool = Pool()
        User = pool.get('res.user')

        @patch.object(ldap3, 'Connection')
        @patch.object(User, 'ldap_search_user')
        def get_login(login, password, find, ldap_search_user, Connection):
            con = Connection.return_value
            con.bind.return_value = bool(find)
            if find:
                ldap_search_user.return_value = [('dn', {'uid': [find]})]
            else:
                ldap_search_user.return_value = None
            user_id = User.get_login(login, {
                    'password': password,
                    })
            if find:
                Connection.assert_called_with(ANY, ANY, password)
            return user_id

        # Test existing user
        user, = User.search([('login', '=', 'admin')])
        self.assertEqual(get_login('admin', 'admin', 'admin'), user.id)
        self.assertEqual(get_login('AdMiN', 'admin', 'admin'), user.id)

        # Test new user
        self.assertFalse(get_login('foo', 'bar', None))
        self.assertFalse(get_login('foo', 'bar', 'foo'))

        # Test create new user
        config.set(section, 'create_user', 'True')
        user_id = get_login('foo', 'bar', 'foo')
        foo, = User.search([('login', '=', 'foo')])
        self.assertEqual(user_id, foo.id)
        self.assertEqual(foo.name, 'foo')

        # Test create new user with different case
        user_id = get_login('BaR', 'foo', 'bar')
        bar, = User.search([('login', '=', 'bar')])
        self.assertEqual(user_id, bar.id)
        self.assertEqual(bar.name, 'bar')
    def test_user_get_login(self):
        'Test User.get_login'
        pool = Pool()
        User = pool.get('res.user')

        @patch.object(ldap3, 'Connection')
        @patch.object(User, 'ldap_search_user')
        def get_login(login, password, find, ldap_search_user, Connection):
            con = Connection.return_value
            con.bind.return_value = bool(find)
            if find:
                ldap_search_user.return_value = [('dn', {'uid': [find]})]
            else:
                ldap_search_user.return_value = None
            user_id = User.get_login(login, {
                    'password': password,
                    })
            if find:
                Connection.assert_called_with(ANY, ANY, password)
            return user_id

        # Test existing user
        user, = User.search([('login', '=', 'admin')])
        self.assertEqual(get_login('admin', 'admin', 'admin'), user.id)
        self.assertEqual(get_login('AdMiN', 'admin', 'admin'), user.id)

        # Test new user
        self.assertFalse(get_login('foo', 'bar', None))
        self.assertFalse(get_login('foo', 'bar', 'foo'))

        # Test create new user
        config.set(section, 'create_user', 'True')
        user_id = get_login('foo', 'bar', 'foo')
        foo, = User.search([('login', '=', 'foo')])
        self.assertEqual(user_id, foo.id)
        self.assertEqual(foo.name, 'foo')

        # Test create new user with different case
        user_id = get_login('BaR', 'foo', 'bar')
        bar, = User.search([('login', '=', 'bar')])
        self.assertEqual(user_id, bar.id)
        self.assertEqual(bar.name, 'bar')
示例#17
0
    def setUp(self):
        methods = config.get('session', 'authentications')
        config.set('session', 'authentications', 'password')
        self.addCleanup(config.set, 'session', 'authentications', methods)

        length = config.get('password', 'length')
        config.set('password', 'length', '4')
        self.addCleanup(config.set, 'password', 'length', length)

        forbidden = config.get('password', 'forbidden', default='')
        config.set('password', 'forbidden',
                   os.path.join(os.path.dirname(__file__), 'forbidden.txt'))
        self.addCleanup(config.set, 'password', 'forbidden', forbidden)

        reset_from = config.get('email', 'from', fallback='')
        config.set('email', 'from', FROM)
        self.addCleanup(lambda: config.set('email', 'from', reset_from))
    def test_user_get_login(self):
        'Test User.get_login'
        pool = Pool()
        User = pool.get('res.user')

        @patch.object(ldap, 'initialize')
        @patch.object(User, 'ldap_search_user')
        def get_login(login, password, find, ldap_search_user, initialize):
            con = initialize.return_value
            con.simple_bind_s.return_value = True
            if find:
                ldap_search_user.return_value = [('dn', {'uid': [find]})]
            else:
                ldap_search_user.return_value = None
            return User.get_login(login, password)

        # Test existing user
        user, = User.search([('login', '=', 'admin')])
        self.assertEqual(get_login('admin', 'admin', None), user.id)
        self.assertEqual(get_login('admin', 'admin', 'admin'), user.id)
        self.assertEqual(get_login('AdMiN', 'admin', 'admin'), user.id)

        # Test new user
        self.assertFalse(get_login('foo', 'bar', None))
        self.assertFalse(get_login('foo', 'bar', 'foo'))

        # Test create new user
        config.set(section, 'create_user', 'True')
        user_id = get_login('foo', 'bar', 'foo')
        foo, = User.search([('login', '=', 'foo')])
        self.assertEqual(user_id, foo.id)
        self.assertEqual(foo.name, 'foo')

        # Test create new user with different case
        user_id = get_login('BaR', 'foo', 'bar')
        bar, = User.search([('login', '=', 'bar')])
        self.assertEqual(user_id, bar.id)
        self.assertEqual(bar.name, 'bar')
    def test_user_get_login(self):
        'Test User.get_login'
        pool = Pool()
        User = pool.get('res.user')

        @patch.object(ldap, 'initialize')
        @patch.object(User, 'ldap_search_user')
        def get_login(login, password, find, ldap_search_user, initialize):
            con = initialize.return_value
            con.simple_bind_s.return_value = True
            if find:
                ldap_search_user.return_value = [('dn', {'uid': [find]})]
            else:
                ldap_search_user.return_value = None
            return User.get_login(login, password)

        # Test existing user
        user, = User.search([('login', '=', 'admin')])
        self.assertEqual(get_login('admin', 'admin', None), user.id)
        self.assertEqual(get_login('admin', 'admin', 'admin'), user.id)
        self.assertEqual(get_login('AdMiN', 'admin', 'admin'), user.id)

        # Test new user
        self.assertFalse(get_login('foo', 'bar', None))
        self.assertFalse(get_login('foo', 'bar', 'foo'))

        # Test create new user
        config.set(section, 'create_user', 'True')
        user_id = get_login('foo', 'bar', 'foo')
        foo, = User.search([('login', '=', 'foo')])
        self.assertEqual(user_id, foo.id)
        self.assertEqual(foo.name, 'foo')

        # Test create new user with different case
        user_id = get_login('BaR', 'foo', 'bar')
        bar, = User.search([('login', '=', 'bar')])
        self.assertEqual(user_id, bar.id)
        self.assertEqual(bar.name, 'bar')
def install_module(request):
    """Install tryton module in specified database.
    """
    if request.config.getoption("--db") == 'sqlite':
        os.environ['TRYTOND_DATABASE_URI'] = "sqlite://"
        os.environ['DB_NAME'] = ':memory:'

    elif request.config.getoption("--db") == 'postgres':
        os.environ['TRYTOND_DATABASE_URI'] = "postgresql://"
        os.environ['DB_NAME'] = 'test_' + str(int(time.time()))

    config.set('database', 'uri', os.environ['TRYTOND_DATABASE_URI'])
    os.environ['TRYTOND_ENCRYPTED_FIELD__SECRET_KEY'] = Fernet.generate_key()
    from trytond.tests import test_tryton
    from trytond.pool import Pool

    Pool.register(
        EncryptedCharField,
        EncryptedTextField,
        EncryptedSelectionField,
        module='tests', type_='model'
    )
    test_tryton.install_module('tests')
示例#21
0
    def setUp(self):
        methods = config.get('session', 'authentications')
        config.set('session', 'authentications', 'password')
        self.addCleanup(config.set, 'session', 'authentications', methods)

        length = config.get('password', 'length')
        config.set('password', 'length', 4)
        self.addCleanup(config.set, 'password', 'length', length)

        forbidden = config.get('password', 'forbidden', default='')
        config.set('password', 'forbidden',
                   os.path.join(os.path.dirname(__file__), 'forbidden.txt'))
        self.addCleanup(config.set, 'password', 'forbidden', forbidden)

        entropy = config.get('password', 'entropy')
        config.set('password', 'entropy', 0.9)
        self.addCleanup(config.set, 'password', 'entropy', entropy)
    def setUp(self):
        super(AuthenticationSMSTestCase, self).setUp()
        methods = config.get('session', 'authentications')
        config.set('session', 'authentications', 'password_sms')
        self.addCleanup(config.set, 'session', 'authentications', methods)
        config.add_section('authentication_sms')
        config.set(
            'authentication_sms', 'function',
            'trytond.modules.authentication_sms.tests.send_sms')
        self.addCleanup(config.remove_section, 'authentication_sms')
        del sms_queue[:]

        length = config.get('password', 'length')
        config.set('password', 'length', 4)
        self.addCleanup(config.set, 'password', 'length', length)

        entropy = config.get('password', 'entropy')
        config.set('password', 'entropy', 0.8)
        self.addCleanup(config.set, 'password', 'entropy', entropy)
示例#23
0
# -*- coding: utf-8 -*-
import unittest
import json
from decimal import Decimal

import trytond.tests.test_tryton
from trytond.tests.test_tryton import POOL, USER, DB_NAME, CONTEXT
from nereid.testing import NereidTestCase
from trytond.transaction import Transaction
from trytond.exceptions import UserError

from trytond.config import config
config.set('database', 'path', '/tmp')


class TestProduct(NereidTestCase):
    "Product Test Case"

    def setup_defaults(self):
        """
        Setup the defaults
        """
        usd, = self.Currency.create([{
            'name': 'US Dollar',
            'code': 'USD',
            'symbol': '$',
        }])
        party1, = self.Party.create([{
            'name': 'Openlabs',
        }])
        company, = self.Company.create([{
示例#24
0
from decimal import Decimal
from time import time
from datetime import datetime
from dateutil.relativedelta import relativedelta
from lxml import objectify


import unittest
import trytond.tests.test_tryton
from trytond.tests.test_tryton import POOL, DB_NAME, USER, CONTEXT
from trytond.transaction import Transaction
from trytond.config import config
from trytond.error import UserError

config.set("database", "path", ".")


class TestUPS(unittest.TestCase):
    """Test UPS Integration
    """

    def setUp(self):
        trytond.tests.test_tryton.install_module("shipping_ups")
        self.Address = POOL.get("party.address")
        self.Sale = POOL.get("sale.sale")
        self.SaleConfig = POOL.get("sale.configuration")
        self.UPSService = POOL.get("ups.service")
        self.Product = POOL.get("product.product")
        self.Uom = POOL.get("product.uom")
        self.Account = POOL.get("account.account")
示例#25
0
# This file is part of Tryton.  The COPYRIGHT file at the top level of
# this repository contains the full copyright notices and license terms.
import json
import unittest

import pycountry
from mock import patch
import trytond.tests.test_tryton
from trytond.tests.test_tryton import POOL, USER, DB_NAME, CONTEXT
from trytond.transaction import Transaction
from trytond.config import config
from nereid.testing import NereidTestCase

config.set('email', 'from', '*****@*****.**')


class TestAddress(NereidTestCase):
    'Test Address'

    def setUp(self):
        trytond.tests.test_tryton.install_module('nereid')

        self.nereid_website_obj = POOL.get('nereid.website')
        self.nereid_website_locale_obj = POOL.get('nereid.website.locale')
        self.nereid_user_obj = POOL.get('nereid.user')
        self.company_obj = POOL.get('company.company')
        self.currency_obj = POOL.get('currency.currency')
        self.language_obj = POOL.get('ir.lang')
        self.country_obj = POOL.get('country.country')
        self.subdivision_obj = POOL.get('country.subdivision')
        self.party_obj = POOL.get('party.party')
"""
import time
import datetime
from dateutil.relativedelta import relativedelta
from decimal import Decimal
from pyes.managers import Indices

import trytond.tests.test_tryton
from trytond.tests.test_tryton import POOL, USER, DB_NAME, CONTEXT
from trytond.transaction import Transaction
from trytond.config import config
from nereid.testing import NereidTestCase
from pagination import ElasticPagination

config.add_section('elastic_search')
config.set('elastic_search', 'server_uri', 'http://localhost:9200')


class TestPagination(NereidTestCase):
    """
    Test Pagination
    """
    def setUp(self):
        """
        Set up data used in the tests.
        this method is called before each test function execution.
        """
        trytond.tests.test_tryton.install_module(
            'nereid_webshop_elastic_search'
        )
示例#27
0
    Test the static file feature of nereid

    :copyright: (c) 2012-2013 by Openlabs Technologies & Consulting (P) LTD
    :license: GPLv3, see LICENSE for more details.
"""
import unittest

import trytond.tests.test_tryton
from trytond.tests.test_tryton import POOL, USER, DB_NAME, CONTEXT
from trytond.transaction import Transaction
from trytond.pool import PoolMeta, Pool
from trytond.config import config
from nereid.testing import NereidTestCase
from nereid import render_template, route

config.set('email', 'from', '*****@*****.**')
config.set('database', 'path', '/tmp/temp_tryton_data/')


class StaticFileServingHomePage:
    __metaclass__ = PoolMeta
    __name__ = 'nereid.website'

    @classmethod
    @route('/static-file-test')
    def static_file_test(cls):
        static_file_obj = Pool().get('nereid.static.file')

        static_file, = static_file_obj.search([])
        return render_template('home.jinja',
                               static_file_obj=static_file_obj,
示例#28
0
 def setUp(self):
     path = config.get('database', 'path')
     dtemp = tempfile.mkdtemp()
     config.set('database', 'path', dtemp)
     self.addCleanup(config.set, 'database', 'path', path)
     self.addCleanup(shutil.rmtree, dtemp)
示例#29
0
文件: action.py 项目: mpassy/trytond
from ..cache import Cache
from ..rpc import RPC

__all__ = [
    'Action',
    'ActionKeyword',
    'ActionReport',
    'ActionActWindow',
    'ActionActWindowView',
    'ActionActWindowDomain',
    'ActionWizard',
    'ActionURL',
]

if not config.get('html', 'plugins-ir.action.report-report_content_html'):
    config.set('html', 'plugins-ir.action.report-report_content_html',
               'fullpage')


class WizardModelError(ValidationError):
    pass


class EmailError(ValidationError):
    pass


class ViewError(ValidationError):
    pass


class DomainError(ValidationError):
import os

DIR = os.path.abspath(os.path.normpath(os.path.join(__file__, "..", "..", "..", "..", "..", "trytond")))
if os.path.isdir(DIR):
    sys.path.insert(0, os.path.dirname(DIR))

import unittest

import boto
from moto import mock_s3
import trytond.tests.test_tryton
from trytond.tests.test_tryton import POOL, DB_NAME, USER, CONTEXT, ModuleTestCase
from trytond.transaction import Transaction
from trytond.config import config

config.set("nereid_s3", "s3_access_key", "ABCD")
config.set("nereid_s3", "s3_secret_key", "123XYZ")
config.set("nereid_s3", "bucket", "tryton-test-s3")


class TestNereidS3(ModuleTestCase):
    """
    Test Nereid S3
    """

    module = "nereid_s3"

    def setUp(self):
        trytond.tests.test_tryton.install_module("nereid_s3")
        self.static_file = POOL.get("nereid.static.file")
        self.static_folder = POOL.get("nereid.static.folder")
示例#31
0
 def setUp(self):
     super(NotificationEmailTestCase, self).setUp()
     reset_from = config.get('email', 'from')
     config.set('email', 'from', FROM)
     self.addCleanup(lambda: config.set('email', 'from', reset_from))
示例#32
0
import random
import datetime
from decimal import Decimal
from dateutil.relativedelta import relativedelta

import pycountry
import trytond.tests.test_tryton
from trytond.tests.test_tryton import POOL, USER
from nereid.testing import NereidTestCase
from trytond.transaction import Transaction
from trytond.config import config

config.set('database', 'path', '/tmp')
config.set('email', 'from', '*****@*****.**')


class BaseTestCase(NereidTestCase):
    """
    Base test Case for nereid webshop
    """
    def setUp(self):
        trytond.tests.test_tryton.install_module('nereid_webshop')

        self.FiscalYear = POOL.get('account.fiscalyear')
        self.Account = POOL.get('account.account')
        self.PaymentTerm = POOL.get('account.invoice.payment_term')
        self.Currency = POOL.get('currency.currency')
        self.Company = POOL.get('company.company')
        self.Party = POOL.get('party.party')
        self.Sale = POOL.get('sale.sale')
        self.Cart = POOL.get('nereid.cart')
    TestParty

    :copyright: (c) 2014-2015 by Openlabs Technologies & Consulting (P) Limited
    :license: BSD, see LICENSE for more details.
"""
import time
import unittest

import trytond.tests.test_tryton
from trytond.tests.test_tryton import POOL, with_transaction

from trytond.config import config
# Add elastic search test configuration
config.add_section('elastic_search')
config.set('elastic_search', 'server_uri', "localhost:9200")


class TestParty(unittest.TestCase):
    """
    Test Party
    """

    def setUp(self):
        trytond.tests.test_tryton.install_module('party_elasticsearch')
        self.Party = POOL.get('party.party')
        self.IndexBacklog = POOL.get('elasticsearch.index_backlog')
        self.ElasticDocumentType = POOL.get('elasticsearch.document.type')
        self.ElasticConfig = POOL.get('elasticsearch.configuration')

    def update_mapping(self):
import os
import time
import datetime
from dateutil.relativedelta import relativedelta
from decimal import Decimal
from pyes.managers import Indices

import trytond.tests.test_tryton
from trytond.tests.test_tryton import POOL, USER, CONTEXT, with_transaction
from trytond.transaction import Transaction
from trytond.config import config
from nereid.testing import NereidTestCase
from pagination import ElasticPagination

config.add_section('elastic_search')
config.set('elastic_search', 'server_uri', 'http://localhost:9200')
config.set('database', 'path', '/tmp/tryton-test-db/')
if not os.path.exists(config.get('database', 'path')):
    os.makedirs(config.get('database', 'path'))


class TestPagination(NereidTestCase):
    """
    Test Pagination
    """
    def setUp(self):
        """
        Set up data used in the tests.
        this method is called before each test function execution.
        """
        trytond.tests.test_tryton.install_module(
示例#35
0
    test_project

    TestProject

    :copyright: (c) 2013-2015 by Openlabs Technologies & Consulting (P) Limited
    :license: BSD, see LICENSE for more details.
"""
import smtplib
from minimock import Mock

import trytond.tests.test_tryton
from trytond.tests.test_tryton import POOL, USER
from nereid.testing import NereidTestCase
from trytond.config import config

config.set("database", "path", ".")
config.set("email", "from", "*****@*****.**")

smtplib.SMTP = Mock("smtplib.SMTP")
smtplib.SMTP.mock_returns = Mock("smtp_connection")


class TestBase(NereidTestCase):
    """
    Creates default values to be used by test cases
    """

    def setUp(self):
        """
        Set up data used in the tests.
        this method is called before each test function execution.
示例#36
0
 def setUp(self):
     methods = config.get('session', 'authentications')
     config.set('session', 'authentications', 'password')
     self.addCleanup(config.set, 'session', 'authentications', methods)
    sys.path.insert(0, os.path.dirname(DIR))

import unittest

from mock import patch
from boto.s3 import connection
from boto.s3.bucket import Bucket
from boto.s3.key import Key
import trytond.tests.test_tryton
from trytond.tests.test_tryton import POOL, DB_NAME, USER, CONTEXT, test_view,\
    test_depends
from trytond.transaction import Transaction
from trytond.exceptions import UserError
from trytond.config import config

config.set('nereid_s3', 's3_access_key', 'ABCD')
config.set('nereid_s3', 's3_secret_key', '123XYZ')
config.set('nereid_s3', 's3_bucket_name', 'tryton-test-s3')


class TestNereidS3(unittest.TestCase):
    '''
    Test Nereid S3
    '''

    def setUp(self):
        trytond.tests.test_tryton.install_module('nereid_s3')
        self.static_file = POOL.get('nereid.static.file')
        self.static_folder = POOL.get('nereid.static.folder')

        # Mock S3Connection
# -*- coding: utf-8 -*-
"""
    tests/test_sale.py
"""
import unittest
import datetime
from dateutil.relativedelta import relativedelta
from decimal import Decimal

import trytond.tests.test_tryton
from trytond.tests.test_tryton import POOL, USER, DB_NAME, CONTEXT
from trytond.transaction import Transaction
from trytond.pyson import Eval
from trytond.config import config

config.set('email', 'from', '*****@*****.**')


class TestSale(unittest.TestCase):

    def setUp(self):
        """
        Set up data used in the tests.
        this method is called before each test function execution.
        """
        trytond.tests.test_tryton.install_module('sale_confirmation_email')

        self.Currency = POOL.get('currency.currency')
        self.Company = POOL.get('company.company')
        self.Party = POOL.get('party.party')
        self.User = POOL.get('res.user')
示例#39
0
import datetime
import simplejson as json
from dateutil.relativedelta import relativedelta
DIR = os.path.abspath(
    os.path.normpath(
        os.path.join(
            __file__, '..', '..', '..', '..', '..', 'trytond'
        )
    )
)
if os.path.isdir(DIR):
    sys.path.insert(0, os.path.dirname(DIR))

from mock import patch
from trytond.config import config
config.set('email', 'from', '*****@*****.**')

import trytond.tests.test_tryton
from trytond.tests.test_tryton import POOL, DB_NAME, USER, CONTEXT
from trytond.transaction import Transaction
from trytond.tests.test_tryton import test_view, test_depends
from nereid.testing import NereidTestCase


class NereidCRMTestCase(NereidTestCase):
    '''
    Test Nereid CRM module.
    '''

    def setUp(self):
        trytond.tests.test_tryton.install_module('nereid_crm')
示例#40
0
"""
import os
import json
import unittest
from mock import patch
from decimal import Decimal

import trytond.tests.test_tryton
from trytond.tests.test_tryton import POOL, USER, DB_NAME, CONTEXT
from trytond.config import config
from trytond.transaction import Transaction
from trytond import backend

from trytond.modules.nereid_cart_b2c.tests.test_product import BaseTestCase

config.set("email", "from", "*****@*****.**")


class BaseTestCheckout(BaseTestCase):
    """Test Checkout Base"""

    @classmethod
    def setUpClass(cls):
        print "====== Tests are running on %s ========" % backend.name()

    def setUp(self):
        super(BaseTestCheckout, self).setUp()
        trytond.tests.test_tryton.install_module("nereid_shipping")
        trytond.tests.test_tryton.install_module("shipping_ups")

        self.Carrier = POOL.get("carrier")
示例#41
0
# -*- coding: utf-8 -*-
import unittest

import trytond.tests.test_tryton
from trytond.tests.test_tryton import POOL, with_transaction, ModuleTestCase
from trytond.config import config


config.add_section('elastic_search')
config.set('elastic_search', 'server_uri', 'http://localhost:9200')


class IndexBacklogTestCase(ModuleTestCase):
    """
    Tests Index Backlog
    """
    module = 'elastic_search'

    def setUp(self):
        trytond.tests.test_tryton.install_module('elastic_search')
        self.IndexBacklog = POOL.get('elasticsearch.index_backlog')
        self.Configuration = POOL.get('elasticsearch.configuration')
        self.User = POOL.get('res.user')

    @with_transaction()
    def test_0010_create_IndexBacklog(self):
        """
        Creates index backlog and updates remote elastic search index
        """
        self.Configuration(1).save()
        users = self.User.create([{
示例#42
0
# -*- coding: utf-8 -*-
"""
    test_nereid_s3

    Test Nereid-S3

"""
import unittest

import boto
from moto import mock_s3
import trytond.tests.test_tryton
from trytond.tests.test_tryton import POOL, with_transaction, ModuleTestCase
from trytond.config import config

config.set('nereid_s3', 's3_access_key', 'ABCD')
config.set('nereid_s3', 's3_secret_key', '123XYZ')
config.set('nereid_s3', 'bucket', 'tryton-test-s3')


class TestNereidS3(ModuleTestCase):
    '''
    Test Nereid S3
    '''

    module = 'nereid_s3'

    def setUp(self):
        self.static_file = POOL.get('nereid.static.file')
        self.static_folder = POOL.get('nereid.static.folder')
    TestParty

    :copyright: (c) 2014-2015 by Openlabs Technologies & Consulting (P) Limited
    :license: BSD, see LICENSE for more details.
"""
import time
import unittest

import trytond.tests.test_tryton
from trytond.tests.test_tryton import DB_NAME, USER, CONTEXT, POOL
from trytond.transaction import Transaction

from trytond.config import config
# Add elastic search test configuration
config.add_section('elastic_search')
config.set('elastic_search', 'server_uri', "localhost:9200")


class TestParty(unittest.TestCase):
    """
    Test Party
    """

    def setUp(self):
        trytond.tests.test_tryton.install_module('party_elasticsearch')
        self.Party = POOL.get('party.party')
        self.IndexBacklog = POOL.get('elasticsearch.index_backlog')
        self.ElasticDocumentType = POOL.get('elasticsearch.document.type')
        self.ElasticConfig = POOL.get('elasticsearch.configuration')

    def update_mapping(self):
示例#44
0
 def setUp(self):
     super().setUp()
     methods = config.get('session', 'authentications', default='')
     config.set('session', 'authentications', 'totp_optional')
     self.addCleanup(config.set, 'session', 'authentications', methods)
示例#45
0
    TestTask

    :copyright: (c) 2013-2015 by Openlabs Technologies & Consulting (P) Limited
    :license: BSD, see LICENSE for more details.
"""
import unittest
import json
import smtplib

from minimock import Mock
from trytond.tests.test_tryton import POOL, DB_NAME, USER, CONTEXT
from trytond.transaction import Transaction
from test_base import TestBase
from trytond.config import config
config.set('database', 'path', '/tmp')
config.set('email', 'from', '*****@*****.**')

smtplib.SMTP = Mock('smtplib.SMTP')
smtplib.SMTP.mock_returns = Mock('smtp_connection')


class TestTask(TestBase):
    '''
    Test Task
    '''

    def get_template_source(self, name):
        """
        Return templates.
        """
 def setUp(self):
     super(LDAPAuthenticationTestCase, self).setUp()
     config.add_section(section)
     config.set(section, 'uri', 'ldap://localhost/dc=tryton,dc=org')
    Test GLS Integration
    :copyright: (c) 2014 by Openlabs Technologies & Consulting (P) Limited
    :license: GPLv3, see LICENSE for more details.
"""
from decimal import Decimal
from datetime import datetime
from dateutil.relativedelta import relativedelta

import os
import unittest
import trytond.tests.test_tryton
from trytond.tests.test_tryton import POOL, DB_NAME, USER, CONTEXT
from trytond.transaction import Transaction
from trytond.config import config

config.set('database', 'path', '.')


class TestGLSShipping(unittest.TestCase):
    """
    Test GLS Integration
    """

    def setUp(self):
        trytond.tests.test_tryton.install_module('shipping_gls')
        self.Address = POOL.get('party.address')
        self.Sale = POOL.get('sale.sale')
        self.SaleLine = POOL.get('sale.line')
        self.SaleConfig = POOL.get('sale.configuration')
        self.PackageType = POOL.get('stock.package.type')
        self.Package = POOL.get('stock.package')
示例#48
0
from trytond.model import (DeactivableMixin, ModelSQL, ModelView, Unique,
                           Workflow, fields)
from trytond.pool import Pool
from trytond.pyson import Eval
from trytond.report import Report, get_email
from trytond.sendmail import SMTPDataManager, sendmail_transactional
from trytond.tools import grouped_slice
from trytond.tools.email_ import set_from_header
from trytond.transaction import Transaction
from trytond.url import http_host
from trytond.wizard import Button, StateTransition, StateView, Wizard

from .exceptions import TemplateError

if not config.get('html', 'plugins-marketing.email.message-content'):
    config.set('html', 'plugins-marketing.email.message-content', 'fullpage')

URL_BASE = config.get('marketing', 'email_base', default=http_host())
URL_OPEN = urljoin(URL_BASE, '/m/empty.gif')


def _formataddr(name, email):
    if name:
        name = str(Header(name, 'utf-8'))
    return formataddr((name, email))


def _add_params(url, **params):
    parts = urlsplit(url)
    query = parse_qsl(parts.query)
    for key, value in sorted(params.items()):
示例#49
0
import random
import datetime
from decimal import Decimal
from dateutil.relativedelta import relativedelta

import pycountry
import trytond.tests.test_tryton
from trytond.tests.test_tryton import POOL, USER, CONTEXT
from nereid.testing import NereidTestCase
from trytond.transaction import Transaction
from trytond.config import config

config.set("database", "path", "/tmp")


class BaseTestCase(NereidTestCase):
    """
    Base test Case for nereid webshop
    """

    def setUp(self):
        trytond.tests.test_tryton.install_module("nereid_webshop")

        self.FiscalYear = POOL.get("account.fiscalyear")
        self.Account = POOL.get("account.account")
        self.PaymentTerm = POOL.get("account.invoice.payment_term")
        self.Currency = POOL.get("currency.currency")
        self.Company = POOL.get("company.company")
        self.Party = POOL.get("party.party")
        self.Sale = POOL.get("sale.sale")
        self.Cart = POOL.get("nereid.cart")
 def setUp(self):
     super().setUp()
     if not config.has_section('marketing'):
         config.add_section('marketing')
     subscribe_url = config.get('marketing',
                                'email_subscribe_url',
                                default='')
     config.set('marketing', 'email_subscribe_url', SUBSCRIBE_URL)
     self.addCleanup(lambda: config.set('marketing', 'email_subscribe_url',
                                        subscribe_url))
     unsubscribe_url = config.get('marketing',
                                  'email_unsubscribe_url',
                                  default='')
     config.set('marketing', 'email_unsubscribe_url', UNSUBSCRIBE_URL)
     self.addCleanup(lambda: config.set(
         'marketing', 'email_unsubscribe_url', unsubscribe_url))
     spy_pixel = config.get('marketing', 'email_spy_pixel', default='')
     config.set('marketing', 'email_spy_pixel', 'true')
     self.addCleanup(
         lambda: config.set('marketing', 'email_spy_pixel', spy_pixel))
     from_ = config.get('email', 'from', default='')
     config.set('email', 'from', FROM)
     self.addCleanup(lambda: config.set('email', 'from', from_))
"""
from decimal import Decimal
from time import time
from datetime import datetime
from dateutil.relativedelta import relativedelta

import sys
import os
import unittest
import trytond.tests.test_tryton
from trytond.tests.test_tryton import POOL, DB_NAME, USER, CONTEXT
from trytond.transaction import Transaction
from trytond.config import config
from trytond.exceptions import UserError
config.set('database', 'path', '.')

DIR = os.path.abspath(os.path.normpath(
    os.path.join(__file__, '..', '..', '..', '..', '..', 'trytond')
))
if os.path.isdir(DIR):
    sys.path.insert(0, os.path.dirname(DIR))


class TestDPDShipment(unittest.TestCase):
    """Test DPD Integration
    """

    def setUp(self):
        trytond.tests.test_tryton.install_module('shipping_dpd')
        self.Address = POOL.get('party.address')
from decimal import Decimal

from dateutil.relativedelta import relativedelta
from pagination import ElasticPagination
from pyes.managers import Indices

import trytond.tests.test_tryton

from trytond.config import config
from trytond.tests.test_tryton import CONTEXT, POOL, USER, with_transaction
from trytond.transaction import Transaction

from nereid.testing import NereidTestCase

config.add_section('elastic_search')
config.set('elastic_search', 'server_uri', 'http://localhost:9200')
config.set('database', 'path', '/tmp/tryton-test-db/')
if not os.path.exists(config.get('database', 'path')):
    os.makedirs(config.get('database', 'path'))


class TestPagination(NereidTestCase):
    """
    Test Pagination
    """
    def setUp(self):
        """
        Set up data used in the tests.
        this method is called before each test function execution.
        """
        trytond.tests.test_tryton.install_module(
示例#53
0
# This file is part of Tryton.  The COPYRIGHT file at the top level of
# this repository contains the full copyright notices and license terms.
import urllib
import unittest
import base64
import json

import trytond.tests.test_tryton
from trytond.tests.test_tryton import POOL, USER, DB_NAME, CONTEXT
from trytond.transaction import Transaction
from trytond.config import config
from nereid.testing import NereidTestCase
from nereid import permissions_required
from werkzeug.exceptions import Forbidden

config.set('email', 'from', '*****@*****.**')


class TestAuth(NereidTestCase):
    """
    Test Authentication Layer
    """

    def setUp(self):
        trytond.tests.test_tryton.install_module('nereid')

        self.nereid_website_obj = POOL.get('nereid.website')
        self.nereid_website_locale_obj = POOL.get('nereid.website.locale')
        self.nereid_permission_obj = POOL.get('nereid.permission')
        self.nereid_user_obj = POOL.get('nereid.user')
        self.company_obj = POOL.get('company.company')
示例#54
0
    Test the static file feature of nereid

    :copyright: (c) 2012-2015 by Openlabs Technologies & Consulting (P) LTD
    :license: GPLv3, see LICENSE for more details.
"""
import unittest

import trytond.tests.test_tryton
from trytond.tests.test_tryton import POOL, USER, DB_NAME, CONTEXT
from trytond.transaction import Transaction
from trytond.pool import PoolMeta, Pool
from trytond.config import config
from nereid.testing import NereidTestCase
from nereid import render_template, route

config.set('email', 'from', '*****@*****.**')
config.set('database', 'path', '/tmp/temp_tryton_data/')


class StaticFileServingHomePage:
    __metaclass__ = PoolMeta
    __name__ = 'nereid.website'

    @classmethod
    @route('/static-file-test')
    def static_file_test(cls):
        static_file_obj = Pool().get('nereid.static.file')

        static_file, = static_file_obj.search([])
        return render_template(
            'home.jinja',
示例#55
0
 def setUp(self):
     super(LDAPAuthenticationTestCase, self).setUp()
     config.add_section(section)
     config.set(section, 'uri', 'ldap://localhost/dc=tryton,dc=org')
示例#56
0
    def setUp(self):
        super(WebUserTestCase, self).setUp()
        validation_url = config.get('web', 'email_validation_url')
        config.set('web', 'email_validation_url', VALIDATION_URL)
        self.addCleanup(
            lambda: config.set('web', 'email_validation_url', validation_url))
        reset_password_url = config.get('web', 'reset_password_url')
        config.set('web', 'reset_password_url', RESET_PASSWORD_URL)
        self.addCleanup(lambda: config.set('web', 'reset_password_url',
                                           reset_password_url))
        reset_from = config.get('email', 'from')
        config.set('email', 'from', FROM)
        self.addCleanup(lambda: config.set('email', 'from', reset_from))

        length = config.get('password', 'length')
        config.set('password', 'length', 4)
        self.addCleanup(config.set, 'password', 'length', length)

        entropy = config.get('password', 'entropy')
        config.set('password', 'entropy', 0.8)
        self.addCleanup(config.set, 'password', 'entropy', entropy)