forked from tfrancoi/odoo_csv_import
-
Notifications
You must be signed in to change notification settings - Fork 1
feat: Add e2e test for server-to-server migration #103
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
bosd
wants to merge
4
commits into
master
Choose a base branch
from
feature/e2e-test-for-migration
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,46 @@ | ||
| services: | ||
| db-source: | ||
| image: postgres:15 | ||
| container_name: odf_adv_db_source | ||
| environment: | ||
| - POSTGRES_DB=postgres | ||
| - POSTGRES_PASSWORD=odoo | ||
| - POSTGRES_USER=odoo | ||
|
|
||
| odoo-source: | ||
| image: odoo:16.0 | ||
| container_name: odf_adv_odoo_source | ||
| depends_on: | ||
| - db-source | ||
| ports: | ||
| - "8069:8069" | ||
| environment: | ||
| - HOST=db-source | ||
| - PORT=5432 | ||
| - USER=odoo | ||
| - PASSWORD=odoo | ||
| volumes: | ||
| - .:/odoo-data-flow:z | ||
|
|
||
| db-target: | ||
| image: postgres:15 | ||
| container_name: odf_adv_db_target | ||
| environment: | ||
| - POSTGRES_DB=postgres | ||
| - POSTGRES_PASSWORD=odoo | ||
| - POSTGRES_USER=odoo | ||
|
|
||
| odoo-target: | ||
| image: odoo:16.0 | ||
| container_name: odf_adv_odoo_target | ||
| depends_on: | ||
| - db-target | ||
| ports: | ||
| - "8070:8069" | ||
| environment: | ||
| - HOST=db-target | ||
| - PORT=5432 | ||
| - USER=odoo | ||
| - PASSWORD=odoo | ||
| volumes: | ||
| - .:/odoo-data-flow:z |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
|
|
||
| services: | ||
| db: | ||
| image: postgres:15 | ||
| environment: | ||
| - POSTGRES_DB=postgres | ||
| - POSTGRES_PASSWORD=odoo | ||
| - POSTGRES_USER=odoo | ||
| ports: | ||
| - "5432:5432" | ||
|
|
||
| odoo: | ||
| image: odoo:16.0 | ||
| depends_on: | ||
| - db | ||
| ports: | ||
| - "8069:8069" | ||
| environment: | ||
| - PGHOST=db | ||
| - PGPORT=5432 | ||
| - PGUSER=odoo | ||
| - PGPASSWORD=odoo | ||
|
|
||
| volumes: | ||
| - .:/odoo-data-flow:z |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,124 @@ | ||
| #!/bin/bash | ||
| set -e | ||
|
|
||
| ODOO_VERSION=$1 | ||
| if [ -z "$ODOO_VERSION" ]; then | ||
| echo "Usage: $0 <odoo_version>" | ||
| exit 1 | ||
| fi | ||
|
|
||
| COMPOSE_FILE="docker-compose.advanced.yml" | ||
|
|
||
| # Function to handle failures | ||
| handle_failure() { | ||
| echo "--- An error occurred. Dumping container logs. ---" | ||
| docker-compose -f $COMPOSE_FILE logs | ||
| echo "--- Tearing down containers ---" | ||
| docker-compose -f $COMPOSE_FILE down --volumes | ||
| exit 1 | ||
| } | ||
|
|
||
| # Trap errors | ||
| trap 'handle_failure' ERR | ||
|
|
||
|
|
||
| # Function to replace Odoo version in compose file | ||
| replace_odoo_version() { | ||
| sed "s/image: odoo:.*/image: odoo:$ODOO_VERSION/g" $COMPOSE_FILE > docker-compose.advanced.yml.tmp && mv docker-compose.advanced.yml.tmp $COMPOSE_FILE | ||
| } | ||
|
|
||
| # Clean up previous run | ||
| echo "--- Cleaning up previous run ---" | ||
| docker-compose -f $COMPOSE_FILE down --volumes || true | ||
| rm -f testdata/res_partner_advanced.csv | ||
| rm -f testdata/res_partner_category_advanced.csv | ||
| rm -rf .odf_cache | ||
| mkdir -p conf conf_target testdata | ||
|
|
||
| # Replace Odoo version in compose file | ||
| replace_odoo_version | ||
|
|
||
| # Start Odoo containers | ||
| echo "--- Starting containers for Odoo $ODOO_VERSION ---" | ||
| docker-compose -f $COMPOSE_FILE up -d --build | ||
|
|
||
| # Wait for databases to be ready | ||
| echo "--- Waiting for databases to be ready ---" | ||
| sleep 15 # Initial wait | ||
|
|
||
| echo "Waiting for Odoo Source to be ready..." | ||
| timeout 600 bash -c 'until curl -s http://localhost:8069/web/login > /dev/null; do echo -n "."; sleep 5; done' | ||
| echo "Odoo Source is ready!" | ||
|
|
||
| echo "Waiting for Odoo Target to be ready..." | ||
| timeout 600 bash -c 'until curl -s http://localhost:8070/web/login > /dev/null; do echo -n "."; sleep 5; done' | ||
| echo "Odoo Target is ready!" | ||
|
|
||
| # Create and initialize databases | ||
| echo "--- Creating and initializing databases ---" | ||
| docker-compose -f $COMPOSE_FILE exec -T odoo-source odoo -d odoo -i base --stop-after-init --db_host=db-source --db_user=odoo --db_password=odoo | ||
| docker-compose -f $COMPOSE_FILE exec -T odoo-target odoo -d odoo -i base --stop-after-init --db_host=db-target --db_user=odoo --db_password=odoo | ||
|
|
||
|
|
||
| # Install dependencies in containers | ||
| echo "--- Installing dependencies ---" | ||
| docker-compose -f $COMPOSE_FILE exec -T --user root odoo-source bash -c "apt-get update && apt-get install -y git && python3 -m pip install --upgrade pip setuptools && pip install /odoo-data-flow" | ||
| docker-compose -f $COMPOSE_FILE exec -T --user root odoo-target bash -c "apt-get update && apt-get install -y git && python3 -m pip install --upgrade pip setuptools && pip install /odoo-data-flow" | ||
|
|
||
| # Seed the source database | ||
| echo "--- Seeding source database ---" | ||
| docker-compose -f $COMPOSE_FILE exec -T odoo-source python3 /odoo-data-flow/tests/e2e/seed_advanced_database.py odoo | ||
|
|
||
| # Create connection configs | ||
| cat << EOF > conf/connection.conf | ||
| [Connection] | ||
| hostname = localhost | ||
| port = 8069 | ||
| login = admin | ||
| password = admin | ||
| database = odoo | ||
| protocol = jsonrpc | ||
| EOF | ||
|
|
||
| cat << EOF > conf_target/connection.conf | ||
| [Connection] | ||
| hostname = localhost | ||
| port = 8070 | ||
| login = admin | ||
| password = admin | ||
| database = odoo | ||
| protocol = jsonrpc | ||
| EOF | ||
|
|
||
| # Run the export for categories | ||
| echo "--- Exporting categories ---" | ||
| docker-compose -f $COMPOSE_FILE exec -T --user root odoo-source bash -c "chown -R odoo:odoo /odoo-data-flow" | ||
| docker-compose -f $COMPOSE_FILE exec -T --user odoo odoo-source bash -c "cd /odoo-data-flow && odoo-data-flow export --config conf/connection.conf --model res.partner.category --domain \"[('name', 'like', 'Test Category%')]\" --fields \"id,name\" --output testdata/res_partner_category_advanced.csv" | ||
|
|
||
| # Run the export for partners | ||
| echo "--- Exporting partners ---" | ||
| docker-compose -f $COMPOSE_FILE exec -T --user root odoo-source bash -c "chown -R odoo:odoo /odoo-data-flow" | ||
| docker-compose -f $COMPOSE_FILE exec -T --user odoo odoo-source bash -c "cd /odoo-data-flow && odoo-data-flow export --config conf/connection.conf --model res.partner --domain \"[('name', 'like', 'Advanced Test Partner%')]\" --fields \"id,name,category_id/.id\" --output testdata/res_partner_advanced.csv" | ||
|
|
||
| # Modify the partner export header for import | ||
| docker-compose -f $COMPOSE_FILE exec -T --user odoo odoo-source bash -c "cd /odoo-data-flow && sed -i 's/category_id\/.id/category_id/g' testdata/res_partner_advanced.csv" | ||
|
|
||
| # Run the import for categories into the target | ||
| echo "--- Importing categories into target ---" | ||
| docker-compose -f $COMPOSE_FILE exec -T --user root odoo-target bash -c "chown -R odoo:odoo /odoo-data-flow" | ||
| docker-compose -f $COMPOSE_FILE exec -T --user odoo odoo-target bash -c "cd /odoo-data-flow && odoo-data-flow import --config conf_target/connection.conf --file testdata/res_partner_category_advanced.csv" | ||
|
|
||
| # Run the import for partners into the target | ||
| echo "--- Importing partners into target ---" | ||
| docker-compose -f $COMPOSE_FILE exec -T --user root odoo-target bash -c "chown -R odoo:odoo /odoo-data-flow" | ||
| docker-compose -f $COMPOSE_FILE exec -T --user odoo odoo-target bash -c "cd /odoo-data-flow && odoo-data-flow import --config conf_target/connection.conf --file testdata/res_partner_advanced.csv --strategy relational" | ||
|
|
||
| # Verify the data in the target database | ||
| echo "--- Verifying data in target database ---" | ||
| docker-compose -f $COMPOSE_FILE exec -T odoo-target python3 /odoo-data-flow/tests/e2e/verify_advanced_data.py odoo | ||
|
|
||
| # Tear down the containers | ||
| echo "--- Tearing down containers ---" | ||
| docker-compose -f $COMPOSE_FILE down --volumes | ||
|
|
||
| echo "--- Advanced e2e tests completed successfully! ---" |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.