Skip to content

Commit

Permalink
Segregation of Dev and Prod envs (mediacms-io#218)
Browse files Browse the repository at this point in the history
Segregation of Dev and Prod envs, addition of tests

Co-authored-by: Markos Gogoulos <[email protected]>
Co-authored-by: Ubuntu <shubhank@my-hostings.nxfutj5b2tlubjykddwgszqteb.bx.internal.cloudapp.net>
  • Loading branch information
3 people authored Jul 1, 2021
1 parent d17b3b4 commit c28a39f
Show file tree
Hide file tree
Showing 12 changed files with 171 additions and 42 deletions.
54 changes: 26 additions & 28 deletions .github/workflows/python.yml
Original file line number Diff line number Diff line change
@@ -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 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -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 changes: 16 additions & 0 deletions Dockerfile-dev
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
[email protected]
[email protected]
5 changes: 5 additions & 0 deletions conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
from pytest_factoryboy import register

from tests.users.factories import UserFactory

register(UserFactory)
66 changes: 66 additions & 0 deletions docker-compose-dev.yaml
Original file line number Diff line number Diff line change
@@ -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 changes: 6 additions & 0 deletions pytest.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[pytest]
DJANGO_SETTINGS_MODULE = cms.settings
python_files = test_*.py

markers =
slow: slow running test
16 changes: 16 additions & 0 deletions requirements-dev.txt
Original file line number Diff line number Diff line change
@@ -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
15 changes: 2 additions & 13 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
13 changes: 13 additions & 0 deletions tests/test_selenium_smoke.py
Original file line number Diff line number Diff line change
@@ -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 changes: 15 additions & 0 deletions tests/users/factories.py
Original file line number Diff line number Diff line change
@@ -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
4 changes: 4 additions & 0 deletions tests/users/test_sample.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
def test_new_user(user_factory):
print(user_factory.name)
print(user_factory.description)
assert True

0 comments on commit c28a39f

Please sign in to comment.