Skip to content
tobbe-joh edited this page Jul 24, 2024 · 3 revisions

Developer Guidelines

Create and Activate Virtual Environment

Create a virtual environment in the project directory and activate it:

python -m venv env

#On Windows:
env\Scripts\activate

#On Unix or macOS:
source env/bin/activate

Install Project Dependencies

Navigate to the project directory where the requirements.txt file is located and install required Python libraries listed in requirements.txt:

pip install -r requirements.txt

This command installs all the necessary packages specified in the requirements.txt file.

Database Initialization and Migration

Navigate to the directory containing manage.py and perform database migrations:

python manage.py makemigrations
python manage.py migrate
python manage.py runscript generate_data
python manage.py runscript generate_jobs
python manage.py runserver
python manage.py qcluster

These commands set up the database schema based on the Django models defined in the project. Qcluster is optional when testing and is used for automating periodic tasks

Create Local Superuser

python manage.py createsuperuser

API Endpoints

Access API documentation at http://localhost:8000/api/docs.

General naming for all APIs

/objects GET lists an object, with method name objects_list, can also have filter parameters
/objects/id GET retrieves a unique instance of object(/objects/id), with method name object_detail(id)
/objects/id POST creates an object, with method name object_add
/objects/id PATCH updates an object, with method name object_update(id)
/objects/id DELETE deletes an object, with method name object_delete(id)

Generate Random Data for Tests

python manage.py runscript delete_all_data
python manage.py runscript generate_data

All login credentials for generated users are stored in the fake_credentials.txt file located in the scripts folder.

Test Site

Access the test site at http://localhost:8000.

Troubleshooting

pkg_resources Module Error

If you encounter a ModuleNotFoundError related to pkg_resources during the migration make sure all dependencies, setup tools & pip are installed and up to date.

pip install setuptools
pip install --upgrade pip

Then retry running the migration commands.

GitHub Workflow

In our organization, we use GitHub workflows to automate the testing, building, and deployment of our projects. These workflows are defined using YAML files located in the .github/workflows directory of each repository.

Workflow Files

Each workflow file in the .github/workflows directory defines a specific pipeline. Here are the main components of our workflow file with explanations:

  • Triggers: Specify the events that trigger the workflow, such as push, pull_request or manually with workflow_dispatch.
  • Jobs: Define a sequence of tasks that the workflow will run. Each job runs in a fresh instance of a virtual environment.
  • Steps: Individual tasks within a job. These can include actions like checking out the repository, setting up Node.js, installing dependencies, running tests, and deploying the application.

Pipelines

  • codeql.yml: CodeQL performs static analysis of your code, meaning it inspects the code without executing it. This allows it to identify potential vulnerabilities, bugs, and code smells early in the development process. CodeQL can detect a wide range of security issues, including SQL injection, cross-site scripting (XSS), buffer overflows, and other common vulnerabilities.