Skip to content

Commit

Permalink
Testing update (#5)
Browse files Browse the repository at this point in the history
* pytest usage
* Update test and environment
* Update README
  • Loading branch information
kmagusiak committed Jan 5, 2024
1 parent a22692f commit 6f631bd
Show file tree
Hide file tree
Showing 10 changed files with 66 additions and 36 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ jobs:
run: docker-compose -f "docker-compose.yaml" build

- name: Run test container
run: docker-compose -f "docker-compose.yaml" -f "docker-compose.test.yaml" run odoo
run: docker-compose -f "docker-compose.yaml" -f "docker-compose.test.yaml" run --rm odoo

- name: Stop containers
if: always()
Expand Down
12 changes: 11 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@
"editor.insertSpaces": true,
"editor.tabSize": 4
},
"[javascript]": {
"editor.insertSpaces": true,
"editor.tabSize": 2
},
"black-formatter.args": [
"--skip-string-normalization",
"--line-length",
Expand All @@ -16,5 +20,11 @@
"../odoo",
"../odoo-addons",
"../odoo-addons/enterprise",
]
],
"python.testing.pytestArgs": [
"--odoo-http",
"./addons/template"
],
"python.testing.pytestEnabled": true,
"python.testing.unittestEnabled": false
}
6 changes: 5 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,12 @@ from ${DOCKER_BASE_IMAGE} as vscode
user root
run apt-get update \
&& apt-get install -y --no-install-recommends \
libxml2-utils \
bash-completion gettext git htop less openssh-client vim
# chrome for testing
run curl https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb --output /tmp/google-chrome.deb \
&& apt-get install -y --no-install-recommends /tmp/google-chrome.deb \
rm /tmp/google-chrome.deb
# python (dev) requirements
add requirements-dev.txt /tmp
run cd /tmp \
&& pip3 install --no-cache -r /tmp/requirements-dev.txt jupyterlab \
Expand Down
31 changes: 21 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@ Dockerized version of Odoo for development and debugging.
You will need `docker-compose` for this to run or `vscode` to develop inside
a container.

## The Dockerfile

Starting from [odoo-docker], add development tools
and a user for development with the same UID as yourself.

## Starting...

Let's start by generating required files, run:
Expand All @@ -13,6 +18,8 @@ launcher configuration.
You should edit the compose override file for the mounts you want.
If you change the configuration, reset your container instance.

Sample commands:

```shell
# start up odoo and the database
docker-compose up -d
Expand Down Expand Up @@ -64,15 +71,10 @@ your-project/
odoo/ # Optionally, have odoo sources available
```

## The Dockerfile

Starting from [odoo-docker], add development tools
and a user for development with the same UID as yourself.

## vscode: devcontainer

[Remote Containers extension](https://marketplace.visualstudio.com/items?itemName=ms-vscode-remote.remote-containers).

Install the extension and reopen after generating the default configuration.
Inside the devcontainer, the user is *vscode* with uid=$DEV_UID.
The same image is used for compose and devcontainer.

Expand Down Expand Up @@ -135,8 +137,9 @@ source .env
DB_TEMPLATE=dump

# load the dump
dropdb --if-exists "$DB_TEMPLATE" && createdb "$DB_TEMPLATE"
psql "$DB_TEMPLATE" < dump.sql
# dropdb --if-exists "$DB_TEMPLATE" && createdb "$DB_TEMPLATE"
# psql "$DB_TEMPLATE" < dump.sql
scripts/reset-db.sh "$DB_TEMPLATE" dump.sql

# create your copy
scripts/reset-db.sh "$DB_NAME" "$DB_TEMPLATE"
Expand All @@ -150,15 +153,23 @@ odoo-test -t -a template_module -d test_db_1
# which is similar to
odoo --test-enable --stop-after-init -i template_module -d test_db_1

# or use pytest (on existing database)
pytest --odoo-http --odoo-database test_db_1 addons/template

# using docker-compose
docker-compose -f docker-compose.yaml -f docker-compose.test.yaml run --rm odoo
```

You will probably have to also install a web-browser in the container.
If you want to run integration tests with the browser, you will have to install
a web-browser in the container.
Since the image is based on Ubuntu, chromium requires snap which
is not running in the container.
You can install [google-chrome](https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb).
Download it, and run `apt-get install ./google-chrome-stable_current_amd64.deb chromium-driver`.

```shell
curl https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb --output /tmp/google-chrome.deb
apt-get install /tmp/google-chrome.deb
```

## Translations

Expand Down
3 changes: 1 addition & 2 deletions addons/template/template_module/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@
'category': 'category',
'license': 'GPL-3',
'depends': [
# Odoo modules
'base',
'web',
],
'data': [
'security/ir.model.access.csv',
Expand Down
31 changes: 14 additions & 17 deletions addons/template/template_module/static/tests/tours/test_tour.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,14 @@
odoo.define('sale.tour', function(require) {
"use strict";

const {_t} = require('web.core');
var tour = require('web_tour.tour');

tour.register('template_tour', {
url: '/web', // Here, you can specify any other starting url
test: true,
}, [
tour.stepUtils.showAppsMenuItem(),
{
trigger: ".o_app[data-menu-xmlid='base.menu_management']",
content: _t("Open Apps"),
},
]);
});
/** @odoo-module */
import tour from 'web_tour.tour';
tour.register('template_tour', {
url: "/web",
test: true,
}, [
// tour.stepUtils.showAppsMenuItem(),
...tour.stepUtils.goToAppSteps('base.menu_management', 'Open apps'),
{
content: "Find something",
trigger: 'a',
run: function() {}, // do nothing
},
]);
8 changes: 7 additions & 1 deletion addons/template/template_module/tests/test_example.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
# https://www.odoo.com/documentation/16.0/developer/reference/backend/testing.html
from odoo.tests.common import TransactionCase
from odoo.tests.common import Form, TransactionCase


class ExampleCase(TransactionCase):
def test_create(self):
"""Default create"""
obj = self.env['template.template'].create({'name': 'test'})
self.assertEqual(len(obj), 1)

def test_form(self):
f = Form(self.env['template.template'])
f.name = 'abc'
self.assertEqual(f.hello, "Hello abc")
f.save()
3 changes: 2 additions & 1 deletion addons/template/template_module/tests/test_tour.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@
class IntegrationCase(HttpCase):
def test_tour(self):
"""Default create"""
self.start_tour("/web", 'template_module.test_tour', login="admin")
# add watch=True for debugging
self.start_tour("/web", 'template_tour', login="admin")
1 change: 1 addition & 0 deletions docker-compose.test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,5 @@ services:
"--base-addons", "${BASE_MODULES:-base}",
"--get-addons", "${TEST_MODULE_PATH:-$ODOO_EXTRA_ADDONS}",
"--addons", "${INSTALL_MODULES:-}",
"--test-tags=-tour",
]
5 changes: 3 additions & 2 deletions requirements-dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,6 @@ py-spy
# fix version for python 3.10.6
prompt-toolkit==3.0.28

# unit testing (chrome)
websocket-client
# unit testing
pytest-odoo
websocket-client # for chrome

0 comments on commit 6f631bd

Please sign in to comment.