Skip to content
This repository has been archived by the owner on Jan 9, 2020. It is now read-only.
/ saleor-backend Public archive

Backend application of the Shopozor product. It bases on saleor's solution written in the Django framework.

Notifications You must be signed in to change notification settings

shopozor/saleor-backend

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

shopozor-backend

Build statuses

Acceptance Build Status Unit Build Status

Docker images

Development

As a frontend developer, you might need to connect your application to the Shopozor's backend server. The development docker image is produced manually upon every PR merging into the dev branch. In order to run the server,

  1. clone this repo
git clone https://github.com/shopozor/backend
cd backend
git submodule init
git submodule update
  1. run
docker-compose build

at the root of that clone; that should be run only upon backend repository clone or pull 3. run the backend

docker-compose up -d
  1. setup the database with
docker exec -it $(docker ps -aqf "name=backend_web") scripts/setup_docker_db.sh

at the root of that clone. That command initializes the database with the relevant data necessary for testing. For example, after that call, the following file with the user credentials will be added to your repo's clone:

./features/fixtures/medium/Users.json

By default, scripts/setup_docker_db.sh generates the medium fixtures set. You can provide that script with one of tiny, small, medium, large to generate the corresponding fixtures set. For example:

docker exec -it $(docker ps -aqf "name=backend_web") scripts/setup_docker_db.sh large

will generate the large fixtures set which will be located under

./features/fixtures/large/Users.json

See section "Ensure Volume Mounts Work" if the volume mounts don't seem to work under WSL.

To shutdown the backend, run

docker-compose down

at the root of your clone of the backend repository.

Continuous integration

We were not able to display the usual cucumber reports in Jenkins for this repository because the behave reports are not compatible with the cucumber reports (see e.g. this reference). Therefore our Jenkinsfile makes use of the junit framework to output acceptance test results.

Development's instructions

Setup the Shopozor software

  1. Clone the repository
git clone https://github.com/softozor/shopozor-backend
  1. Init and update all the submodules
cd shopozor-backend
git submodule init
git submodule update

In particular, saleor software will then be accessible at the latest release we granted access to.

  1. Create virtual environment
virtualenv venv
  1. Install dependencies
. venv/bin/activate
./scripts/install/install.sh
./scripts/install/install-dev.sh
  1. Activate the pre-commit hooks
./scripts/activate-hooks.sh <path-to-repo-root>

That activates pre-commit hooks for the backend code as well as for the graphql queries repo and fixtures repo.

  1. Add the relevant environment variables to the virtual environment (in the file venv/bin/activate):
export WORKSPACE=<full-path-to-repo>
export PYTHONPATH=$PYTHONPATH:$WORKSPACE/saleor
export SECRET_KEY=hahahaha
export JWT_EXPIRATION_DELTA_IN_DAYS=30
export JWT_REFRESH_EXPIRATION_DELTA_IN_DAYS=360
export JWT_SECRET_KEY='test_key'
export JWT_ALGORITHM='HS256'
  1. Everytime you need to run a shopozor command, you will need to have activated your virtual environment:
cd shopozor-backend
source venv/bin/activate

Make sure that the path to saleor module is correctly displayed by the following command in the python shell:

  1. run the python shell
python manage.py shell
  1. double-check the python path:
import sys
for path in sys.path:
    print(path)

Setup the PostgreSQL database

Following this advice, you do

sudo apt-get install wget ca-certificates
wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo apt-key add -
sudo sh -c 'echo "deb http://apt.postgresql.org/pub/repos/apt/ `lsb_release -cs`-pgdg main" >> /etc/apt/sources.list.d/pgdg.list'
sudo apt-get update
sudo apt-get install -y postgresql postgresql-contrib

Setup the Shopozor PostgreSQL database

First, you create the database user and the database:

sudo -u postgres psql -c "CREATE ROLE saleor PASSWORD 'saleor' SUPERUSER CREATEDB CREATEROLE INHERIT LOGIN;"
sudo -u postgres psql -c "CREATE DATABASE saleor OWNER saleor ENCODING 'utf-8' TEMPLATE template0;"

Second, you perform Django's database migration:

cd shopozor-backend
. ./venv/bin/activate
python manage.py migrate

Getting started

To get started, you can access the shopozor's GraphQL playground. To make it happen, you need to

sudo /etc/init.d/postgresql start
cd shopozor-backend
. ./venv/bin/activate
python manage.py runserver

Then you browse http://localhost:8000/graphql and discover the Shopozor's GraphQL playground.

Configuring Visual Studio Code

First, you need to install VS Code. The relevant configuration is set in VS Code settings file. In addition to that, you might also want to install the extensions we find useful:

cd shopozor-backend
./.vscode/install-extensions.sh

To start the shopozor-backend so that it recognizes all the necessary python module, do this:

cd shopozor-backend
. ./venv/bin/activate
code . &

In addition to that, the first time you open the project, you might need to specify the python interpreter as explained here. If you work under Windows with WSL, follow this advice.

Some of the Visual studio code settings are really user-specific. For example, the path to the python interpreter or the terminal to be used is not something we want to share across all the team. An example of user-specific settings is provided here that uses a python interpreter through a WSL terminal. Under Windows 10, such settings are usually stored under C:\Users\<username>\AppData\Roaming\Code\User\settings.json.

Testing saleor

The purpose of the shopozor-backend project is to provide the Shopozor's frontends with a backend. In particular, this means that we don't care at all about saleor's frontend developments. However, it can be that you need to run saleor's tests for some reasons. In that case, you will need to

  1. Install saleor's third-party dependencies (cf. method installSaleorDependencies of our CI/CD installation manifest)
sudo apt install -y build-essential python3-cffi libcairo2 libpango-1.0-0 libpangocairo-1.0-0 libgdk-pixbuf2.0-0 libffi-dev shared-mime-info
  1. Build saleor's frontend software (cf. unit testing pipeline)
cd shopozor-backend/saleor
npm i
npm run build-assets
npm run build-emails
  1. Run saleor's unit tests (cf. unit testing pipeline):
export DJANGO_SETTINGS_MODULE=saleor.settings
py.test -ra

Testing the Shopozor

Running the Shopozor backend acceptance tests do not require any frontend installation. Their specification is written in Gherkin language. To run them, you can run the following commands (cf. acceptance testing pipeline):

cd shopozor-backend
. ./venv/bin/activate
python manage.py behave --settings features.settings --keepdb --tags ~wip

You can get rid of the --tags option if you want to run the features that are "work in progress" too.

About

Backend application of the Shopozor product. It bases on saleor's solution written in the Django framework.

Topics

Resources

Stars

Watchers

Forks

Packages

No packages published