forked from mediacms-io/mediacms
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Segregation of Dev and Prod envs (mediacms-io#218)
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
1 parent
d17b3b4
commit c28a39f
Showing
12 changed files
with
171 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |