Skip to main content

Checking the Django project for quality

Project description

eqator

Checking the Django project for quality. It can be convenient if you include it in CI.

Used packages:

  • django unittest - unit testing in Django.
  • flake8 - linter of source code.
  • radon - tool that computes various metrics from the source code.
  • bandit - a security linter from PyCQA.
  • coverage - a test coverage for unittest.

Quickstart

Install with pip:

pip install eqator

Add the eqator to your INSTALLED_APPS:

# settings.py

INSTALLED_APPS = [
    # ...
    'eqator',
]

To use Lighthouse scoring, install Lighthouse CI with npm:

npm install -g @lhci/cli

Check your project:

python manage.py qa

Check your project by separate options.

Run checking style guide with flake8:

python manage.py qa -f
python manage.py qa --flake

Run checking cyclomatic complexity with radon

python manage.py qa -r
python manage.py qa --radon

Run security lint with bandit

python manage.py qa -l
python manage.py qa --linter

Run django project migrations check

python manage.py qa -m
python manage.py qa --migrations

Run django unittest

python manage.py qa -t
python manage.py qa --tests

Run django unit tests for garpix_page

python manage.py qa -p
python manage.py qa --garpix_page

Lighthouse CI check:

(requires Lighthouse CI installed)

python manage.py qa -lh
python manage.py qa --lighthouse

Run test coverage check

python manage.py qa -c
python manage.py qa --test_coverage

Note, that you need to add TEST_COVERAGE_RATE variable to your settings.py file (default value is 70):

TEST_COVERAGE_RATE = 70

Optionally, do not save Lighthouse CI report files:

python manage.py qa --all --clear-reports

Check your project with all logs:

python manage.py qa --verbose

You can also add add SENTRY_CHECK_METHOD and LIGHTHOUSE_CHECK_METHOD variables to your settings.py file to controle the sentry SDK and lighthouse CI checking methods:

# settings.py
SENTRY_CHECK_METHOD = 'error'
LIGHTHOUSE_CHECK_METHOD = 'warning'

Example output with OK

Input

  Directory: /Users/aleksejkuznecov/projects/garpix_packages/eqator/backend
  Start at: 2021-02-27 12:09:30.999142

Checking

  Checking style guide with flake8 (see ".flake8") OK
  Django unit tests OK
  Cyclomatic complexity with radon (see "radon.cfg") OK
  Security lint with bandit (only high-severity issues, see ".bandit") OK

Result

  Problems found: 0
  End at: 2021-02-27 12:09:33.789880
  Duration: 0:00:02.790738

Example output with problems

Input

  Directory: /Users/aleksejkuznecov/projects/garpix_packages/eqator/backend
  Start at: 2021-02-27 12:23:41.066752

Checking

  Checking style guide with flake8 (see ".flake8") ERROR
/Users/aleksejkuznecov/projects/garpix_packages/eqator/backend/eqator/constants.py:18:4: W292 no newline at end of file
/Users/aleksejkuznecov/projects/garpix_packages/eqator/backend/eqator/helpers.py:38:1: E302 expected 2 blank lines, found 1
/Users/aleksejkuznecov/projects/garpix_packages/eqator/backend/eqator/colors.py:9:1: W391 blank line at end of file

  Django unit tests OK
  Cyclomatic complexity with radon (see "radon.cfg") OK
  Security lint with bandit (only high-severity issues, see ".bandit") ERROR
[main]  INFO    Found project level .bandit file: /Users/aleksejkuznecov/projects/garpix_packages/eqator/backend/.bandit
[main]  INFO    profile include tests: None
[main]  INFO    cli include tests: None
[main]  INFO    cli exclude tests: None
[main]  INFO    running on Python 3.8.2
Run started:2021-02-27 12:23:45.044503

Test results:
>> Issue: [B602:subprocess_popen_with_shell_equals_true] subprocess call with shell=True identified, security issue.
   Severity: High   Confidence: High
   Location: /Users/aleksejkuznecov/projects/garpix_packages/eqator/backend/eqator/helpers.py:39
   More Info: https://bandit.readthedocs.io/en/latest/plugins/b602_subprocess_popen_with_shell_equals_true.html
38      def shell_run(cmd):
39          ps = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
40          lines = ps.communicate()[0]

--------------------------------------------------
Code scanned:
        Total lines of code: 285
        Total lines skipped (#nosec): 0

Run metrics:
        Total issues (by severity):
                Undefined: 0.0
                Low: 1.0
                Medium: 0.0
                High: 1.0
        Total issues (by confidence):
                Undefined: 0.0
                Low: 0.0
                Medium: 0.0
                High: 2.0
Files skipped (0):


Result

  Problems found: 2
  End at: 2021-02-27 12:23:45.098015
  Duration: 0:00:04.031263

Configure Lighthouse CI

Edit lighthouserc.json to set URL and configure assertions.

Reference: https://github.com/GoogleChrome/lighthouse-ci/blob/main/docs/configuration.md

Changelog

See CHANGELOG.md.

Contributing

See CONTRIBUTING.md.

License

MIT


Developed by Garpix / https://garpix.com

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

eqator-2.5.0.tar.gz (17.5 kB view details)

Uploaded Source

Built Distribution

eqator-2.5.0-py3-none-any.whl (24.2 kB view details)

Uploaded Python 3

File details

Details for the file eqator-2.5.0.tar.gz.

File metadata

  • Download URL: eqator-2.5.0.tar.gz
  • Upload date:
  • Size: 17.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.8.13

File hashes

Hashes for eqator-2.5.0.tar.gz
Algorithm Hash digest
SHA256 cf767961b9a0429369bb4e026b40727242de1fd9233149db1a2f4413b9165379
MD5 8cab227b0a4a1dffba072f9e24cefee5
BLAKE2b-256 7060e889c0c41f110e6566156c06deed07fb7856692d19d4861cdfba0556dd60

See more details on using hashes here.

File details

Details for the file eqator-2.5.0-py3-none-any.whl.

File metadata

  • Download URL: eqator-2.5.0-py3-none-any.whl
  • Upload date:
  • Size: 24.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.8.13

File hashes

Hashes for eqator-2.5.0-py3-none-any.whl
Algorithm Hash digest
SHA256 d42db70084d8d01005d53c00a26591c2a2bfcdf9539ece2d396c77f79c74e48b
MD5 e86a0e7b0f57f6441597b181734a7297
BLAKE2b-256 5e68506f62b4b737eda64d941a07e4b8162ce4fac431a32ba76463d063f5748a

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page