Skip to content
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

Patch for step # #43

Open
wants to merge 33 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
3858c5d
correct pip dependancy
GayLaurent Oct 14, 2020
6a88a1b
Merge branch 'master' of github.com:GayLaurent/truffe2
GayLaurent Oct 14, 2020
548eb86
add tests script with code coverage
GayLaurent Oct 14, 2020
d7d29bd
add tests for main, logistics, users, vehicles
GayLaurent Oct 17, 2020
04771ab
correct tests logistics
GayLaurent Oct 17, 2020
e763972
append new regression tests
GayLaurent Oct 19, 2020
8d6f4d2
append new no-regression tests
GayLaurent Oct 20, 2020
7b89f24
complete README.md with option of script
GayLaurent Oct 21, 2020
c7e858b
add tests for GenericModelWithLines
GayLaurent Oct 21, 2020
59f476b
corections after feetback of truffe2 community
GayLaurent Oct 28, 2020
008795e
migrate from Django 1.6 to Django 1.7
Oct 29, 2020
7ceaaa4
migrate from Django 1.7 to Django 1.8
Oct 31, 2020
2d03683
migrate from Django 1.8 to Django 1.9
Oct 31, 2020
071dae9
correct wsgi
Nov 2, 2020
cb20e0a
correct list json
Nov 2, 2020
a263a96
migrate from Django 1.9 to Django 1.10
Nov 2, 2020
6278bad
migrate from Django 1.10 to Django 1.11
Nov 3, 2020
9712373
Fix missing change in url ref from . to -
TeoGoddet Nov 4, 2020
3a5b3d7
Merge pull request #1 from TeoGoddet/master
GayLaurent Nov 4, 2020
97c075a
correction about migration 1.6->1.11 on production server
Nov 4, 2020
bf529cd
correction about tequila login
Nov 5, 2020
f7a6f32
Fix for guest account testing
TeoGoddet Nov 6, 2020
e2a2a15
change PDF generator and upgrade old components
Nov 9, 2020
b100bcd
migrate from Python 2.7 to Python 3.5
Nov 10, 2020
78904ce
migrate from Python 3.5 to Python 3.7
Nov 10, 2020
b5812e6
Library Py3 for HTML to PDF
Nov 10, 2020
e95284c
change README & deployement script for Py3
Nov 10, 2020
c786c5a
Merge pull request #2 from TeoGoddet/master
GayLaurent Nov 10, 2020
193f377
correct Python3 for tequila login
Nov 13, 2020
97bf598
correct for tequila login
Nov 13, 2020
86f1c65
migrate to Django 2.2 + upgrade library + correct PDF
Feb 10, 2021
f77716f
migrate to Django 3.1 + check Python 3.8
Feb 11, 2021
477f940
Migrate correction: map/filter using -> typecast to list + replace it…
Mar 8, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
8 changes: 7 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,13 @@
.ropeproject
*.swp
*.sw?
.project
.pydevproject
.settings/

htmlcov/*
truffe2/.coverage
truffe2/db.sqlite3
venv/*
truffe2/.idea/*
truffe2/.idea/*

1 change: 0 additions & 1 deletion Deployement/django.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,6 @@ def chmod_and_chown():
def sync_databases():
"""Sync django databases"""
with cd('/var/www/git-repo/truffe2/truffe2'):
sudo("python manage.py syncdb --noinput")
sudo("python manage.py migrate --noinput")


Expand Down
21 changes: 14 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ Truffe 2 is licensed under the [BSD](http://opensource.org/licenses/BSD-2-Clause
* Cedric Cook (Fixed a typo)
* Yolan Romailler (Fixed a path)
* Yann Beaud (Fixed VCARDs)
* Laurent Gay (Migration to Python3/Django3)

## Development

Expand All @@ -38,16 +39,22 @@ Deployment scripts using fabric are located in the `Deployment` folder.

### Example development environment setup

1. Create a virtual Python environment: `virtualenv --python=/usr/bin/python2 venv`
1. Create a virtual Python 3 environment: `virtualenv --python=/usr/bin/python3 venv`
2. Activate it: `. ./venv/bin/activate`
3. Install dependencies: `pip install -r ./truffe2/data/pip-reqs.txt`
4. `cp ./truffe2/app/settingsLocal.py{.dist,}`
5. Edit `./truffe2/app/settingsLocal.py` and set the database engine to `django.db.backends.sqlite3` and database name to `db.sqlite3`
6. To be apple to see the mails sent from the application, run a [maildump](https://pypi.python.org/pypi/maildump) instance on port 1025
7. Go inside the `truffe2` directory for the next steps: `cd truffe2`
8. Create the database tables not managed by south with `python manage.py syncdb`
9. On OSX, if you get `ImportError: MagickWand shared library not found.`, it's probably because Python was not installed using MacPorts, you have to export MAGICK_HOME path. You should try to set the path with `export MAGICK_HOME=/opt/local` and go back to point 8.
10. Create the database tables managed by south with `python manage.py migrate`
11. Run the development server with `python manage.py runserver`
12. Go to `http://localhost:8000/` and log in with Tequila
13. Give your user superuser rights with `echo "update users_truffeuser set is_superuser=1 where id=1;" | sqlite3 db.sqlite3`
8. On OSX, if you get `ImportError: MagickWand shared library not found.`, it's probably because Python was not installed using MacPorts, you have to export MAGICK_HOME path. You should try to set the path with `export MAGICK_HOME=/opt/local` and go back to point 8.
9. Create the database tables with `python manage.py migrate`
10. Run the development server with `python manage.py runserver`
11. Go to `http://localhost:8000/` and log in with Tequila
12. Give your user superuser rights with `echo "update users_truffeuser set is_superuser=1 where id=1;" | sqlite3 db.sqlite3`

Those actions are setting in a script for Linux : `tools/install_venv.sh`.
2 Options for this script:
- `./tools/install_venv.sh noclean` : don't remove virtual Python environment, just delete SQLite DB file and reload a new DB.
- `./tools/install_venv.sh "" demo` : add examples of data for testing in DB (5 users: admin, user1, user2, user3, user4 with username as password).

A new script, `tools/run_tests.sh`, allows to launch tests with code coverage.
32 changes: 32 additions & 0 deletions tools/install_venv.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#!/bin/bash
# Script to install virtual environment for truffe2 for developpement
# --- DO NOT USE IN PRODUCTION MODE ---

set -e
set +x

project_dir="$(dirname $(dirname $(readlink -f "$0")))"

if [ "$1" != "noclean" ]
then
rm -rf "$project_dir/venv"
python3 -m virtualenv --python python3.8 "$project_dir/venv"

. "$project_dir/venv/bin/activate"
pip install -U pip
pip install -r "$project_dir/truffe2/data/pip-reqs.txt"
else
. "$project_dir/venv/bin/activate"
fi

rm -rf "$project_dir/truffe2/db.sqlite3"
cp "$project_dir/tools/settingsLocal.py.test" "$project_dir/truffe2/app/settingsLocal.py"

(
cd "$project_dir/truffe2"
python -Wd manage.py migrate
if [ "$2" == "demo" ]
then
echo 'from main.test_data import setup_testing_all_data; setup_testing_all_data()' | python -Wd manage.py shell
fi
)
18 changes: 18 additions & 0 deletions tools/run_tests.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#!/bin/bash

set +e
set +x

project_dir=$(dirname $(dirname $(readlink -f "$0")))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
project_dir=$(dirname $(dirname $(readlink -f "$0")))
project_dir="$(dirname $(dirname $(readlink -f "$0")))"

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Normaly, good developper don't use space in working directory ;)
But, it's a good idea to protect about this bad using


rm -rf $project_dir/htmlcov
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
rm -rf $project_dir/htmlcov
rm -rf "$project_dir/htmlcov"

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good idea to protect about this bad using

. $project_dir/venv/bin/activate

cd $project_dir/truffe2
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
cd $project_dir/truffe2
cd "$project_dir/truffe2"

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good idea to protect about this bad using

python -m pip install -U coverage >/dev/null
python -m coverage erase
python -Wd -m coverage run --branch --source=. manage.py test
# python -m coverage report
python -m coverage html -d $project_dir/htmlcov
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
python -m coverage html -d $project_dir/htmlcov
python -m coverage html -d "$project_dir/htmlcov"

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good idea to protect about this bad using


deactivate
57 changes: 57 additions & 0 deletions tools/settingsLocal.py.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
from os.path import join, dirname, abspath
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': join(dirname(dirname(abspath(__file__))), 'db.sqlite3'),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it really a good idea to use a sqlite3 database since it's not what is used in production ?

I suggest using the same database to avoid potential issues

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMHO the production database sets even a higher barrier to potentially new developers. I'd rather stay with something simple and if a CI is ever implemented use the production configuration there. In any case, it should be easily replaceable (e.g. TEST_DATABASE_URL envvar). A section in the README.md about reading the tests should be added.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Developers should use the correct database, especially dues to various small changes that can lead to misbehavior and/or missing features.

Tests are meaningless if they fail or not depending on the context. Developers should not use sqlite3.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's hard to find developers motivated to code truffe ! I'm against creating supplementary barrier. And Django provide a correct abstraction of the database. To my opinion, we should instead avoid database specific code.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need to decide on this @the-glu !

Copy link
Contributor

@roosemberth roosemberth Feb 10, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I support @TeoGoddet's argument on this one.

}
}

SECRET_KEY = "_____________________________________________________"

# Deactivate Haystack indexing on save
HAYSTACK_SIGNAL_PROCESSOR = 'haystack.signals.BaseSignalProcessor'

# Logging to console, for debug :)
LOGGING = {
'disable_existing_loggers': False,
'version': 1,
'formatters': {
'verbose': {
'format': '%(levelname)s %(asctime)s %(module)s %(process)d %(thread)d %(message)s'
},
'simple': {
'format': '%(levelname)s %(message)s'
},
},
'handlers': {
'console': {
'level': 'DEBUG',
'class': 'logging.StreamHandler',
'formatter': 'simple'
},
},
'loggers': {
'django': {
'handlers': ['console'],
'level': 'DEBUG',
'propagate': True,
},

'django.template': {
'handlers': ['console'],
'level': 'INFO',
'propagate': True,
},

'django.db.backends': {
'handlers': ['console'],
'level': 'ERROR',
'propagate': False,
},
},
}

EMAIL_HOST = 'localhost'
EMAIL_PORT = 1025

TEQUILA_ALLOW_GUEST = True # used for test
Loading