mirror of https://github.com/snachodog/mybuddy.git
Add tests utilities and core views tests.
This commit is contained in:
parent
f9c286cb77
commit
646ffbf093
|
@ -5,7 +5,7 @@ from .base import *
|
|||
|
||||
SECRET_KEY = '(z4ha%^_=7#jco0wmna_#0jvyyt!03#f7l_y%@1x(a2xj$nrx%'
|
||||
DEBUG = True
|
||||
# Enables the debug template varaible.
|
||||
|
||||
INTERNAL_IPS = (
|
||||
'0.0.0.0',
|
||||
'127.0.0.1',
|
||||
|
|
|
@ -0,0 +1,131 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from django.test import TestCase
|
||||
from django.test import Client as HttpClient
|
||||
from django.contrib.auth.models import User
|
||||
from django.core.management import call_command
|
||||
|
||||
from faker import Factory
|
||||
|
||||
from core import models
|
||||
|
||||
|
||||
class ViewsTestCase(TestCase):
|
||||
@classmethod
|
||||
def setUpClass(cls):
|
||||
super(ViewsTestCase, cls).setUpClass()
|
||||
fake = Factory.create()
|
||||
call_command('migrate', verbosity=0)
|
||||
call_command('fake', verbosity=0)
|
||||
|
||||
cls.c = HttpClient()
|
||||
|
||||
fake_user = fake.simple_profile()
|
||||
cls.credentials = {
|
||||
'username': fake_user['username'],
|
||||
'password': fake.password()
|
||||
}
|
||||
cls.user = User.objects.create_user(
|
||||
is_superuser=True, **cls.credentials)
|
||||
|
||||
cls.c.login(**cls.credentials)
|
||||
|
||||
def test_child_views(self):
|
||||
page = self.c.get('/children/')
|
||||
self.assertEqual(page.status_code, 200)
|
||||
page = self.c.get('/children/add/')
|
||||
self.assertEqual(page.status_code, 200)
|
||||
|
||||
entry = models.Child.objects.first()
|
||||
page = self.c.get('/children/{}/'.format(entry.slug))
|
||||
self.assertEqual(page.status_code, 200)
|
||||
page = self.c.get('/children/{}/edit/'.format(entry.slug))
|
||||
self.assertEqual(page.status_code, 200)
|
||||
page = self.c.get('/children/{}/delete/'.format(entry.slug))
|
||||
self.assertEqual(page.status_code, 200)
|
||||
|
||||
def test_diaperchange_views(self):
|
||||
page = self.c.get('/changes/')
|
||||
self.assertEqual(page.status_code, 200)
|
||||
page = self.c.get('/changes/add/')
|
||||
self.assertEqual(page.status_code, 200)
|
||||
|
||||
entry = models.DiaperChange.objects.first()
|
||||
page = self.c.get('/changes/{}/'.format(entry.id))
|
||||
self.assertEqual(page.status_code, 200)
|
||||
page = self.c.get('/changes/{}/delete/'.format(entry.id))
|
||||
self.assertEqual(page.status_code, 200)
|
||||
|
||||
def test_feeding_views(self):
|
||||
page = self.c.get('/feedings/')
|
||||
self.assertEqual(page.status_code, 200)
|
||||
page = self.c.get('/feedings/add/')
|
||||
self.assertEqual(page.status_code, 200)
|
||||
|
||||
entry = models.Feeding.objects.first()
|
||||
page = self.c.get('/feedings/{}/'.format(entry.id))
|
||||
self.assertEqual(page.status_code, 200)
|
||||
page = self.c.get('/feedings/{}/delete/'.format(entry.id))
|
||||
self.assertEqual(page.status_code, 200)
|
||||
|
||||
def test_note_views(self):
|
||||
page = self.c.get('/notes/')
|
||||
self.assertEqual(page.status_code, 200)
|
||||
page = self.c.get('/notes/add/')
|
||||
self.assertEqual(page.status_code, 200)
|
||||
|
||||
entry = models.Note.objects.first()
|
||||
page = self.c.get('/notes/{}/'.format(entry.id))
|
||||
self.assertEqual(page.status_code, 200)
|
||||
page = self.c.get('/notes/{}/delete/'.format(entry.id))
|
||||
self.assertEqual(page.status_code, 200)
|
||||
|
||||
def test_sleep_views(self):
|
||||
page = self.c.get('/sleep/')
|
||||
self.assertEqual(page.status_code, 200)
|
||||
page = self.c.get('/sleep/add/')
|
||||
self.assertEqual(page.status_code, 200)
|
||||
|
||||
entry = models.Sleep.objects.first()
|
||||
page = self.c.get('/sleep/{}/'.format(entry.id))
|
||||
self.assertEqual(page.status_code, 200)
|
||||
page = self.c.get('/sleep/{}/delete/'.format(entry.id))
|
||||
self.assertEqual(page.status_code, 200)
|
||||
|
||||
def test_timer_views(self):
|
||||
page = self.c.get('/timers/')
|
||||
self.assertEqual(page.status_code, 200)
|
||||
page = self.c.get('/timer/add/')
|
||||
self.assertEqual(page.status_code, 200)
|
||||
|
||||
page = self.c.get('/timer/add/quick/')
|
||||
self.assertEqual(page.status_code, 302)
|
||||
entry = models.Timer.objects.first()
|
||||
page = self.c.get('/timer/{}/'.format(entry.id))
|
||||
self.assertEqual(page.status_code, 200)
|
||||
|
||||
page = self.c.get('/timer/{}/edit/'.format(entry.id))
|
||||
self.assertEqual(page.status_code, 200)
|
||||
# Post to test custom get_success_url() method.
|
||||
page = self.c.post('/timer/{}/edit/'.format(entry.id), {'name': 'New'})
|
||||
self.assertEqual(page.status_code, 302)
|
||||
|
||||
page = self.c.get('/timer/{}/delete/'.format(entry.id))
|
||||
self.assertEqual(page.status_code, 200)
|
||||
page = self.c.get('/timer/{}/stop/'.format(entry.id))
|
||||
self.assertEqual(page.status_code, 302)
|
||||
page = self.c.get('/timer/{}/restart/'.format(entry.id))
|
||||
self.assertEqual(page.status_code, 302)
|
||||
|
||||
def test_tummytime_views(self):
|
||||
page = self.c.get('/tummy-time/')
|
||||
self.assertEqual(page.status_code, 200)
|
||||
page = self.c.get('/tummy-time/add/')
|
||||
self.assertEqual(page.status_code, 200)
|
||||
|
||||
entry = models.TummyTime.objects.first()
|
||||
page = self.c.get('/tummy-time/{}/'.format(entry.id))
|
||||
self.assertEqual(page.status_code, 200)
|
||||
page = self.c.get('/tummy-time/{}/delete/'.format(entry.id))
|
||||
self.assertEqual(page.status_code, 200)
|
|
@ -10,7 +10,7 @@ urlpatterns = [
|
|||
url(r'^children/add/$', views.ChildAdd.as_view(), name='child-add'),
|
||||
url(r'^children/(?P<slug>[^/.]+)/$', views.ChildDetail.as_view(),
|
||||
name='child'),
|
||||
url(r'^children/(?P<slug>[^/.]+)/edit$', views.ChildUpdate.as_view(),
|
||||
url(r'^children/(?P<slug>[^/.]+)/edit/$', views.ChildUpdate.as_view(),
|
||||
name='child-update'),
|
||||
url(r'^children/(?P<slug>[^/.]+)/delete/$', views.ChildDelete.as_view(),
|
||||
name='child-delete'),
|
||||
|
@ -47,12 +47,12 @@ urlpatterns = [
|
|||
|
||||
url(r'^timers/$', views.TimerList.as_view(), name='timer-list'),
|
||||
url(r'^timer/add/$', views.TimerAdd.as_view(), name='timer-add'),
|
||||
url(r'^timer/(?P<pk>[0-9]+)/edit$', views.TimerUpdate.as_view(),
|
||||
name='timer-update'),
|
||||
url(r'^timer/add/quick/$', views.TimerAddQuick.as_view(),
|
||||
name='timer-add-quick'),
|
||||
url(r'^timer/(?P<pk>[0-9]+)/$', views.TimerDetail.as_view(),
|
||||
name='timer-detail'),
|
||||
url(r'^timer/(?P<pk>[0-9]+)/edit/$', views.TimerUpdate.as_view(),
|
||||
name='timer-update'),
|
||||
url(r'^timer/(?P<pk>[0-9]+)/delete/$', views.TimerDelete.as_view(),
|
||||
name='timer-delete'),
|
||||
url(r'^timer/(?P<pk>[0-9]+)/stop/$', views.TimerStop.as_view(),
|
||||
|
|
|
@ -2,7 +2,7 @@ var gulp = require('gulp');
|
|||
|
||||
var sassLint = require('gulp-sass-lint');
|
||||
var pump = require('pump');
|
||||
var spawn = require('child_process').spawn;
|
||||
var spawn = require('child_process').spawn;
|
||||
|
||||
var watchConfig = require('../config.js').watchConfig;
|
||||
|
||||
|
|
|
@ -0,0 +1,36 @@
|
|||
var gulp = require('gulp');
|
||||
|
||||
var spawn = require('child_process').spawn;
|
||||
|
||||
|
||||
gulp.task('test', function(cb) {
|
||||
spawn(
|
||||
'pipenv',
|
||||
[
|
||||
'run',
|
||||
'python',
|
||||
'manage.py',
|
||||
'test'
|
||||
],
|
||||
{
|
||||
stdio: 'inherit'
|
||||
}
|
||||
).on('exit', cb);
|
||||
});
|
||||
|
||||
gulp.task('coverage', function(cb) {
|
||||
spawn(
|
||||
'pipenv',
|
||||
[
|
||||
'run',
|
||||
'coverage',
|
||||
'run',
|
||||
'--source=api,core,dashboard,reports',
|
||||
'manage.py',
|
||||
'test'
|
||||
],
|
||||
{
|
||||
stdio: 'inherit'
|
||||
}
|
||||
).on('exit', cb);
|
||||
});
|
Loading…
Reference in New Issue