Segregation of Dev and Prod envs (#218)

Segregation of Dev and Prod envs, addition of tests

Co-authored-by: Markos Gogoulos <mgogoulos@gmail.com>
Co-authored-by: Ubuntu <shubhank@my-hostings.nxfutj5b2tlubjykddwgszqteb.bx.internal.cloudapp.net>
This commit is contained in:
Shubhank Saxena 2021-07-01 20:35:43 +05:30 committed by GitHub
parent d17b3b4153
commit c28a39fa47
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
12 changed files with 171 additions and 42 deletions

View File

@ -1,37 +1,35 @@
name: Python Tests
on: [push]
on:
pull_request:
push:
branches:
- main
jobs:
build:
runs-on: ubuntu-latest
services:
postgres:
image: postgres:12
env:
POSTGRES_USER: mediacms
POSTGRES_PASSWORD: mediacms
POSTGRES_DB: mediacms
ports:
- 5432:5432
# needed because the postgres container does not provide a healthcheck
options: --health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 5
steps:
- uses: actions/checkout@v1
- name: Set up Python 3.7
uses: actions/setup-python@v1
with:
python-version: 3.7
- name: psycopg2 prerequisites
run: sudo apt-get install libpq-dev
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt
- name: Run migrations
run: python manage.py migrate
- name: Run tests
run: py.test
- name: Checkout
uses: actions/checkout@v1
- name: Build the Stack
run: docker-compose -f docker-compose-dev.yaml build
- name: Start containers
run: docker-compose -f docker-compose-dev.yaml up -d
- name: List containers
run: docker ps
- name: Sleep for 60 seconds
run: sleep 60s
shell: bash
- name: Run Django Tests
run: docker-compose -f docker-compose-dev.yaml exec -T web pytest
- name: Tear down the Stack
run: docker-compose -f docker-compose-dev.yaml down

1
.gitignore vendored
View File

@ -12,5 +12,6 @@ static/ckeditor/
static/debug_toolbar/
static/mptt/
static/rest_framework/
static/drf-yasg
cms/local_settings.py
deploy/docker/local_settings.py

16
Dockerfile-dev Normal file
View File

@ -0,0 +1,16 @@
FROM mediacms/mediacms:latest
SHELL ["/bin/bash", "-c"]
# Set up virtualenv
ENV VIRTUAL_ENV=/home/mediacms.io
ENV PATH="$VIRTUAL_ENV/bin:$PATH"
ENV PIP_NO_CACHE_DIR=1
RUN cd /home/mediacms.io && python3 -m venv $VIRTUAL_ENV
COPY requirements.txt .
COPY requirements-dev.txt .
RUN pip install -r requirements-dev.txt
WORKDIR /home/mediacms.io/mediacms

View File

@ -125,4 +125,4 @@ If you like the project, here's a few things you can do
- Checkout the [Code of conduct page](CODE_OF_CONDUCT.md) if you want to contribute to this repository
## Contact
info@mediacms.io
info@mediacms.io

5
conftest.py Normal file
View File

@ -0,0 +1,5 @@
from pytest_factoryboy import register
from tests.users.factories import UserFactory
register(UserFactory)

66
docker-compose-dev.yaml Normal file
View File

@ -0,0 +1,66 @@
version: "3"
services:
# frontend:
# image: node:14
# volumes:
# - ${PWD}/frontend:/home/mediacms.io/mediacms/frontend/
# working_dir: /home/mediacms.io/mediacms/frontend/
# command: bash -c "npm install && npm run start"
# env_file:
# - ${PWD}/frontend/.env
# ports:
# - "8097:8097"
# depends_on:
# - web
web:
build:
context: .
dockerfile: ./Dockerfile-dev
image: mediacms/mediacms-dev:latest
ports:
- "80:80"
volumes:
- ./:/home/mediacms.io/mediacms/
depends_on:
redis:
condition: service_healthy
db:
condition: service_healthy
selenium_hub:
container_name: selenium_hub
image: selenium/hub
ports:
- "4444:4444"
selenium_chrome:
container_name: selenium_chrome
image: selenium/node-chrome-debug
environment:
- HUB_PORT_4444_TCP_ADDR=selenium_hub
- HUB_PORT_4444_TCP_PORT=4444
ports:
- "5900:5900"
depends_on:
- selenium_hub
db:
image: postgres
volumes:
- ../postgres_data:/var/lib/postgresql/data/
restart: always
environment:
POSTGRES_USER: mediacms
POSTGRES_PASSWORD: mediacms
POSTGRES_DB: mediacms
healthcheck:
test: ["CMD-SHELL", "pg_isready -U mediacms"]
interval: 10s
timeout: 5s
retries: 5
redis:
image: "redis:alpine"
restart: always
healthcheck:
test: ["CMD", "redis-cli","ping"]
interval: 30s
timeout: 10s
retries: 3

6
pytest.ini Normal file
View File

@ -0,0 +1,6 @@
[pytest]
DJANGO_SETTINGS_MODULE = cms.settings
python_files = test_*.py
markers =
slow: slow running test

16
requirements-dev.txt Normal file
View File

@ -0,0 +1,16 @@
-r requirements.txt
rpdb
tqdm
ipython
flake8
pylint
pep8
django-silk
pre-commit
pytest-cov
pytest-django
pytest-factoryboy
Faker
selenium
webdriver-manager

View File

@ -28,17 +28,6 @@ django-celery-email
m3u8
django-ckeditor
django-login-required-middleware==0.6.1
# extra nice utilities!
rpdb
tqdm
ipython
flake8
pylint
pep8
django-silk
django-debug-toolbar
pre-commit
pytest-django
django-login-required-middleware==0.6.1

View File

@ -0,0 +1,13 @@
from django.test import TestCase
from selenium import webdriver
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
class SeleniumTest(TestCase):
def setUp(self):
self.chrome = webdriver.Remote(command_executor='http://selenium_hub:4444/wd/hub', desired_capabilities=DesiredCapabilities.CHROME)
self.chrome.implicitly_wait(10)
def test_visit_site_with_chrome(self):
self.chrome.get('http://web/admin')
self.assertIn(self.chrome.title, "Log in | Django site admin")

15
tests/users/factories.py Normal file
View File

@ -0,0 +1,15 @@
import factory
from django.conf import settings
from faker import Faker
fake = Faker()
User = settings.AUTH_USER_MODEL
class UserFactory(factory.django.DjangoModelFactory):
class Meta:
model = User
description = fake.paragraph(nb_sentences=4)
name = fake.name()
is_editor = True

View File

@ -0,0 +1,4 @@
def test_new_user(user_factory):
print(user_factory.name)
print(user_factory.description)
assert True