예제 #1
0
    def test_lock(self):
        """Lock a record"""
        main_partner = self.env.ref("base.main_partner")
        work = WorkContext(model_name="res.partner", collection=self.backend)
        work.component("record.locker").lock(main_partner)

        main_partner2 = self.env2.ref("base.main_partner")
        work2 = WorkContext(model_name="res.partner", collection=self.backend2)
        locker2 = work2.component("record.locker")
        with self.assertRaises(RetryableJobError):
            locker2.lock(main_partner2)
예제 #2
0
 def _get_service_component(self, usage):
     collection = _PseudoCollection(self._collection_name, self.env)
     work = WorkContext(
         model_name="rest.service.registration",
         collection=collection,
         components_registry=self.comp_registry,
     )
     return work.component(usage=usage)
예제 #3
0
 def _get_service_component(class_or_instance, usage):
     collection = _PseudoCollection(class_or_instance._collection_name,
                                    class_or_instance.env)
     work = WorkContext(
         model_name="rest.service.registration",
         collection=collection,
         components_registry=class_or_instance.comp_registry,
     )
     return work.component(usage=usage)
예제 #4
0
    def test_public_service(self):
        collection = _PseudoCollection("emc.services", self.env)
        emc_services_env = WorkContext(model_name="rest.service.registration",
                                       collection=collection)

        service = emc_services_env.component(usage="ping")
        result = service.test()

        self.assertTrue("message" in result)
 def setUp(self):
     res = super().setUp()
     collection = _PseudoCollection("emc.services", self.env)
     emc_services_env = WorkContext(model_name="rest.service.registration",
                                    collection=collection)
     self.ap_service = emc_services_env.component(usage="payment")
     self.ai_service = emc_services_env.component(usage="invoice")
     self.demo_request_1 = self.browse_ref(
         "easy_my_coop.subscription_request_1_demo")
     return res
예제 #6
0
    def setUp(self):
        res = super().setUp()
        collection = _PseudoCollection("emc.services", self.env)
        emc_services_env = WorkContext(model_name="rest.service.registration",
                                       collection=collection)
        self.ai_service = emc_services_env.component(usage="invoice")

        self.share_type_A = self.browse_ref(
            "easy_my_coop.product_template_share_type_1_demo")
        self._capital_release_create()

        today = Date.to_string(Date.today())
        self.demo_invoice_dict = {
            "id":
            1,
            "name":
            "Capital Release Example",
            "partner": {
                "id": 1,
                "name": "Catherine des Champs"
            },
            "account": {
                "id": 1,
                "name": "Cooperators"
            },
            "journal": {
                "id": 1,
                "name": "Subscription Journal"
            },
            "subscription_request": {},
            "state":
            "open",
            "date":
            today,
            "date_invoice":
            today,
            "date_due":
            today,
            "type":
            "out_invoice",
            "invoice_lines": [{
                "name": "Share Type A",
                "product": {
                    "id": 1,
                    "name": "Part A - Founder"
                },
                "price_unit": 100.0,
                "quantity": 2.0,
                "account": {
                    "id": 2,
                    "name": "Equity"
                },
            }],
        }
        return res
예제 #7
0
 def _get_component_context(self, collection=None):
     """
     This method can be inherited to add parameter into the component
     context
     :return: dict of key value.
     """
     work = WorkContext(
         model_name="rest.service.registration",
         collection=collection or self.default_collection,
         request=request,
         controller=self,
     )
     provider = work.component(usage=self._component_context_provider)
     return provider._get_component_context()
    def setUp(self):
        super().setUp()
        collection = _PseudoCollection("emc.services", self.env)
        emc_services_env = WorkContext(model_name="rest.service.registration",
                                       collection=collection)

        self.sr_service = emc_services_env.component(
            usage="subscription-request")

        self.demo_request_1 = self.browse_ref(
            "easy_my_coop.subscription_request_1_demo")
        self.demo_request_2 = self.browse_ref(
            "easy_my_coop.subscription_request_waiting_demo")
        self.demo_share_product = (
            self.demo_request_1.share_product_id.product_tmpl_id)

        date = Date.to_string(self.demo_request_1.date)
        self.demo_request_1_dict = {
            "id": self.demo_request_1.get_api_external_id(),
            "name": "Manuel Dublues",
            "email": "*****@*****.**",
            "date": date,
            "state": "draft",
            "ordered_parts": 3,
            "share_product": {
                "id": self.demo_share_product.get_api_external_id(),
                "name": self.demo_share_product.name,
            },
            "address": {
                "street": "schaerbeekstraat",
                "zip_code": "1111",
                "city": "Brussels",
                "country": "BE",
            },
            "lang": "en_US",
            "capital_release_request": [],
        }
예제 #9
0
class TestSaleOrderImport(SaleImportCase):
    @property
    def payload_multi_sale(self):
        chunks_data = [
            self.get_chunk_vals("all")["data_str"],
            self.get_chunk_vals("all")["data_str"],
        ]
        chunks_data[1]["payment"]["reference"] = "PMT-EXAMPLE-002"
        return {"sale_orders": chunks_data}

    def setUp(self):
        super().setUp()
        # As the env.user is superuser anyways for our controllers,
        # for now we neglect it for tests
        superuser = self.env["res.users"].browse([SUPERUSER_ID])
        self.env = self.env(user=superuser)
        self.cr = self.env.cr
        self.api_key = "ASecureKeyEbay"
        collection = _PseudoCollection("sale.import.rest.services", self.env)
        self.sale_import_service_env = WorkContext(model_name="sale.order",
                                                   collection=collection)
        self.service = self.sale_import_service_env.component(usage="sale")
        self.api_key = "ASecureKeyEbay"

    def _service_create(self, vals):
        with patch(
                "odoo.addons.sale_import_rest.components.sale_import_service."
                "SaleImportService._get_api_key",
                return_value=self.api_key,
        ):
            return self.service.dispatch("create", params=vals)

    def _service_cancel(self, params):
        with patch(
                "odoo.addons.sale_import_rest.components.sale_import_service."
                "SaleImportService._get_api_key",
                return_value=self.api_key,
        ):
            return self.service.dispatch("cancel", params=params)

    def test_chunks_created(self):
        chunk_count_initial = self.env["queue.job.chunk"].search_count([])
        self._service_create(self.payload_multi_sale)
        chunk_count_after = self.env["queue.job.chunk"].search_count([])
        self.assertEqual(chunk_count_initial + 2, chunk_count_after)

    def test_wrong_key(self):
        self.api_key = "WrongKey"
        with self.assertRaises(ValidationError):
            return self._service_create(self.payload_multi_sale)

    def test_key_not_mapped_to_channel(self):
        self.env["auth.api.key"].create({
            "name": "aName",
            "key": "ASecureKey",
            "user_id": 1
        })
        self.api_key = "ASecureKey"
        with self.assertRaises(ValidationError):
            return self._service_create(self.payload_multi_sale)

    def test_cancel_sale(self):
        sale = self.env.ref("sale.sale_order_1")
        sale.sale_channel_id = self.sale_channel_ebay
        sale.client_order_ref = "CLIENTREF"
        res = self._service_cancel({"sale_name": "CLIENTREF"})
        self.assertEqual(sale.state, "cancel")
        self.assertEqual(res, {"success": True})

    def test_cancel_sale_missing(self):
        with self.assertRaises(MissingError):
            self._service_cancel({"sale_name": "does not exist"})
예제 #10
0
 def _get_service(self, usage):
     collection = _PseudoCollection("res.partner", self.env)
     work = WorkContext(
         model_name="rest.service.registration", collection=collection
     )
     return work.component(usage=usage)