This repository has been archived by the owner on Aug 8, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 262
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #18 from YoLoveLife/devel
some models testcase
- Loading branch information
Showing
10 changed files
with
204 additions
and
40 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
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
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,28 +1,27 @@ | ||
# -*- coding:utf-8 -*- | ||
from django.test import TestCase,Client,LiveServerTestCase | ||
# from validate.models import ExtendUser | ||
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) | ||
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') | ||
|
||
def test_indexpage(self): | ||
response = self.c.get('/') | ||
self.assertEqual(response.status_code,302) | ||
|
||
def test_404page(self): | ||
self.c.force_login(self.user) | ||
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) |
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
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 |
---|---|---|
@@ -1,3 +1,77 @@ | ||
# -*- coding:utf-8 -*- | ||
from __future__ import unicode_literals | ||
from django.test import TestCase | ||
from manager.models import Group,Host,Storage | ||
#model test | ||
class GroupTestCase(TestCase): | ||
def setUp(self): | ||
Group.objects.create(name='Testname',info='Testinfo') | ||
|
||
def test_groupcreate(self): | ||
group = Group.objects.get(name='Testname') | ||
self.assertEqual(group.info,'Testinfo') | ||
|
||
def test_groupupdate(self): | ||
group = Group.objects.get(name='Testname') | ||
group.info='Testinfo2' | ||
group.save() | ||
self.assertEqual(group.info,'Testinfo2') | ||
|
||
def test_groupdelete(self): | ||
Group.objects.filter(name='Testname').delete() | ||
self.assertEqual(Group.objects.filter(name='Testname').count(),0) | ||
|
||
class StorageTestCase(TestCase): | ||
def setUp(self): | ||
Storage.objects.create(disk_size='1024GB',disk_path='//192.168.0.1/testdisk',info='testdisk') | ||
|
||
def test_storagecreate(self): | ||
storage=Storage.objects.get(disk_size='1024GB') | ||
self.assertEqual(storage.disk_path,'//192.168.0.1/testdisk') | ||
|
||
def test_storageupdate(self): | ||
Storage.objects.filter(disk_size='1024GB').update(disk_path='//192.168.0.1/ddr') | ||
storage = Storage.objects.get(disk_size='1024GB') | ||
self.assertEqual(storage.disk_path,'//192.168.0.1/ddr') | ||
|
||
def test_storagedelete(self): | ||
Storage.objects.filter(disk_size='1024GB').delete() | ||
self.assertEqual(Storage.objects.filter(disk_size='1024GB').count(),0) | ||
|
||
class HostTestCase(TestCase): | ||
def setUp(self): | ||
Group.objects.create(name='Testgroup',info='Testgroupinfo') | ||
Storage.objects.create(disk_size='1024GB', disk_path='//192.168.0.1/testdisk', info='testdisk') | ||
groups = Group.objects.filter(name='Testgroup') | ||
storages = Storage.objects.filter(disk_size='1024GB') | ||
host = Host.objects.create(systemtype=1, | ||
manage_ip='192.168.1.1',service_ip='192.168.1.2', | ||
outer_ip='192.168.1.3',server_position='VmWare', | ||
hostname='localhost.localdomain',normal_user='TestProd', | ||
sshpasswd='testpasswd',sshport='52000',coreness='36', | ||
memory='1024MB',root_disk='1024G',info='testinfo') | ||
host.storages = storages | ||
host.groups = groups | ||
host.save() | ||
|
||
def test_hostcreate(self): | ||
host = Host.objects.get(service_ip='192.168.1.2') | ||
self.assertEqual(host.hostname,'localhost.localdomain') | ||
|
||
def test_hostmany2many(self): | ||
host = Host.objects.get(service_ip='192.168.1.2') | ||
self.assertEqual(host.groups.all()[0].name,'Testgroup') | ||
self.assertEqual(host.storages.all()[0].disk_path,'//192.168.0.1/testdisk') | ||
|
||
def test_storage_getallgroupname(self): | ||
storage = Storage.objects.get(disk_size='1024GB') | ||
self.assertEqual(storage.get_all_group_name(),'Testgroup') | ||
|
||
def test_hostupdate(self): | ||
Host.objects.filter(service_ip='192.168.1.2').update(server_position='Position-1') | ||
host = Host.objects.get(service_ip='192.168.1.2') | ||
self.assertEqual(host.server_position,'Position-1') | ||
|
||
def test_hostdelete(self): | ||
Host.objects.filter(service_ip='192.168.1.2').delete() | ||
self.assertEqual(Host.objects.filter(service_ip='192.168.1.2').count(),0) |
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