Fakultas Ilmu Komputer UI

Commit b370d5f2 authored by Endrawan Andika Wicaksana's avatar Endrawan Andika Wicaksana
Browse files

1606862740-152-Sebagai admin, saya ingin melakukan verifikasi beberapa company sekaligus

parent 936e0972
......@@ -4,7 +4,19 @@ from core.models.accounts import Company, Supervisor, Student
from core.models.feedbacks import Feedback
from core.models.vacancies import Vacancy
admin.site.register(Company)
class CompanyAdmin(admin.ModelAdmin):
list_display = ('name', 'status')
actions = ['set_as_verified', 'set_as_unverified']
def set_as_verified(self, request, queryset):
queryset.update(status=Company.VERIFIED)
set_as_verified.short_description = 'Set selected as verified'
def set_as_unverified(self, request, queryset):
queryset.update(status=Company.UNVERIFIED)
set_as_unverified.short_description = 'Set selected as unverified'
admin.site.register(Company, CompanyAdmin)
admin.site.register(Student)
admin.site.register(Supervisor)
admin.site.register(Vacancy)
......
from django.test import TestCase
from django.contrib.auth.models import User
from django.contrib.admin.sites import AdminSite
from core.models import Company
from core.admin import CompanyAdmin
class CompanyAdminTest(TestCase):
def setUp(self):
self.company_admin = CompanyAdmin(Company, AdminSite())
def test_set_as_verified_should_verified_company(self):
user = User.objects.create_user('username')
company = Company.objects.create(user=user, status=Company.NEW)
queryset = Company.objects.filter(user=user)
self.company_admin.set_as_verified(queryset=queryset, request=None)
self.assertEqual(Company.objects.get(user=user).status, Company.VERIFIED)
def test_set_as_unverified_should_unverified_company(self):
user = User.objects.create_user('username')
company = Company.objects.create(user=user, status=Company.NEW)
queryset = Company.objects.filter(user=user)
self.company_admin.set_as_unverified(queryset=queryset, request=None)
self.assertEqual(Company.objects.get(user=user).status, Company.UNVERIFIED)
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment