Commit 3495c195 authored by David Haynes's avatar David Haynes 🙆

Merge branch 'issue43' into 'master'

A simple unit test & coverage support (Closes #50)

gitlab-ci is now useful

See merge request !29
parents 9e8dc36e 5cd70da8
Pipeline #336 passed with stage
in 3 minutes and 31 seconds
......@@ -11,3 +11,6 @@ venv
/go/static/admin
/go/media
/go/go/migrations
.coverage
htmlcov/
image: ubuntu:14.04
services:
- mysql:latest
types:
- build
- test
build_Go:
type: build
script: echo Building!
variables:
MYSQL_DATABASE: go
MYSQL_ROOT_PASSWORD: root
test_Go:
type: test
script: echo Testing!
before_script:
- apt-get update -qy
- apt-get install -y python-dev python-pip python-pip libldap2-dev mysql-client libmysqlclient-dev python-mysqldb libsasl2-dev libjpeg-dev git
- pip install -r requirements.txt
- pip install coverage
- cp go/settings/settings.py.template go/settings/settings.py
- cp go/settings/secret.py.template go/settings/secret.py
- export SECRET_KEY=$(dd if=/dev/urandom count=100 | tr -dc "A-Za-z0-9" | fold -w 60 | head -n1 2>/dev/null)
- sed -i go/settings/secret.py -e 's/DB_NAME.*/DB_NAME = \"go\"/'
- sed -i go/settings/secret.py -e 's/DB_USER.*/DB_USER = \"root\"/'
- sed -i go/settings/secret.py -e 's/DB_PASSWORD.*/DB_PASSWORD = \"root\"/'
- sed -i go/settings/secret.py -e 's/DB_HOST.*/DB_HOST = \"mysql\"/'
- sed -i go/settings/secret.py -e 's/SECRET_KEY.*/SECRET_KEY = \"${SECRET_KEY}\"/'
- cd go
- export DJANGO_DEBUG="True"
- python manage.py makemigrations
- python manage.py makemigrations go
- python manage.py migrate
- echo "from django.contrib.auth import get_user_model; User = get_user_model(); User.objects.create_superuser('root', 'root@srct.gmu.edu', 'root') " | python ./manage.py shell
script:
- cd ..
- coverage run --source=go ./go/manage.py test
- coverage html
- grep pc_cov htmlcov/index.html | egrep -o "[0-9]+\%" | awk '{ print "covered " $1;}'
# Go (URL Shortener) [![build status](https://git.gmu.edu/srct/go/badges/master/build.svg)](https://git.gmu.edu/srct/go/commits/master)
# Go (URL Shortener) [![build status](https://git.gmu.edu/srct/go/badges/master/build.svg)](https://git.gmu.edu/srct/go/commits/master) [![coverage report](https://git.gmu.edu/srct/go/badges/master/coverage.svg)](https://git.gmu.edu/srct/go/commits/master)
A project of [GMU SRCT](http://srct.gmu.edu).
......@@ -104,4 +106,4 @@ manage.py.
### Note
Link by Viktor Vorobyev from the Noun Project.
\ No newline at end of file
Link by Viktor Vorobyev from the Noun Project.
from django.test import TestCase
from go.models import URL, RegisteredUser
class URLTestCase(TestCase):
def test_Django_Test(self):
self.assertEqual("Hello World!", "Hello World!")
......@@ -10,7 +10,9 @@
- hosts: all
tasks:
- name: install go packages
apt: name={{ item }} state=latest
apt:
name: "{{ item }}"
state: latest
with_items:
- python
- python-dev
......@@ -26,44 +28,54 @@
- libjpeg-dev
- name: create mysql user
mysql_user: >
name={{ mysql['user'] }}
password={{ mysql['pass'] }}
login_password={{ mysql['root_pass'] }}
login_user={{ mysql['root_user'] }}
state=present
host=localhost
priv={{ mysql['db'] }}.*:ALL
mysql_user:
name: "{{ mysql['user'] }}"
password: "{{ mysql['pass'] }}"
login_password: "{{ mysql['root_pass'] }}"
login_user: "{{ mysql['root_user'] }}"
state: present
host: localhost
priv: "{{ mysql['db'] }}.*:ALL"
- name: create mysql database
mysql_db: >
name={{ mysql['db'] }}
state=present
login_user={{ mysql['root_user'] }}
login_password={{ mysql['root_pass'] }}
mysql_db:
name: "{{ mysql['db'] }}"
state: present
login_user: "{{ mysql['root_user'] }}"
login_password: "{{ mysql['root_pass'] }}"
- name: give mysql user access to test db
mysql_user:
name: "{{ mysql['user'] }}"
login_password: "{{ mysql['root_pass'] }}"
login_user: "{{ mysql['root_user'] }}"
state: present
host: localhost
priv: test_{{ mysql['db'] }}.*:ALL
append_privs: yes
- name: install site packages to virtual env
pip: >
requirements={{ django['requirements_path'] }}
virtualenv={{ django['venv_path'] }}
virtualenv_python=python2.7
pip:
requirements: "{{ django['requirements_path'] }}"
virtualenv: "{{ django['venv_path'] }}"
virtualenv_python: python2.7
- name: install django settings.py
template: >
src=templates/settings.py.j2
dest={{ django['settings_path'] }}/settings.py
backup=yes
template:
src: templates/settings.py.j2
dest: "{{ django['settings_path'] }}/settings.py"
backup: yes
- name: install django secret.py
template: >
src=templates/secret.py.j2
dest={{ django['settings_path'] }}/secret.py
template:
src: templates/secret.py.j2
dest: "{{ django['settings_path'] }}/secret.py"
- name: setup django database
django_manage: >
command={{ item }}
app_path={{ django['app_path'] }}
virtualenv={{ django['venv_path'] }}
django_manage:
command: "{{ item }}"
app_path: "{{ django['app_path'] }}"
virtualenv: "{{ django['venv_path'] }}"
with_items:
- flush
- makemigrations
......@@ -71,10 +83,10 @@
- migrate
- name: create python superuser (defaults to dhaynes3)
django_manage: >
command="createsuperuser --noinput --username={{ django['superuser'] }} --email={{ django['superuser'] }}@masonlive.gmu.edu"
app_path={{ django['app_path'] }}
virtualenv={{ django['venv_path'] }}
django_manage:
command: "createsuperuser --noinput --username={{ django['superuser'] }} --email={{ django['superuser'] }}@masonlive.gmu.edu"
app_path: "{{ django['app_path'] }}"
virtualenv: "{{ django['venv_path'] }}"
- name: killing old screen sessions
shell: screen -ls | grep -q django && screen -X -S django quit
......
......@@ -19,4 +19,3 @@ requests==2.11.0
simplejson==3.8.2
six==1.10.0
wheel==0.29.0
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment