Skip to content

Commit

Permalink
arogcd_deployer: Add tests
Browse files Browse the repository at this point in the history
argocd_sale: Add tests
  • Loading branch information
tarteo committed Mar 5, 2024
1 parent 883480a commit 1c99dc9
Show file tree
Hide file tree
Showing 8 changed files with 88 additions and 8 deletions.
3 changes: 3 additions & 0 deletions argocd_deployer/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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 <[email protected]:onesteinbv/odoo-generator-k8s.git>`_


Configuration
#############

Expand All @@ -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
############

Expand Down
7 changes: 6 additions & 1 deletion argocd_deployer/models/application.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions argocd_deployer/tests/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import test_application
30 changes: 30 additions & 0 deletions argocd_deployer/tests/test_application.py
Original file line number Diff line number Diff line change
@@ -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)
1 change: 1 addition & 0 deletions argocd_sale/demo/product_template_demo.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
<record id="demo_curq_basis_product_template" model="product.template">
<field name="name">Curq Basis</field>
<field name="application_template_id" ref="argocd_deployer.demo_curq_basis_application_template" />
<field name="invoice_policy">order</field>
</record>
<record id="demo_pos_product_template" model="product.template">
<field name="name">Point of Sales</field>
Expand Down
15 changes: 8 additions & 7 deletions argocd_sale/models/account_move.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(

Check warning on line 15 in argocd_sale/models/account_move.py

View check run for this annotation

Codecov / codecov/patch

argocd_sale/models/account_move.py#L15

Added line #L15 was not covered by tests
_("Invoice can only have one application, please remove one")
)

def _customer_name_to_application_name(self):
self.ensure_one()
Expand All @@ -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
Expand Down
1 change: 1 addition & 0 deletions argocd_sale/tests/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
from . import test_reseller
from . import test_invoice_to_application
38 changes: 38 additions & 0 deletions argocd_sale/tests/test_invoice_to_application.py
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 1c99dc9

Please sign in to comment.