From 1c99dc97538ca578143da05a5c231c7e52f4da53 Mon Sep 17 00:00:00 2001 From: tarteo Date: Tue, 5 Mar 2024 12:45:43 +0100 Subject: [PATCH] arogcd_deployer: Add tests argocd_sale: Add tests --- argocd_deployer/README.rst | 3 ++ argocd_deployer/models/application.py | 7 +++- argocd_deployer/tests/__init__.py | 1 + argocd_deployer/tests/test_application.py | 30 +++++++++++++++ argocd_sale/demo/product_template_demo.xml | 1 + argocd_sale/models/account_move.py | 15 ++++---- argocd_sale/tests/__init__.py | 1 + .../tests/test_invoice_to_application.py | 38 +++++++++++++++++++ 8 files changed, 88 insertions(+), 8 deletions(-) create mode 100644 argocd_deployer/tests/__init__.py create mode 100644 argocd_deployer/tests/test_application.py create mode 100644 argocd_sale/tests/test_invoice_to_application.py diff --git a/argocd_deployer/README.rst b/argocd_deployer/README.rst index 71361a8..92326ea 100644 --- a/argocd_deployer/README.rst +++ b/argocd_deployer/README.rst @@ -9,6 +9,7 @@ It uses a git generator (directory) to spawn e.g. Curq instances. By simply adding a file in like this ``instances/**/config.yaml`` the application set generates a new application. This is how the repo should look like: `Example application set `_ + Configuration ############# @@ -17,6 +18,8 @@ Configuration #. Change system parameter ``application_set_directory`` to the directory where the instance configuration files are put `(default = instances)` #. Change system parameter ``application_domain_format`` used in creating domain names for applications if there's none specified +**Assumes https is enabled for all exposed services.** + Installation ############ diff --git a/argocd_deployer/models/application.py b/argocd_deployer/models/application.py index 8775efe..527668c 100644 --- a/argocd_deployer/models/application.py +++ b/argocd_deployer/models/application.py @@ -122,7 +122,12 @@ def _compute_modules(self): @api.model def find_next_available_name(self, name): - """Returns a name which is available based on name (e.g. greg2)""" + """ + Find a name which is available based on name (e.g. greg2) + + @param name: a name + @return: first available name + """ if not self.search([("name", "=", name)], count=True): return name i = 0 diff --git a/argocd_deployer/tests/__init__.py b/argocd_deployer/tests/__init__.py new file mode 100644 index 0000000..7abb9fe --- /dev/null +++ b/argocd_deployer/tests/__init__.py @@ -0,0 +1 @@ +from . import test_application diff --git a/argocd_deployer/tests/test_application.py b/argocd_deployer/tests/test_application.py new file mode 100644 index 0000000..2d0a517 --- /dev/null +++ b/argocd_deployer/tests/test_application.py @@ -0,0 +1,30 @@ +from odoo import Command +from odoo.tests.common import TransactionCase + + +class TestApplication(TransactionCase): + def test_get_urls(self): + app = self.env["argocd.application"].create( + { + "name": "myapp", + "template_id": self.ref( + "argocd_deployer.demo_curq_basis_application_template" + ), + "tag_ids": [ + self.ref("argocd_deployer.demo_matomo_server_application_tag") + ], + } + ) + app.render_config() + urls = app.get_urls() + expected_urls = [ + ("https://myapp.curq.k8s.onestein.eu", "Odoo"), + ("https://matomo.myapp.curq.k8s.onestein.eu", "Matomo Server"), + ] + self.assertEqual(urls, expected_urls) + + app.tag_ids = [Command.clear()] + app.render_config() + urls = app.get_urls() + expected_urls = [("https://myapp.curq.k8s.onestein.eu", "Odoo")] + self.assertEqual(urls, expected_urls) diff --git a/argocd_sale/demo/product_template_demo.xml b/argocd_sale/demo/product_template_demo.xml index e71229e..1934d1d 100644 --- a/argocd_sale/demo/product_template_demo.xml +++ b/argocd_sale/demo/product_template_demo.xml @@ -3,6 +3,7 @@ Curq Basis + order Point of Sales diff --git a/argocd_sale/models/account_move.py b/argocd_sale/models/account_move.py index 4d5c368..623e26f 100644 --- a/argocd_sale/models/account_move.py +++ b/argocd_sale/models/account_move.py @@ -7,13 +7,14 @@ class AccountMove(models.Model): @api.constrains("invoice_line_ids") def _check_multiple_application_products(self): - app_lines = self.line_ids.filtered( - lambda l: l.product_id.application_template_id - ) - if len(app_lines) > 1: - raise ValidationError( - _("Invoice can only have one application, please remove one") + for move in self: + app_lines = move.line_ids.filtered( + lambda l: l.product_id.application_template_id ) + if len(app_lines) > 1: + raise ValidationError( + _("Invoice can only have one application, please remove one") + ) def _customer_name_to_application_name(self): self.ensure_one() @@ -33,7 +34,7 @@ def _invoice_paid_hook(self): ) for line in lines: name = application_sudo.find_next_available_name( - self._customer_name_to_application_name() + invoice._customer_name_to_application_name() ) tags = invoice.line_ids.filtered( lambda l: l.product_id.application_tag_ids diff --git a/argocd_sale/tests/__init__.py b/argocd_sale/tests/__init__.py index 1e87cda..cc1ff9e 100644 --- a/argocd_sale/tests/__init__.py +++ b/argocd_sale/tests/__init__.py @@ -1 +1,2 @@ from . import test_reseller +from . import test_invoice_to_application diff --git a/argocd_sale/tests/test_invoice_to_application.py b/argocd_sale/tests/test_invoice_to_application.py new file mode 100644 index 0000000..853f7c7 --- /dev/null +++ b/argocd_sale/tests/test_invoice_to_application.py @@ -0,0 +1,38 @@ +from odoo import Command +from odoo.tests import common + + +class TestInvoiceToApplication(common.TransactionCase): + def test_name_should_never_conflict(self): + """Test if a customer can create multiple applications for themselves.""" + partner = self.env["res.partner"].create({"name": "Onestein B.V. (some here)"}) + product = self.env.ref( + "argocd_sale.demo_curq_basis_product_template" + ).product_variant_ids + orders = self.env["sale.order"].create( + { + "partner_id": partner.id, + "order_line": [ + Command.create( + {"name": "Product", "product_id": product.id, "price_unit": 0} + ) + ], + } + ) + orders += orders.copy() + orders.action_confirm() + invoices = orders._create_invoices(grouped=True) + invoices.action_post() + created_applications = self.env["argocd.application"].search( + [("invoice_id", "in", invoices.ids)] + ) + application_names = created_applications.mapped("name") + self.assertEqual(len(created_applications), 2) + self.assertIn("onestein-bv-some-here", application_names) + self.assertIn("onestein-bv-some-here0", application_names) + + def test_never_multiple_applications(self): + pass # TODO + + def test_application_tags(self): + pass # TODO