from django.test import TestCase, Client
from django.contrib.auth import get_user_model
from django.urls import reverse


class AdminTestCase(TestCase):
    def setUp(self):
        self.client = Client()
        self.admin_user = get_user_model().objects \
            .create_superuser(
                email="admin@email.com",
                password="password")
        self.client.force_login(self.admin_user)
        self.user = get_user_model().objects.create_user(
            email = "test@email.com",
            password = "p@ssword")

    def test_listed_users(self):
        """ Test that users are listed on the user page"""
        url = reverse('admin:core_user_changelist')
        res = self.client.get(url)
        self.assertContains(res,self.user.email)

    def test_user_change_page(self):
        """Test that the single edit page works"""
        url = reverse('admin:core_user_change', args=[self.user.id])
        res = self.client.get(url)
        self.assertEqual(res.status_code,200)

    def test_create_user_page(self):
        """Test that the create user page worked"""
        url = reverse('admin:core_user_add')
        res = self.client.get(url)
        self.assertEqual(res.status_code, 200)