def test_saving_and_retrieving_experience(self): first_item = Experience() first_item.title = "Test Experience 1" first_item.subtitle = "Experience 1 Type" first_item.date = "Test 01" first_item.text = "Test 1 Detailed" first_item.save() second_item = Experience() second_item.title = "Test Experience 2" second_item.subtitle = "Experience 2 Type" second_item.date = "Test 02" second_item.text = "Test 2 Detailed" second_item.save() saved_items = Experience.objects.all() self.assertEqual(saved_items.count(), 2) first_saved_item = saved_items[0] second_saved_item = saved_items[1] self.assertEqual(first_saved_item.title, 'Test Experience 1') self.assertEqual(second_saved_item.title, 'Test Experience 2')
def test_delete_experience_unauthenticated(self): item = Experience() item.title = "Test No Auth Experience 3" item.subtitle = "Experience No Auth 3 Type" item.date = "Test No Auth 03" item.text = "Test No Auth 3 Detailed" item.save() self.assertEqual(Experience.objects.count(), 1) new_item = Experience.objects.first() url = "/cv/experience/" + str(new_item.pk) + "/remove/" response = self.client.get(url) self.assertEqual(Experience.objects.count(), 1) self.assertNotEqual(response['location'], "/cv/") self.assertEqual(response['location'], "/accounts/login/?next=" + url)
def test_edit_buttons_experience_auth(self): item = Experience() item.title = "Test No Auth Experience 1 EDIT" item.subtitle = "Placeholder" item.date = "Placeholder" item.text = "Placeholder" item.save() self.assertEqual(Experience.objects.count(), 1) response = self.client.get('/cv/') html = response.content.decode('utf8') self.assertNotIn('class="btn btn-outline-dark edit_btn"', html) self.assertNotIn('class="btn btn-outline-dark delete_btn"', html) self.client.login(username='******', password='******') response = self.client.get('/cv/') html = response.content.decode('utf8') self.assertIn('class="btn btn-outline-dark edit_btn"', html) self.assertIn('class="btn btn-outline-dark delete_btn"', html) self.client.logout()
def test_edit_experience_post_unauthenticated(self): item = Experience() item.title = "Test No Auth Experience 2" item.subtitle = "Experience No Auth 2 Type" item.date = "Test No Auth 02" item.text = "Test No Auth 2 Detailed" item.save() self.assertEqual(Experience.objects.count(), 1) new_item = Experience.objects.first() url = "/cv/experience/" + str(new_item.pk) + "/edit/" data = { 'title': "Test No Auth Experience", 'subtitle': "Experience Type", 'date': "Test date", 'text': "Test Detailed", } response = self.client.post(url, data) self.assertEqual(Experience.objects.count(), 1) self.assertNotEqual(response['location'], "/cv/") self.assertEqual(response['location'], "/accounts/login/?next=" + url) unedited_item = Experience.objects.first() self.assertEqual(unedited_item.title, "Test No Auth Experience 2") self.assertEqual(unedited_item.subtitle, "Experience No Auth 2 Type") self.assertEqual(unedited_item.text, "Test No Auth 2 Detailed")