mirror of
https://github.com/retspen/webvirtcloud
synced 2024-11-01 03:54:15 +00:00
Added accounts test(moved from admin)
Actuall added admin tests
This commit is contained in:
parent
7b0016c0b2
commit
5ab22ba947
3 changed files with 118 additions and 16 deletions
|
@ -1,3 +1,28 @@
|
|||
from django.test import TestCase
|
||||
from django.contrib.auth.models import User
|
||||
from django.shortcuts import reverse
|
||||
from django.test import Client, TestCase
|
||||
|
||||
# Create your tests here.
|
||||
|
||||
class AccountsTestCase(TestCase):
|
||||
def setUp(self):
|
||||
self.client.login(username='admin', password='admin')
|
||||
User.objects.create_user(username='test', password='test')
|
||||
|
||||
def test_profile(self):
|
||||
response = self.client.get(reverse('profile'))
|
||||
self.assertEqual(response.status_code, 200)
|
||||
|
||||
response = self.client.get(reverse('account', args=[2]))
|
||||
self.assertEqual(response.status_code, 200)
|
||||
|
||||
def test_login_logout(self):
|
||||
user = User.objects.get(username='test')
|
||||
self.assertEqual(user.id, 2)
|
||||
|
||||
client = Client()
|
||||
|
||||
response = client.post(reverse('login'), {'username': 'test', 'password': 'test'})
|
||||
self.assertRedirects(response, reverse('profile'))
|
||||
|
||||
response = client.get(reverse('logout'))
|
||||
self.assertRedirects(response, reverse('login'))
|
||||
|
|
103
admin/tests.py
103
admin/tests.py
|
@ -1,30 +1,107 @@
|
|||
from django.contrib.auth.models import User
|
||||
from django.contrib.auth.models import Group, User
|
||||
from django.core.exceptions import ObjectDoesNotExist
|
||||
from django.shortcuts import reverse
|
||||
from django.test import Client, TestCase
|
||||
from django.test import TestCase
|
||||
|
||||
from .urls import urlpatterns
|
||||
from accounts.models import UserAttributes
|
||||
|
||||
|
||||
class AdminTestCase(TestCase):
|
||||
def setUp(self):
|
||||
self.client.login(username='admin', password='admin')
|
||||
User.objects.create_user(username='test', password='test')
|
||||
# User.objects.create_user(username='test', password='test')
|
||||
|
||||
def test_profile(self):
|
||||
response = self.client.get(reverse('profile'))
|
||||
# def test_user(self):
|
||||
# user = User.objects.get(username='test')
|
||||
# self.assertEqual(user.id, 2)
|
||||
|
||||
def test_group_list(self):
|
||||
response = self.client.get(reverse('admin:group_list'))
|
||||
self.assertEqual(response.status_code, 200)
|
||||
|
||||
response = self.client.get(reverse('account', args=[2]))
|
||||
def test_groups(self):
|
||||
response = self.client.post(reverse('admin:group_create'), {'name': 'Test Group'})
|
||||
self.assertRedirects(response, reverse('admin:group_list'))
|
||||
|
||||
group = Group.objects.get(name='Test Group')
|
||||
self.assertEqual(group.id, 1)
|
||||
|
||||
response = self.client.post(reverse('admin:group_update', args=[1]), {'name': 'Updated Group Test'})
|
||||
self.assertRedirects(response, reverse('admin:group_list'))
|
||||
|
||||
group = Group.objects.get(id=1)
|
||||
self.assertEqual(group.name, 'Updated Group Test')
|
||||
|
||||
response = self.client.post(reverse('admin:group_delete', args=[1]))
|
||||
self.assertRedirects(response, reverse('admin:group_list'))
|
||||
|
||||
with self.assertRaises(ObjectDoesNotExist):
|
||||
Group.objects.get(id=1)
|
||||
|
||||
def test_user_list(self):
|
||||
response = self.client.get(reverse('admin:user_list'))
|
||||
self.assertEqual(response.status_code, 200)
|
||||
|
||||
def test_login_logout(self):
|
||||
def test_users(self):
|
||||
response = self.client.post(
|
||||
reverse('admin:user_create'),
|
||||
{
|
||||
'username': 'test',
|
||||
'password': 'test',
|
||||
'max_instances': 1,
|
||||
'max_cpus': 1,
|
||||
'max_memory': 1024,
|
||||
'max_disk_size': 4,
|
||||
},
|
||||
)
|
||||
self.assertRedirects(response, reverse('admin:user_list'))
|
||||
|
||||
user = User.objects.get(username='test')
|
||||
self.assertEqual(user.id, 2)
|
||||
|
||||
client = Client()
|
||||
ua: UserAttributes = UserAttributes.objects.get(id=2)
|
||||
self.assertEqual(ua.user_id, 2)
|
||||
self.assertEqual(ua.max_instances, 1)
|
||||
self.assertEqual(ua.max_cpus, 1)
|
||||
self.assertEqual(ua.max_memory, 1024)
|
||||
self.assertEqual(ua.max_disk_size, 4)
|
||||
|
||||
response = client.post(reverse('login'), {'username': 'test', 'password': 'test'})
|
||||
self.assertRedirects(response, reverse('profile'))
|
||||
response = self.client.post(
|
||||
reverse('admin:user_update', args=[2]),
|
||||
{
|
||||
'username': 'utest',
|
||||
'max_instances': 2,
|
||||
'max_cpus': 2,
|
||||
'max_memory': 2048,
|
||||
'max_disk_size': 8,
|
||||
},
|
||||
)
|
||||
self.assertRedirects(response, reverse('admin:user_list'))
|
||||
|
||||
response = client.get(reverse('logout'))
|
||||
self.assertRedirects(response, reverse('login'))
|
||||
user = User.objects.get(id=2)
|
||||
self.assertEqual(user.username, 'utest')
|
||||
|
||||
ua: UserAttributes = UserAttributes.objects.get(id=2)
|
||||
self.assertEqual(ua.user_id, 2)
|
||||
self.assertEqual(ua.max_instances, 2)
|
||||
self.assertEqual(ua.max_cpus, 2)
|
||||
self.assertEqual(ua.max_memory, 2048)
|
||||
self.assertEqual(ua.max_disk_size, 8)
|
||||
|
||||
response = self.client.get(reverse('admin:user_block', args=[2]))
|
||||
user = User.objects.get(id=2)
|
||||
self.assertFalse(user.is_active)
|
||||
|
||||
response = self.client.get(reverse('admin:user_unblock', args=[2]))
|
||||
user = User.objects.get(id=2)
|
||||
self.assertTrue(user.is_active)
|
||||
|
||||
response = self.client.post(reverse('admin:user_delete', args=[2]))
|
||||
self.assertRedirects(response, reverse('admin:user_list'))
|
||||
|
||||
with self.assertRaises(ObjectDoesNotExist):
|
||||
User.objects.get(id=2)
|
||||
|
||||
def test_user_logs(self):
|
||||
response = self.client.get(reverse('admin:logs'))
|
||||
self.assertEqual(response.status_code, 200)
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
from django.conf import settings
|
||||
from django.contrib.auth.decorators import user_passes_test
|
||||
from django.contrib.auth.models import Group, User
|
||||
from django.core.paginator import Paginator
|
||||
from django.shortcuts import get_object_or_404, redirect, render
|
||||
|
@ -30,6 +29,7 @@ def group_create(request):
|
|||
if form.is_valid():
|
||||
form.save()
|
||||
return redirect('admin:group_list')
|
||||
|
||||
return render(
|
||||
request,
|
||||
'admin/common/form.html',
|
||||
|
|
Loading…
Reference in a new issue