Skip to content

Commit

Permalink
Merge pull request #160 from coopdevs/feat/add_test
Browse files Browse the repository at this point in the history
feat(testing): add devenv test
  • Loading branch information
oyale authored Apr 23, 2024
2 parents 29ffc74 + 53058a8 commit fecda00
Show file tree
Hide file tree
Showing 8 changed files with 95 additions and 3 deletions.
19 changes: 19 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,25 @@ Example Playbook
odoo_role_odoo_release: 20180424
```

Developing & Testing
-------

For developing and testing the role, we use [`devenv`](https://github.com/coopdevs/devenv) to manage local virtual machines in Linux environments.

You can use the `.devenv` file in `tests` folder to create a virtual machine.

```bash
devenv
```

Then, you can test the role with the following command:

```bash
ansible-playbook devenv.yml -i inventory
```

It will provision a virtual machine with postgresql and then, execute the role.

Release
-------

Expand Down
2 changes: 1 addition & 1 deletion defaults/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ odoo_role_list_db: false
odoo_role_dbfilter_enabled: true

# Comma-separated list of modules to install before running the server
odoo_role_odoo_core_modules: "base"
odoo_role_odoo_core_modules: "base,web"

# path of where to find the community modules requirements.txt
odoo_role_community_modules_requirements_path: "{{ inventory_dir }}/../files/requirements.txt"
Expand Down
10 changes: 10 additions & 0 deletions tests/.devenv
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# File created with devenv init command

NAME="odoo-role-test"
DISTRIBUTION="ubuntu"
RELEASE="jammy"
ARCH="amd64"
HOST="$NAME.local"

# Select the python interpeter python2.7 or python3
PYTHON_INTERPRETER=python3
2 changes: 2 additions & 0 deletions tests/ansible.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[defaults]
roles_path = ../../
20 changes: 20 additions & 0 deletions tests/devenv.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
---
- hosts: devenv
remote_user: root
become: true
# This is needed to be able to test the role without postgresql role
tasks:
- include_tasks: setup_postgresql.yml

- hosts: devenv
remote_user: root
become: true
roles:
- odoo-role
vars:
odoo_role_odoo_url: "https://git.coopdevs.org/coopdevs/odoo/OCB/-/archive/{{ odoo_role_odoo_release }}/OCB-{{ odoo_role_odoo_release }}.tar.gz"
odoo_role_odoo_version: "14.0"
odoo_role_odoo_release: "{{ odoo_role_odoo_version }}"
odoo_role_community_modules_requirements_path: requirements.txt
odoo_role_odoo_http_interface: 0.0.0.0
odoo_role_odoo_community_modules: "web_responsive,web_environment_ribbon"
6 changes: 4 additions & 2 deletions tests/inventory
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
localhost

[devenv]
odoo-role-test.local ansible_host=odoo-role-test.local
[all]
localhost ansible_connection=local
2 changes: 2 additions & 0 deletions tests/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
odoo14-addon-web_responsive==14.0.1.2.3.dev4
odoo14-addon-web_environment_ribbon==14.0.1.0.1.dev11
37 changes: 37 additions & 0 deletions tests/setup_postgresql.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
---
- name: Install pip
apt:
name: python3-pip

- name: Install psycopg2
pip:
name: psycopg2-binary

- name: Install PostgreSQL
apt:
name: postgresql
state: present
update_cache: true
when: ansible_os_family == "Debian"

- name: Ensure PostgreSQL is running
service:
name: postgresql
state: started
enabled: true

- name: Create a database user for Odoo
become: true
become_user: postgres
postgresql_user:
name: odoo
state: present
role_attr_flags: LOGIN,CREATEDB

- name: Create a database for Odoo
become: true
become_user: postgres
postgresql_db:
name: odoo
owner: odoo
state: present

0 comments on commit fecda00

Please sign in to comment.