from django.urls import resolve, reverse
from django.test import TestCase
from .views import signup
from django.contrib.auth.forms import UserCreationForm


class SignUpTests(TestCase):
	def setUp(self):
		url = reverse('signup')
		self.response = self.client.get(url)

	# test the response code of the url
	def test_signup_status_code(self):
		self.assertEquals(self.response.status_code,200) 

	# Test the url /signup/ to see if it returns the correct view function
	def test_signup_url_resolves_signup_view(self):
		view =  resolve('/signup/')
		self.assertEquals(view.func, signup)

	def test_csrf(self):
		self.assertContains(self.response, 'csrfmiddlewaretoken')

	def test_contains_form(self):
		form = self.response.context.get('form')
		self.assertIsInstance(form, UserCreationForm)
		

