<commit_before># -*- coding: utf-8 -*-
##############################################################################
#
#    Author: <NAME>
#    Copyright 2013 Camptocamp SA
#
#    This program is free software: you can redistribute it and/or modify
#    it under the terms of the GNU Affero General Public License as
#    published by the Free Software Foundation, either version 3 of the
#    License, or (at your option) any later version.
#
#    This program is distributed in the hope that it will be useful,
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#    GNU Affero General Public License for more details.
#
#    You should have received a copy of the GNU Affero General Public License
#    along with this program.  If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################

from functools import partial

from openerp.addons.connector.exception import InvalidDataError
from openerp.addons.magentoerpconnect.unit.import_synchronizer import (
    import_batch,
    import_record)
from openerp.addons.connector.session import ConnectorSession
import openerp.tests.common as common
from .common import (mock_api,
                     mock_urlopen_image,
                     MagentoHelper)
from .test_data import magento_base_responses


DB = common.DB
ADMIN_USER_ID = common.ADMIN_USER_ID


class SetUpMagentoBase(common.TransactionCase):
    """ Base class - Test the imports from a Magento Mock.

    The data returned by Magento are those created for the
    demo version of Magento on a standard 1.7 version.
    """

    def setUp(self):
        super(SetUpMagentoBase, self).setUp()
        self.backend_model = self.registry('magento.backend')
        self.session = ConnectorSession(self.cr, self.uid)
        self.session.context['__test_no_commit'] = True
        data_model = self.registry('ir.model.data')
        self.get_ref = partial(data_model.get_object_reference,
                               self.cr, self.uid)
        backend_ids = self.backend_model.search(
            self.cr, self.uid,
            [('name', '=', 'Test Magento')])
        if backend_ids:
            self.backend_id = backend_ids[0]
        else:
            __, warehouse_id = self.get_ref('stock', 'warehouse0')
            self.backend_id = self.backend_model.create(
                self.cr,
                self.uid,
                {'name': 'Test Magento',
                 'version': '1.7',
                 'location': 'http://anyurl',
                 'username': 'guewen',
                 'warehouse_id': warehouse_id,
                 'password': '42'})
            # payment method needed to import a sale order
            __, workflow_id = self.get_ref('sale_automatic_workflow',
                                           'manual_validation')
            __, journal_id = self.get_ref('account',
                                          'check_journal')
            self.registry('payment.method').create(
                self.cr, self.uid,
                {'name': 'checkmo',
                 'workflow_process_id': workflow_id,
                 'import_rule': 'always',
                 'days_before_cancel': 0,
                 'journal_id': journal_id})

    def get_magento_helper(self, model_name):
        return MagentoHelper(self.cr, self.registry, model_name)


class TestBaseMagento(SetUpMagentoBase):

    def test_00_import_backend(self):
        """ Synchronize initial metadata """
        with mock_api(magento_base_responses):
            import_batch(self.session, 'magento.website', self.backend_id)
            import_batch(self.session, 'magento.store', self.backend_id)
            import_batch(self.session, 'magento.storeview', self.backend_id)

        website_model = self.registry('magento.website')
        website_ids = website_model.search(
            self.cr, self.uid,
            [('backend_id', '=', self.backend_id)])
        self.assertEqual(len(website_ids), 2)

        store_model = self.registry('magento.store')
        store_ids = store_model.search(self.cr,
                                       self.uid,
                                       [('backend_id', '=', self.backend_id)])
        self.assertEqual(len(store_ids), 2)
<commit_msg>setUp is executed before each test, search will never find<commit_after># -*- coding: utf-8 -*-
##############################################################################
#
#    Author: <NAME>
#    Copyright 2013 Camptocamp SA
#
#    This program is free software: you can redistribute it and/or modify
#    it under the terms of the GNU Affero General Public License as
#    published by the Free Software Foundation, either version 3 of the
#    License, or (at your option) any later version.
#
#    This program is distributed in the hope that it will be useful,
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#    GNU Affero General Public License for more details.
#
#    You should have received a copy of the GNU Affero General Public License
#    along with this program.  If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################

from functools import partial

from openerp.addons.connector.exception import InvalidDataError
from openerp.addons.magentoerpconnect.unit.import_synchronizer import (
    import_batch,
    import_record)
from openerp.addons.connector.session import ConnectorSession
import openerp.tests.common as common
from .common import (mock_api,
                     mock_urlopen_image,
                     MagentoHelper)
from .test_data import magento_base_responses


DB = common.DB
ADMIN_USER_ID = common.ADMIN_USER_ID


class SetUpMagentoBase(common.TransactionCase):
    """ Base class - Test the imports from a Magento Mock.

    The data returned by Magento are those created for the
    demo version of Magento on a standard 1.7 version.
    """

    def setUp(self):
        super(SetUpMagentoBase, self).setUp()
        self.backend_model = self.registry('magento.backend')
        self.session = ConnectorSession(self.cr, self.uid)
        self.session.context['__test_no_commit'] = True
        data_model = self.registry('ir.model.data')
        self.get_ref = partial(data_model.get_object_reference,
                               self.cr, self.uid)
        __, warehouse_id = self.get_ref('stock', 'warehouse0')
        self.backend_id = self.backend_model.create(
            self.cr,
            self.uid,
            {'name': 'Test Magento',
             'version': '1.7',
             'location': 'http://anyurl',
             'username': 'guewen',
             'warehouse_id': warehouse_id,
             'password': '42'})
        # payment method needed to import a sale order
        __, workflow_id = self.get_ref('sale_automatic_workflow',
                                       'manual_validation')
        __, journal_id = self.get_ref('account',
                                      'check_journal')
        self.registry('payment.method').create(
            self.cr, self.uid,
            {'name': 'checkmo',
             'workflow_process_id': workflow_id,
             'import_rule': 'always',
             'days_before_cancel': 0,
             'journal_id': journal_id})

    def get_magento_helper(self, model_name):
        return MagentoHelper(self.cr, self.registry, model_name)


class TestBaseMagento(SetUpMagentoBase):

    def test_00_import_backend(self):
        """ Synchronize initial metadata """
        with mock_api(magento_base_responses):
            import_batch(self.session, 'magento.website', self.backend_id)
            import_batch(self.session, 'magento.store', self.backend_id)
            import_batch(self.session, 'magento.storeview', self.backend_id)

        website_model = self.registry('magento.website')
        website_ids = website_model.search(
            self.cr, self.uid,
            [('backend_id', '=', self.backend_id)])
        self.assertEqual(len(website_ids), 2)

        store_model = self.registry('magento.store')
        store_ids = store_model.search(self.cr,
                                       self.uid,
                                       [('backend_id', '=', self.backend_id)])
        self.assertEqual(len(store_ids), 2)

{'fraction_non_alphanumeric': 0.12947008143514693, 'fraction_numerical': 0.004366812227074236, 'mean_word_length': 2.4252223120452707, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 10, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '667582', 'n_tokens_mistral': 2341, 'n_tokens_neox': 2270, 'n_words': 589}