Skip to content
This repository has been archived by the owner on Aug 8, 2023. It is now read-only.

Commit

Permalink
Merge pull request #17 from YoLoveLife/devel
Browse files Browse the repository at this point in the history
LiveServerTestCase
  • Loading branch information
YoLoveLife authored Sep 20, 2017
2 parents da89f16 + c207db3 commit d2a6176
Show file tree
Hide file tree
Showing 7 changed files with 83 additions and 15 deletions.
6 changes: 5 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,9 @@ services:
- mysql
install:
- pip install -r requirements.txt
before_script:
- mysql -e "CREATE DATABASE deveopsdb;"
- python apps/manage.py makemigrations
script:
- python apps/manage.py test
- python apps/manage.py migrate -v 3
- python apps/manage.py test -v 3
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ Author: [YoLoveLife.com](http://www.yolovelife.com) :ok_hand: </br>
:muscle: 已经努力让它适用于各种可能出现的生产环境</br>
django & rest-framework & bootstrap</br>
:muscle: 参考了诸多django项目 代码已经尽量优美</br>
travis & django TestCase</br>
:muscle: 单元测试 测试不规范但是努力去做

如果你关注:自动化运维、运维资源管理等内容 :star: 我,[分享](http://www.yolovelife.com)给其他的运维人员</br>
如果你关注:django开发、rest-framework等内容 :star: 我,[分享](http://www.yolovelife.com)给其他的开发者</br>
Expand Down
17 changes: 14 additions & 3 deletions apps/deveops/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
INSTALLED_APPS = [
# 'manager.apps.ManagerConfig',
'validate.apps.ValidateConfig',
'softlib.apps.SoftlibConfig',
# 'softlib.apps.SoftlibConfig',
# 'application.apps.MagicConfig',
# 'operation.apps.OperationConfig',
# 'timeline.apps.TimelineConfig',
Expand Down Expand Up @@ -95,18 +95,29 @@

# Database
# https://docs.djangoproject.com/en/1.10/ref/settings/#databases
# if 'BUILD_ON_TRAVIS' in os.environ:
# DATABASES={
# 'default':{
# 'ENGINE':'django.db.backends.mysql',
# 'NAME':'deveops_testdb',
# 'USER':'root',
# 'PASSWORD':'',
# 'HOST':'127.0.0.1',
# 'PORT':'3306',
# },
# }
# else:
DATABASES={
'default':{
'ENGINE':'django.db.backends.mysql',
'NAME':'deveopsdb',
'USER':'root',
'PASSWORD':'',
'HOST':'',
'HOST':'127.0.0.1',
'PORT':'3306',
},
}

# TEST_DATABASE_NAME='testdeveops123321'
# Password validation
# https://docs.djangoproject.com/en/1.10/ref/settings/#auth-password-validators

Expand Down
28 changes: 28 additions & 0 deletions apps/deveops/tests.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# -*- coding:utf-8 -*-
from django.test import TestCase,Client,LiveServerTestCase
# from validate.models import ExtendUser
# Create your tests here.


#view test
# class IndexPageTestCase(LiveServerTestCase):
# port = 8000
# def setUp(self):
# self.user=ExtendUser.objects.create(username='yz2',first_name='Yu',last_name='Zhou')
# self.user.set_password('testuser')
# self.user.save()
# self.c = Client(HTTP_USER_AGENT='Mozilla/5.0')
# self.c.login(username='yz2',password='testuser')
# self.c.force_login(self.user)
#
# def test_indexpage(self):
# response = self.c.get('/')
# self.assertEqual(response.status_code,200)
#
# def test_404page(self):
# response = self.c.get('/404')
# self.assertEqual(response.status_code,301)
#
# def test_permissionpage(self):
# response = self.c.get('/permission')
# self.assertEqual(response.status_code,301)
16 changes: 8 additions & 8 deletions apps/softlib/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@
from __future__ import unicode_literals

from django.test import TestCase
from softlib.models import Softlib
# from softlib.models import Softlib
# Create your tests here.
class SoftlibTestCase(TestCase):
def setUp(self):
Softlib.objects.create(soft_type='1',soft_version='1.2.1')

def test_getfullname(self):
softlib = Softlib.objects.get(soft_version='1.2.1')
self.assertEqual(softlib.soft_type,'1')
# class SoftlibTestCase(TestCase):
# def setUp(self):
# Softlib.objects.create(soft_type='1',soft_version='1.2.1')
#
# def test_getfullname(self):
# softlib = Softlib.objects.get(soft_version='1.2.1')
# self.assertEqual(softlib.soft_type,'1')
28 changes: 25 additions & 3 deletions apps/validate/tests.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
# -*- coding:utf-8 -*-
from django.test import TestCase
from django.test import TestCase,Client,LiveServerTestCase
from validate.models import ExtendUser
# Create your tests here.

#model test
class ExtendUserTestCase(TestCase):
def setUp(self):
ExtendUser.objects.create(username='yz2',first_name='Yu',last_name='Zhou')
Expand All @@ -10,5 +12,25 @@ def test_getfullname(self):
user = ExtendUser.objects.get(username='yz2')
self.assertEqual(user.get_full_name(),'YuZhou')

def tearDown(self):
super(ExtendUserTestCase,self).tearDown()
#view test
class LoginPageTestCase(LiveServerTestCase):
port = 8000
def test_loginpage(self):
c = Client()
response = c.get('/validate/login')
self.assertEqual(response.status_code,200)

class LoginPostTestCase(LiveServerTestCase):
port = 8000
def setUp(self):
ExtendUser.objects.create(username='yz2',first_name='Yu',last_name='Zhou',password='testlogin')

def test_loginpost(self):
c = Client(HTTP_USER_AGENT='Mozilla/5.0')
response = c.post('/validate/login',{'username':'yz2','passwd':'testlogin'})
self.assertEqual(response.status_code,200)

def test_logoutpage(self):
c = Client()
response = c.get('/validate/logout')
self.assertEqual(response.status_code,302)
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,5 @@ pycrypto==2.6.1
pytz==2017.2
requests==2.18.4
six==1.10.0
selenium==3.5.0
urllib3==1.22

0 comments on commit d2a6176

Please sign in to comment.