def test_initial_data(self): request = self.request.get(reverse('users:update_profile')) request.user = self.user response = update_profile(request) self.assertEqual(response.status_code, HTTP_OK) self.assertContains(response, self.user.profile.state) self.assertContains(response, self.user.profile.preferred_candidate) self.assertContains(response, self.user.profile.reason_decoded) self.assertContains(response, self.user.email)
def test_email_required(self): new_state = StateFactory.create() new_reason = "Why do you need my email, anyway?" data = { 'preferred_candidate': self.user.profile.preferred_candidate, 'state': new_state.name, 'reason': new_reason, 'email': '' } request = self.request.post(reverse('users:update_profile'), data=data) request.user = self.user response = update_profile(request) self.assertEqual(response.status_code, HTTP_OK) self.assertContains(response, "error") self.assertContains(response, "This field is required")
def test_set_allow_random(self): data = { 'preferred_candidate': self.user.profile.preferred_candidate, 'state': self.user.profile.state, 'reason': self.user.profile.reason, 'email': self.user.email, 'allow_random': 'on' } request = self.request.post(reverse('users:update_profile'), data=data) request.user = self.user response = update_profile(request) self.assertEqual(response.status_code, HTTP_REDIRECT) self.assertTrue(response.has_header('Location')) self.assertEqual(response.get('Location'), reverse('users:profile')) profile = Profile.objects.get(id=self.user.profile.id) self.assertTrue(profile.allow_random)
def test_update(self): new_state = StateFactory.create() new_reason = "I want to get off of Mr. Trump's wild ride" new_email = '*****@*****.**' data = { 'preferred_candidate': self.user.profile.preferred_candidate, 'state': new_state.name, 'reason': new_reason, 'email': new_email } request = self.request.post(reverse('users:update_profile'), data=data) request.user = self.user response = update_profile(request) self.assertEqual(response.status_code, HTTP_REDIRECT) self.assertTrue(response.has_header('Location')) self.assertEqual(response.get('Location'), reverse('users:profile')) profile = Profile.objects.get(id=self.user.profile.id) self.assertEqual(profile.state, new_state.name) self.assertEqual(profile.reason_decoded, new_reason) user = User.objects.get(id=self.user.id) self.assertEqual(user.email, new_email)
def test_go_back(self): request = self.request.get(reverse('users:update_profile')) request.user = self.user response = update_profile(request) self.assertEqual(response.status_code, HTTP_OK) self.assertContains(response, "Cancel")