Changeset - 874cbc4462bd
[Not reviewed]
1 3 0
Lance Edgar - 6 years ago 2019-02-18 21:27:57
ledgar@techsupport.coop
Clean up Rattail <-> Rattail import/export handlers a bit
4 files changed with 19 insertions and 317 deletions:
0 comments (0 inline, 0 general)
rattail/importing/rattail.py
Show inline comments
 
# -*- coding: utf-8 -*-
 
# -*- coding: utf-8; -*-
 
################################################################################
 
#
 
#  Rattail -- Retail Software Framework
 
#  Copyright © 2010-2017 Lance Edgar
 
#  Copyright © 2010-2019 Lance Edgar
 
#
 
#  This file is part of Rattail.
 
#
 
#  Rattail is free software: you can redistribute it and/or modify it under the
 
#  terms of the GNU General Public License as published by the Free Software
 
#  Foundation, either version 3 of the License, or (at your option) any later
 
#  version.
 
#
 
#  Rattail 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 General Public License for more
 
#  details.
 
#
 
#  You should have received a copy of the GNU General Public License along with
 
#  Rattail.  If not, see <http://www.gnu.org/licenses/>.
 
#
 
################################################################################
 
"""
 
Rattail -> Rattail data import
 
"""
 

	
 
from __future__ import unicode_literals, absolute_import
 

	
 
from rattail.db import Session
 
@@ -106,73 +106,76 @@ class FromRattailToRattailBase(object):
 
        importers['DepositLink'] = DepositLinkImporter
 
        importers['Tax'] = TaxImporter
 
        importers['InventoryAdjustmentReason'] = InventoryAdjustmentReasonImporter
 
        importers['Brand'] = BrandImporter
 
        importers['Product'] = ProductImporter
 
        importers['ProductCode'] = ProductCodeImporter
 
        importers['ProductCost'] = ProductCostImporter
 
        importers['ProductPrice'] = ProductPriceImporter
 
        importers['ProductStoreInfo'] = ProductStoreInfoImporter
 
        importers['ProductImage'] = ProductImageImporter
 
        importers['LabelProfile'] = LabelProfileImporter
 
        return importers
 

	
 
    def get_default_keys(self):
 
        keys = self.get_importer_keys()
 
        if 'AdminUser' in keys:
 
            keys.remove('AdminUser')
 
        if 'ProductImage' in keys:
 
            keys.remove('ProductImage')
 
        return keys
 

	
 

	
 
class FromRattailToRattailImport(FromRattailToRattailBase, FromRattailHandler, ToRattailHandler):
 
    """
 
    Handler for Rattail -> Rattail data import.
 
    Handler for Rattail (other) -> Rattail (local) data import.
 
    """
 
    local_title = "Rattail (local)"
 
    dbkey = 'host'
 

	
 
    @property
 
    def host_title(self):
 
        return "Rattail ({})".format(self.dbkey)
 
        return "{} ({})".format(self.config.app_title(default="Rattail"), self.dbkey)
 

	
 
    @property
 
    def local_title(self):
 
        return self.config.node_title()
 

	
 
    def make_host_session(self):
 
        return Session(bind=self.config.rattail_engines[self.dbkey])
 

	
 
# TODO: deprecate/remove this?
 
FromRattailToRattail = FromRattailToRattailImport
 

	
 

	
 
class FromRattailToRattailExport(FromRattailToRattailBase, FromRattailHandler, ToRattailHandler):
 
    """
 
    Handler for Rattail -> Rattail data import.
 
    Handler for Rattail (local) -> Rattail (other) data export.
 
    """
 
    host_title = "Rattail (default)"
 

	
 
    @property
 
    def host_title(self):
 
        return self.config.node_title()
 

	
 
    @property
 
    def local_title(self):
 
        return "Rattail ({})".format(self.dbkey)
 
        return "{} ({})".format(self.config.app_title(default="Rattail"), self.dbkey)
 

	
 
    def make_session(self):
 
        return Session(bind=self.config.rattail_engines[self.dbkey])
 

	
 

	
 
class FromRattail(FromSQLAlchemy):
 
    """
 
    Base class for Rattail -> Rattail data importers.
 
    """
 

	
 
    @property
 
    def host_model_class(self):
 
        return self.model_class
 

	
 
    @property
 
    def supported_fields(self):
 
        """
 
        We only need to support the simple fields in a Rattail->Rattail import,
 
        since all relevant tables should be covered and therefore no need to do
 
        crazy foreign key acrobatics etc.
 
        """
 
        return self.simple_fields
 

	
 
    def query(self):
rattail/importing/rattail_bulk.py
Show inline comments
 
# -*- coding: utf-8 -*-
 
# -*- coding: utf-8; -*-
 
################################################################################
 
#
 
#  Rattail -- Retail Software Framework
 
#  Copyright © 2010-2017 Lance Edgar
 
#  Copyright © 2010-2019 Lance Edgar
 
#
 
#  This file is part of Rattail.
 
#
 
#  Rattail is free software: you can redistribute it and/or modify it under the
 
#  terms of the GNU General Public License as published by the Free Software
 
#  Foundation, either version 3 of the License, or (at your option) any later
 
#  version.
 
#
 
#  Rattail 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 General Public License for more
 
#  details.
 
#
 
#  You should have received a copy of the GNU General Public License along with
 
#  Rattail.  If not, see <http://www.gnu.org/licenses/>.
 
#
 
################################################################################
 
"""
 
Rattail -> Rattail bulk data import
 
"""
 

	
 
from __future__ import unicode_literals, absolute_import
 

	
 
from rattail import importing
 
from rattail.util import OrderedDict
 
from rattail.importing.rattail import FromRattailToRattail, FromRattail
 
from rattail.importing.rattail import FromRattailToRattailImport, FromRattail
 

	
 

	
 
class BulkFromRattailToRattail(FromRattailToRattail, importing.BulkImportHandler):
 
class BulkFromRattailToRattail(FromRattailToRattailImport, importing.BulkImportHandler):
 
    """
 
    Handler for Rattail -> Rattail bulk data import.
 
    """
 

	
 
    def get_importers(self):
 
        importers = OrderedDict()
 
        importers['Person'] = PersonImporter
 
        importers['PersonEmailAddress'] = PersonEmailAddressImporter
 
        importers['PersonPhoneNumber'] = PersonPhoneNumberImporter
 
        importers['PersonMailingAddress'] = PersonMailingAddressImporter
 
        importers['User'] = UserImporter
 
        importers['Message'] = MessageImporter
 
        importers['MessageRecipient'] = MessageRecipientImporter
 
        importers['Store'] = StoreImporter
 
        importers['StorePhoneNumber'] = StorePhoneNumberImporter
 
        importers['Employee'] = EmployeeImporter
 
        importers['EmployeeStore'] = EmployeeStoreImporter
 
        importers['EmployeeEmailAddress'] = EmployeeEmailAddressImporter
 
        importers['EmployeePhoneNumber'] = EmployeePhoneNumberImporter
 
        importers['ScheduledShift'] = ScheduledShiftImporter
 
        importers['WorkedShift'] = WorkedShiftImporter
 
        importers['Customer'] = CustomerImporter
 
        importers['CustomerGroup'] = CustomerGroupImporter
 
        importers['CustomerGroupAssignment'] = CustomerGroupAssignmentImporter
rattail/tests/commands/test_importing.py.bak
Show inline comments
 
deleted file
rattail/tests/importing/test_rattail.py
Show inline comments
 
@@ -35,49 +35,49 @@ class DualRattailMixin(RattailMixin):
 

	
 
        self.host_session.close()
 
        model = self.get_rattail_model()
 
        model.Base.metadata.drop_all(bind=self.config.rattail_engines['host'])
 

	
 
        if hasattr(self, 'tempio'):
 
            self.tempio = None
 

	
 

	
 
class DualRattailTestCase(DualRattailMixin, TestCase):
 
    pass
 

	
 

	
 
class TestFromRattailHandler(RattailTestCase, ImporterTester):
 
    handler_class = rattail_importing.FromRattailHandler
 
        
 
    def test_make_host_session(self):
 
        handler = self.make_handler()
 
        session = handler.make_host_session()
 
        self.assertIsInstance(session, SessionBase)
 
        self.assertIs(session.bind, self.config.rattail_engine)
 

	
 

	
 
class TestFromRattailToRattail(DualRattailTestCase, ImporterTester):
 
    handler_class = rattail_importing.FromRattailToRattail
 
    handler_class = rattail_importing.FromRattailToRattailImport
 

	
 
    def test_host_title(self):
 
        handler = self.make_handler()
 
        self.assertEqual(handler.host_title, "Rattail (host)")
 

	
 
    # TODO
 
    def test_default_keys(self):
 
        handler = self.make_handler()
 
        handler.get_default_keys()
 

	
 
    def test_make_session(self):
 
        handler = self.make_handler()
 
        session = handler.make_session()
 
        self.assertIsInstance(session, SessionBase)
 
        self.assertIs(session.bind, self.config.rattail_engine)
 

	
 
    def test_make_host_session(self):
 

	
 
        # default is 'host'
 
        handler = self.make_handler()
 
        session = handler.make_host_session()
 
        self.assertIsInstance(session, SessionBase)
 
        self.assertIs(session.bind, self.host_engine)
 

	
0 comments (0 inline, 0 general)