from django.contrib.admin import helpers
from django.contrib.auth import get_user_model
from django.urls import reverse
from django.forms import model_to_dict
from django.test import TestCase

import datetime

import aristotle_mdr.models as models
import aristotle_mdr.perms as perms
import aristotle_mdr.tests.utils as utils
from aristotle_mdr.utils import setup_aristotle_test_environment

setup_aristotle_test_environment()


class AdminPage(utils.LoggedInViewPages, TestCase):
    def setUp(self):
        super().setUp()

    def test_workgroup_list(self):
        new_editor = get_user_model().objects.create_user(
            '*****@*****.**', 'editor')
        new_editor.is_staff = True
        new_editor.save()

        wg_nm = models.Workgroup.objects.create(name="normal and is manager")
        wg_am = models.Workgroup.objects.create(name="archived and is manager",
                                                archived=True)
        wg_nv = models.Workgroup.objects.create(name="normal and is viewer")
        wg_av = models.Workgroup.objects.create(name="archived and is viewer",
from django.contrib.auth import get_user_model
from django.test import TestCase

import datetime

import aristotle_mdr.models as models
import aristotle_mdr.perms as perms
from aristotle_mdr.tests import utils

from aristotle_mdr.utils import setup_aristotle_test_environment


setup_aristotle_test_environment()


class SuperuserPermissions(TestCase):
    # All of the below are called with None as a Superuser, by definition *must* be able to edit, view and managed everything. Since a is_superuser chcek is cheap is should be called first, so calling with None checks that there is no other database calls going on.
    def setUp(self):
        self.su=get_user_model().objects.create_superuser('*****@*****.**','user')

    def test_user_can_alter_comment(self):
        self.assertTrue(perms.user_can_alter_comment(self.su,None))
    def test_user_can_alter_post(self):
        self.assertTrue(perms.user_can_alter_post(self.su,None))
    def test_can_view(self):
        self.assertTrue(perms.user_can_view(self.su,None))
    def test_is_editor(self):
        self.assertTrue(perms.user_is_editor(self.su))
    def test_is_registrar(self):
        self.assertTrue(perms.user_is_registrar(self.su))
        ra = models.RegistrationAuthority.objects.create(name="Test RA")