Skip to content

Commit

Permalink
[ADD] connector_carepoint: Add test coverage
Browse files Browse the repository at this point in the history
* Add Binder tests
* Add Mapper tests
* Add BaseExporter tests
* Add CarepointExporter tests
* Add CarepointImporter tests
* Add BatchImporter tests
* Add DelayedBatchImporter tests
* Add DirectBatchImporter tests
* Add related_action tests
* Add consumer tests
* Add connector tests
* Add CarepointImportMapper tests
* Add PartnerImportMapper tests
* Add PersonImportMapper tests
* Add PersonExportMapper tests
  • Loading branch information
lasley committed Aug 8, 2016
1 parent 9e5dd0a commit cadff65
Show file tree
Hide file tree
Showing 73 changed files with 2,418 additions and 250 deletions.
2 changes: 1 addition & 1 deletion connector_carepoint/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# -*- coding: utf-8 -*-
# © 2015 LasLabs Inc.
# Copyright 2015-2016 LasLabs Inc.
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).

from . import models
Expand Down
2 changes: 1 addition & 1 deletion connector_carepoint/__openerp__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# -*- coding: utf-8 -*-
# © 2015 LasLabs Inc.
# Copyright 2015-2016 LasLabs Inc.
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).

{
Expand Down
2 changes: 1 addition & 1 deletion connector_carepoint/backend.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# -*- coding: utf-8 -*-
# © 2015 LasLabs Inc.
# Copyright 2015-2016 LasLabs Inc.
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).

import openerp.addons.connector.backend as backend
Expand Down
18 changes: 10 additions & 8 deletions connector_carepoint/connector.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# -*- coding: utf-8 -*-
# © 2015 LasLabs Inc.
# Copyright 2015-2016 LasLabs Inc.
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).

from openerp import models, fields
Expand All @@ -11,13 +11,15 @@ def get_environment(session, model_name, backend_id):
""" Create an environment to work with. """
backend_record = session.env['carepoint.backend'].browse(backend_id)
env = ConnectorEnvironment(backend_record, session, model_name)
lang = backend_record.default_lang_id
lang_code = lang.code if lang else 'en_US'
if lang_code == session.context.get('lang'):
return env
else:
with env.session.change_context(lang=lang_code):
return env
return env
# @TODO: Multiple lang support. Seems not needed.
# lang = backend_record.default_lang_id
# lang_code = lang.code if lang else 'en_US'
# if lang_code == session.context.get('lang'):
# return env
# else:
# with env.session.change_context(lang=lang_code):
# return env


class CarepointBinding(models.AbstractModel):
Expand Down
28 changes: 14 additions & 14 deletions connector_carepoint/consumer.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
# -*- coding: utf-8 -*-
# © 2015 LasLabs Inc.
# Copyright 2015-2016 LasLabs Inc.
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).

from openerp.addons.connector.connector import Binder
# from openerp.addons.connector.connector import Binder
from .unit.export_synchronizer import (export_record,
)
from .unit.delete_synchronizer import export_delete_record
from .connector import get_environment
# from .unit.delete_synchronizer import export_delete_record
# from .connector import get_environment
# from openerp.addons.connector.event import (on_record_write,
# on_record_create,
# on_record_unlink
Expand Down Expand Up @@ -58,13 +58,13 @@ def delay_export_all_bindings(session, model_name, record_id, vals):
# 'carepoint.carepoint.address',
# 'carepoint.carepoint.address.patient',
# ])
def delay_unlink(session, model_name, record_id):
""" Delay a job which delete a record on Carepoint.
Called on binding records."""
record = session.env[model_name].browse(record_id)
env = get_environment(session, model_name, record.backend_id.id)
binder = env.get_connector_unit(Binder)
carepoint_id = binder.to_backend(record_id, wrap=False)
if carepoint_id:
export_delete_record.delay(session, model_name,
record.backend_id.id, carepoint_id)
# def delay_unlink(session, model_name, record_id):
# """ Delay a job which delete a record on Carepoint.
# Called on binding records."""
# record = session.env[model_name].browse(record_id)
# env = get_environment(session, model_name, record.backend_id.id)
# binder = env.get_connector_unit(Binder)
# carepoint_id = binder.to_backend(record_id, wrap=False)
# if carepoint_id:
# export_delete_record.delay(session, model_name,
# record.backend_id.id, carepoint_id)
2 changes: 1 addition & 1 deletion connector_carepoint/data/medical_units.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# -*- coding: utf-8 -*-
# © 2015 LasLabs Inc.
# Copyright 2015-2016 LasLabs Inc.
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).

#
Expand Down
2 changes: 1 addition & 1 deletion connector_carepoint/models/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# -*- coding: utf-8 -*-
# © 2015 LasLabs Inc.
# Copyright 2015-2016 LasLabs Inc.
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).

# Backend
Expand Down
2 changes: 1 addition & 1 deletion connector_carepoint/models/account.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# -*- coding: utf-8 -*-
# © 2015 LasLabs Inc.
# Copyright 2015-2016 LasLabs Inc.
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).

import logging
Expand Down
2 changes: 1 addition & 1 deletion connector_carepoint/models/account_invoice_line.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# -*- coding: utf-8 -*-
# © 2015 LasLabs Inc.
# Copyright 2015-2016 LasLabs Inc.
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).

import logging
Expand Down
2 changes: 1 addition & 1 deletion connector_carepoint/models/address.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# -*- coding: utf-8 -*-
# © 2015 LasLabs Inc.
# Copyright 2015-2016 LasLabs Inc.
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).

import logging
Expand Down
2 changes: 1 addition & 1 deletion connector_carepoint/models/address_patient.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# -*- coding: utf-8 -*-
# © 2015 LasLabs Inc.
# Copyright 2015-2016 LasLabs Inc.
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).

import logging
Expand Down
2 changes: 1 addition & 1 deletion connector_carepoint/models/address_pharmacy.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# -*- coding: utf-8 -*-
# © 2015 LasLabs Inc.
# Copyright 2015-2016 LasLabs Inc.
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).

import logging
Expand Down
2 changes: 1 addition & 1 deletion connector_carepoint/models/address_physician.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# -*- coding: utf-8 -*-
# © 2015 LasLabs Inc.
# Copyright 2015-2016 LasLabs Inc.
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).

import logging
Expand Down
2 changes: 1 addition & 1 deletion connector_carepoint/models/carepoint_backend.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# -*- coding: utf-8 -*-
# © 2015 LasLabs Inc.
# Copyright 2015-2016 LasLabs Inc.
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).

import logging
Expand Down
2 changes: 1 addition & 1 deletion connector_carepoint/models/carepoint_person.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# -*- coding: utf-8 -*-
# © 2015 LasLabs Inc.
# Copyright 2015-2016 LasLabs Inc.
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).

import logging
Expand Down
2 changes: 1 addition & 1 deletion connector_carepoint/models/carepoint_state.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# -*- coding: utf-8 -*-
# © 2015 LasLabs Inc.
# Copyright 2015-2016 LasLabs Inc.
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).

from openerp import models, fields
Expand Down
2 changes: 1 addition & 1 deletion connector_carepoint/models/fdb_form.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# -*- coding: utf-8 -*-
# © 2015 LasLabs Inc.
# Copyright 2015-2016 LasLabs Inc.
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).

import logging
Expand Down
2 changes: 1 addition & 1 deletion connector_carepoint/models/fdb_gcn.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# -*- coding: utf-8 -*-
# © 2015 LasLabs Inc.
# Copyright 2015-2016 LasLabs Inc.
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).

import logging
Expand Down
2 changes: 1 addition & 1 deletion connector_carepoint/models/fdb_gcn_seq.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# -*- coding: utf-8 -*-
# © 2015 LasLabs Inc.
# Copyright 2015-2016 LasLabs Inc.
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).

import logging
Expand Down
2 changes: 1 addition & 1 deletion connector_carepoint/models/fdb_img.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# -*- coding: utf-8 -*-
# © 2015 LasLabs Inc.
# Copyright 2015-2016 LasLabs Inc.
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).

import logging
Expand Down
2 changes: 1 addition & 1 deletion connector_carepoint/models/fdb_img_date.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# -*- coding: utf-8 -*-
# © 2015 LasLabs Inc.
# Copyright 2015-2016 LasLabs Inc.
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).

import logging
Expand Down
2 changes: 1 addition & 1 deletion connector_carepoint/models/fdb_img_id.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# -*- coding: utf-8 -*-
# © 2015 LasLabs Inc.
# Copyright 2015-2016 LasLabs Inc.
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).

import logging
Expand Down
2 changes: 1 addition & 1 deletion connector_carepoint/models/fdb_img_mfg.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# -*- coding: utf-8 -*-
# © 2015 LasLabs Inc.
# Copyright 2015-2016 LasLabs Inc.
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).

import logging
Expand Down
2 changes: 1 addition & 1 deletion connector_carepoint/models/fdb_lbl_rid.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# -*- coding: utf-8 -*-
# © 2015 LasLabs Inc.
# Copyright 2015-2016 LasLabs Inc.
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).

import logging
Expand Down
2 changes: 1 addition & 1 deletion connector_carepoint/models/fdb_ndc.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# -*- coding: utf-8 -*-
# © 2015 LasLabs Inc.
# Copyright 2015-2016 LasLabs Inc.
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).

import logging
Expand Down
2 changes: 1 addition & 1 deletion connector_carepoint/models/fdb_ndc_cs_ext.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# -*- coding: utf-8 -*-
# © 2015 LasLabs Inc.
# Copyright 2015-2016 LasLabs Inc.
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).

import logging
Expand Down
2 changes: 1 addition & 1 deletion connector_carepoint/models/fdb_pem_moe.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# -*- coding: utf-8 -*-
# © 2015 LasLabs Inc.
# Copyright 2015-2016 LasLabs Inc.
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).

import logging
Expand Down
2 changes: 1 addition & 1 deletion connector_carepoint/models/fdb_pem_mogc.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# -*- coding: utf-8 -*-
# © 2015 LasLabs Inc.
# Copyright 2015-2016 LasLabs Inc.
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).

import logging
Expand Down
2 changes: 1 addition & 1 deletion connector_carepoint/models/fdb_route.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# -*- coding: utf-8 -*-
# © 2015 LasLabs Inc.
# Copyright 2015-2016 LasLabs Inc.
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).

import logging
Expand Down
2 changes: 1 addition & 1 deletion connector_carepoint/models/fdb_unit.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# -*- coding: utf-8 -*-
# © 2015 LasLabs Inc.
# Copyright 2015-2016 LasLabs Inc.
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).

import logging
Expand Down
2 changes: 1 addition & 1 deletion connector_carepoint/models/medical_medicament.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# -*- coding: utf-8 -*-
# © 2015 LasLabs Inc.
# Copyright 2015-2016 LasLabs Inc.
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).

import logging
Expand Down
2 changes: 1 addition & 1 deletion connector_carepoint/models/medical_medicament_attribute.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# -*- coding: utf-8 -*-
# © 2015 LasLabs Inc.
# Copyright 2015-2016 LasLabs Inc.
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).

import logging
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# -*- coding: utf-8 -*-
# © 2015 LasLabs Inc.
# Copyright 2015-2016 LasLabs Inc.
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).

import logging
Expand Down
2 changes: 1 addition & 1 deletion connector_carepoint/models/medical_patient.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# -*- coding: utf-8 -*-
# © 2015 LasLabs Inc.
# Copyright 2015-2016 LasLabs Inc.
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).

import logging
Expand Down
64 changes: 2 additions & 62 deletions connector_carepoint/models/medical_pharmacy.py
Original file line number Diff line number Diff line change
@@ -1,22 +1,18 @@
# -*- coding: utf-8 -*-
# © 2015 LasLabs Inc.
# Copyright 2015-2016 LasLabs Inc.
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).

import logging
from openerp import models, fields
from openerp.addons.connector.queue.job import job
from openerp.addons.connector.connector import ConnectorUnit
from openerp.addons.connector.unit.mapper import (mapping,
only_create,
)
from ..unit.backend_adapter import CarepointCRUDAdapter
from ..connector import get_environment
from ..backend import carepoint
from ..unit.mapper import PartnerImportMapper
from ..unit.import_synchronizer import (DelayedBatchImporter,
CarepointImporter,
)
from ..connector import add_checkpoint

_logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -78,17 +74,6 @@ class MedicalPharmacyBatchImporter(DelayedBatchImporter):
"""
_model_name = ['carepoint.medical.pharmacy']

def run(self, filters=None):
""" Run the synchronization """
if filters is None:
filters = {}
record_ids = self.backend_adapter.search(**filters)
_logger.info('Search for carepoint companies %s returned %s\n',
filters, record_ids)
for record_id in record_ids:
_logger.info('In record loop with %s', record_id)
self._import_record(record_id)


@carepoint
class MedicalPharmacyImportMapper(PartnerImportMapper):
Expand All @@ -106,8 +91,8 @@ class MedicalPharmacyImportMapper(PartnerImportMapper):
('chg_date', 'updated_at'),
]

@only_create
@mapping
@only_create
def odoo_id(self, record):
""" Will bind the company on an existing company
with the same name """
Expand All @@ -130,49 +115,4 @@ def carepoint_id(self, record):
@carepoint
class MedicalPharmacyImporter(CarepointImporter):
_model_name = ['carepoint.medical.pharmacy']

_base_mapper = MedicalPharmacyImportMapper

def _create(self, data):
binding = super(MedicalPharmacyImporter, self)._create(data)
checkpoint = self.unit_for(MedicalPharmacyAddCheckpoint)
checkpoint.run(binding.id)
return binding

def _import_dependencies(self):
""" Import depends for record """
# record = self.carepoint_record
# @TODO: Fix below error
# 'csstore_addr' does not have the identity property.
# Cannot perform SET operation.
#
# self._import_dependency(record['store_id'],
# 'carepoint.carepoint.address.pharmacy')

#
# def _after_import(self, partner_binding):
# """ Import the addresses """
# book = self.unit_for(PartnerAddressBook, model='carepoint.address')
# book.import_addresses(self.carepoint_id, partner_binding.id)


@carepoint
class MedicalPharmacyAddCheckpoint(ConnectorUnit):
""" Add a connector.checkpoint on the carepoint.medical.pharmacy record """
_model_name = ['carepoint.medical.pharmacy', ]

def run(self, binding_id):
add_checkpoint(self.session,
self.model._name,
binding_id,
self.backend_record.id)


@job(default_channel='root.carepoint.core')
def company_import_batch(session, model_name, backend_id, filters=None):
""" Prepare the import of companies modified on Carepoint """
if filters is None:
filters = {}
env = get_environment(session, model_name, backend_id)
importer = env.get_connector_unit(MedicalPharmacyBatchImporter)
importer.run(filters=filters)

0 comments on commit cadff65

Please sign in to comment.