-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
unittest: account controller - view_test (manage, add, remove)
- Loading branch information
janik
committed
Aug 14, 2024
1 parent
64f7b21
commit 2839412
Showing
4 changed files
with
74 additions
and
4 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
from django.test import TestCase, Client | ||
from django.urls import reverse | ||
from account_controller.models import AdminAccount | ||
|
||
|
||
class AccountTestViews(TestCase): | ||
|
||
def setUp(self): | ||
|
||
self.client = Client() | ||
|
||
self.account_url = reverse('account') | ||
self.add_url = reverse('add') | ||
self.delete_url = reverse('delete') | ||
|
||
self.account1 = AdminAccount.objects.create(identifier='admin1') | ||
def test_manage_accounts_GET(self): | ||
|
||
response = self.client.get(reverse(self.account_url)) | ||
|
||
self.assertEquals(response.status_code, 200) | ||
self.assertTemplateUsed(response, 'account.html') | ||
|
||
def test_add_accounts_POST_add_new_admin(self): | ||
|
||
initial_count = AdminAccount.objects.count() | ||
|
||
response = self.client.post(self.add_url, { | ||
'identifier': self.account1.identifier}) | ||
|
||
new_count = AdminAccount.objects.count() | ||
|
||
self.assertEquals(response.status_code, 302) | ||
self.assertEquals(new_count, initial_count + 1) | ||
|
||
def test_add_accounts_POST_no_data(self): | ||
|
||
initial_count = AdminAccount.objects.count() | ||
|
||
response = self.client.post(self.add_url) | ||
|
||
new_count = AdminAccount.objects.count() | ||
|
||
self.assertEquals(response.status_code, 302) | ||
self.assertEquals(new_count, initial_count) | ||
|
||
def test_remove_accounts_POST_remove_account(self): | ||
|
||
initial_count = AdminAccount.objects.count() | ||
|
||
response = self.client.post(self.delete_url, { | ||
'identifier': self.account1.identifier}) | ||
|
||
new_count = AdminAccount.objects.count() | ||
|
||
self.assertEquals(response.status_code, 302) | ||
self.assertEquals(new_count, initial_count - 1) | ||
|
||
def test_remove_accounts_POST_no_data(self): | ||
|
||
initial_count = AdminAccount.objects.count() | ||
|
||
response = self.client.post(self.delete_url) | ||
|
||
new_count = AdminAccount.objects.count() | ||
|
||
self.assertEquals(response.status_code, 302) | ||
self.assertEquals(new_count, initial_count) | ||
|
||
|
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