Skip to content
This repository has been archived by the owner on Apr 19, 2024. It is now read-only.

eliflores/my-first-blog

Repository files navigation

CircleCI Test Coverage Maintainability

My First Blog - Django Girls Tutorial

Introduction

I 💛 the Django Girls Tutorial. After following it, I continued the fun by:

  • Adding Tests
  • Setting up Continuous Integration with circleci
  • Setting up Code Climate for Code Quality and Code Coverage
  • Setting up a delivery pipeline to run the blog in a staging and production environment in Heroku.

How to run the project locally?

  1. Create a virtual env
python -m venv venv
  1. Active the virtual env:
source venv/bin/activate
  1. Start the web server:
python manage.py runserver localhost:8000
  1. Development server will run at: http://localhost:8000/

How to run tests?

Test suite

The test suite currently includes unit and integration tests and can be run with:

python runtests.py

It does not include E2E / UI tests, they can be run separately, see the E2E Tests section.

Single test case(s)

You can pass the module or test case:

python manage.py test <module_pattern> 

For example, to run all the tests in the test_models module:

python manage.py test tests.test_models

And you can also use the --pattern or -p argument. For example:

python manage.py test --pattern="*_forms.py"
python manage.py test -p "*_forms.py"

Modify the verbosity level

You can get more details about the test execution by passing the argument --verbosity or -v. For the value you can choose from: 0, 1, 2, 3.

For example, to pass verbosity of 2:

python manage.py test tests -v 2

Code coverage

coverage run manage.py test tests

Coverage report

coverage html -d coverage-report

E2E Tests

🔎 It is also possible to run a single E2E test by using the options described here.

On a local machine 💻

Pre-requirements

brew install geckodriver

Running E2E Tests

E2E Tests are currently run separately from the main test suite and can be run with:

python manage.py test e2e.local

On a remote machine ☁️

Remote E2E Tests - tests that run on the cloud - are setup to run on Sauce Labs ⚡.

Pre-requirements

  • A username and API Key is needed to run the tests on the Sauce Labs Testing Cloud.

Running E2E Tests

Tests that run on the cloud can be run with:

python manage.py test e2e.remote

Demo Tests

Demo tests are E2E selenium tests that run with SeleniumBase to provide a visual blog tour of this project.

Pre-requirements

brew install geckodriver

Run the demo tests

./tour.sh

Continuous Integration

Continuous Integration (CI) is managed with the help of CircleCI.

Every time a PR is opened all tests - except E2E Functional tests - are run. Passing tests are required to merge a PR to master.

Deployment

The application runs in Heroku.

There are 2 different environments:

  1. Staging
  2. Production

Deployment is managed with the help of CircleCI and after a PR is merged, the change is automagically deployed to the staging environment.

Once changes are verified in staging, they can be promoted to production using Heroku Pipelines.

Here is how the UI to promote changes looks like in Heroku:

pipeline

Review Apps

Heroku has a Review Apps feature that could be used if you would like to see or test a feature or a fix under development. You can create an ad-hoc app for a PR that is open, review the changes and then delete the app.

Here is how Review Apps UI looks like in Heroku:

review_apps