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 9 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
Jump to file
Failed to load files.
Loading
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/*

9 changes: 8 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,11 @@ Deployment scripts using fabric are located in the `Deployment` folder.
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`
13. 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.
31 changes: 31 additions & 0 deletions tools/install_venv.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#!/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

Copy link
Contributor

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 ;)

Spaces are a valid POSIX path component. There's no reason to make any assumptions whatsoever about how the project may be deployed or developed.

There's no way to forsee how code will evolve, and this is precisely the kind to bugs that may have disastrous consequences on the user's machine.


if [ "$1" != "noclean" ]
then
rm -rf $project_dir/venv
python2 -m virtualenv $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
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/truffe2/db.sqlite3
rm -rf "$project_dir/truffe2/db.sqlite3"

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

cp $project_dir/tools/settingsLocal.py.test $project_dir/truffe2/app/settingsLocal.py
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
cp $project_dir/tools/settingsLocal.py.test $project_dir/truffe2/app/settingsLocal.py
cp "$project_dir/tools/settingsLocal.py.test" "$project_dir/truffe2/app/settingsLocal.py"

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


(
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.

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

python manage.py syncdb
python manage.py migrate
if [ "$2" == "demo" ]
then
echo 'from main.test_data import initial_data; initial_data()' | python manage.py shell
fi
)
16 changes: 16 additions & 0 deletions tools/run_tests.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#!/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 -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

49 changes: 49 additions & 0 deletions tools/settingsLocal.py.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
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 = "*=)2_8tuf5qym&6szbr%=xz)g8aw=w3z)ltc=+d)iy7v7grj#!"
Copy link
Contributor

Choose a reason for hiding this comment

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

The Django secret key in test can just be set to "_" or something similar. Random keys like the one proposed may make other developers think you've leaked a key :)

Copy link
Author

Choose a reason for hiding this comment

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

Yes, of course, it's juste a random key in this case.
good idea to use only "_" letters


# 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.db.backends': {
'handlers': ['console'],
'level': 'ERROR',
'propagate': False,
},
},
}

EMAIL_HOST = 'localhost'
EMAIL_PORT = 1025
81 changes: 79 additions & 2 deletions truffe2/accounting_core/tests.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,80 @@
from django.test import TestCase
# -*- coding: utf-8 -*-
"""
This file demonstrates writing tests using the unittest module. These will pass
when you run "manage.py test".

# Create your tests here.
Replace this with more appropriate tests for your application.
"""

from main.test_tools import TruffeTestAbstract


class AccountingCoreNoLoginTest(TruffeTestAbstract):

def test_accountingyear_copy(self):
self.call_check_redirect('/accounting/core/accountingyear/1/copy')

def test_accountingyear_cost_centers(self):
self.call_check_redirect('/accounting/core/accountingyear/1/cost_centers')

def test_accountingyear_accounts(self):
self.call_check_redirect('/accounting/core/accountingyear/1/accounts')

def test_accountingyear_get_leaves_cat(self):
self.call_check_redirect('/accounting/core/accountingyear/1/get_leaves_cat')

def test_accountingyear_get_parents_cat(self):
self.call_check_redirect('/accounting/core/accountingyear/1/get_parents_cat')

def test_accountingyear_get_accounts(self):
self.call_check_redirect('/accounting/core/accountingyear/1/get_accounts')

def test_costcenter_available_list(self):
self.call_check_redirect('/accounting/core/costcenter/available_list')

def test_account_available_list(self):
self.call_check_redirect('/accounting/core/account/available_list')

def test_tva_available_list(self):
self.call_check_redirect('/accounting/core/tva/available_list')

def test_unit_users_available_list(self):
self.call_check_redirect('/accounting/core/unit/1/users_available_list')


class AccountingCoreWithLoginTest(TruffeTestAbstract):

def test_accountingyear_copy(self):
self.call_check_redirect('/accounting/core/accountingyear/1/copy',
redirect_url='/accounting/core/accountingyear/2/edit')

def test_accountingyear_cost_centers(self):
self.call_check_pdf('/accounting/core/accountingyear/1/cost_centers')

def test_accountingyear_accounts(self):
self.call_check_pdf('/accounting/core/accountingyear/1/accounts')

def test_accountingyear_get_leaves_cat(self):
self.call_check_json('/accounting/core/accountingyear/1/get_leaves_cat')

def test_accountingyear_get_parents_cat(self):
self.call_check_json('/accounting/core/accountingyear/1/get_parents_cat')

def test_accountingyear_get_accounts(self):
self.call_check_json('/accounting/core/accountingyear/1/get_accounts')
self.call_check_json('/accounting/core/accountingyear/1/get_accounts', data={"outcomes":1})
self.call_check_json('/accounting/core/accountingyear/1/get_accounts', data={"incomes":1})

def test_costcenter_available_list(self):
self.call_check_json('/accounting/core/costcenter/available_list', data={'upk':1, 'ypk':1})

def test_account_available_list(self):
self.call_check_json('/accounting/core/account/available_list', data={'ypk':1})

def test_tva_available_list(self):
self.call_check_json('/accounting/core/tva/available_list')
self.call_check_json('/accounting/core/tva/available_list', data={'q':10})
self.call_check_json('/accounting/core/tva/available_list', data={'init':10})

def test_unit_users_available_list(self):
self.call_check_json('/accounting/core/unit/1/users_available_list')
Loading