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

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 ...@@ -11,3 +11,6 @@ venv
/go/static/admin /go/static/admin
/go/media /go/media
/go/go/migrations /go/go/migrations
.coverage
htmlcov/
image: ubuntu:14.04
services:
- mysql:latest
types: types:
- build
- test - test
build_Go: variables:
type: build MYSQL_DATABASE: go
script: echo Building! MYSQL_ROOT_PASSWORD: root
test_Go: test_Go:
type: test 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). A project of [GMU SRCT](http://srct.gmu.edu).
...@@ -104,4 +106,4 @@ manage.py. ...@@ -104,4 +106,4 @@ manage.py.
### Note ### Note
Link by Viktor Vorobyev from the Noun Project. Link by Viktor Vorobyev from the Noun Project.
\ No newline at end of file
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 @@ ...@@ -10,7 +10,9 @@
- hosts: all - hosts: all
tasks: tasks:
- name: install go packages - name: install go packages
apt: name={{ item }} state=latest apt:
name: "{{ item }}"
state: latest
with_items: with_items:
- python - python
- python-dev - python-dev
...@@ -26,44 +28,54 @@ ...@@ -26,44 +28,54 @@
- libjpeg-dev - libjpeg-dev
- name: create mysql user - name: create mysql user
mysql_user: > mysql_user:
name={{ mysql['user'] }} name: "{{ mysql['user'] }}"
password={{ mysql['pass'] }} password: "{{ mysql['pass'] }}"
login_password={{ mysql['root_pass'] }} login_password: "{{ mysql['root_pass'] }}"
login_user={{ mysql['root_user'] }} login_user: "{{ mysql['root_user'] }}"
state=present state: present
host=localhost host: localhost
priv={{ mysql['db'] }}.*:ALL priv: "{{ mysql['db'] }}.*:ALL"
- name: create mysql database - name: create mysql database
mysql_db: > mysql_db:
name={{ mysql['db'] }} name: "{{ mysql['db'] }}"
state=present state: present
login_user={{ mysql['root_user'] }} login_user: "{{ mysql['root_user'] }}"
login_password={{ mysql['root_pass'] }} 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 - name: install site packages to virtual env
pip: > pip:
requirements={{ django['requirements_path'] }} requirements: "{{ django['requirements_path'] }}"
virtualenv={{ django['venv_path'] }} virtualenv: "{{ django['venv_path'] }}"
virtualenv_python=python2.7 virtualenv_python: python2.7
- name: install django settings.py - name: install django settings.py
template: > template:
src=templates/settings.py.j2 src: templates/settings.py.j2
dest={{ django['settings_path'] }}/settings.py dest: "{{ django['settings_path'] }}/settings.py"
backup=yes backup: yes
- name: install django secret.py - name: install django secret.py
template: > template:
src=templates/secret.py.j2 src: templates/secret.py.j2
dest={{ django['settings_path'] }}/secret.py dest: "{{ django['settings_path'] }}/secret.py"
- name: setup django database - name: setup django database
django_manage: > django_manage:
command={{ item }} command: "{{ item }}"
app_path={{ django['app_path'] }} app_path: "{{ django['app_path'] }}"
virtualenv={{ django['venv_path'] }} virtualenv: "{{ django['venv_path'] }}"
with_items: with_items:
- flush - flush
- makemigrations - makemigrations
...@@ -71,10 +83,10 @@ ...@@ -71,10 +83,10 @@
- migrate - migrate
- name: create python superuser (defaults to dhaynes3) - name: create python superuser (defaults to dhaynes3)
django_manage: > django_manage:
command="createsuperuser --noinput --username={{ django['superuser'] }} --email={{ django['superuser'] }}@masonlive.gmu.edu" command: "createsuperuser --noinput --username={{ django['superuser'] }} --email={{ django['superuser'] }}@masonlive.gmu.edu"
app_path={{ django['app_path'] }} app_path: "{{ django['app_path'] }}"
virtualenv={{ django['venv_path'] }} virtualenv: "{{ django['venv_path'] }}"
- name: killing old screen sessions - name: killing old screen sessions
shell: screen -ls | grep -q django && screen -X -S django quit shell: screen -ls | grep -q django && screen -X -S django quit
......
...@@ -19,4 +19,3 @@ requests==2.11.0 ...@@ -19,4 +19,3 @@ requests==2.11.0
simplejson==3.8.2 simplejson==3.8.2
six==1.10.0 six==1.10.0
wheel==0.29.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