def test_and_retrieve_experience(self): experience = Experience() """ experience.date_start = models.DateField() experience.date_end = models.DateField() """ experience.location = "test street" experience.duties = "making coffee" experience.description = "Generic description" experience.save() experience2 = Experience() """ experience2.date_start = models.DateField() experience2.date_end = models.DateField() """ experience2.location = "test road" experience2.duties = "doing important things" experience2.description = "more unique description" experience2.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(str(first_saved_item.date_start), str(models.DateField(models.DateField.auto_now_add))) """ self.assertEqual(first_saved_item.location, 'test street') self.assertEqual(first_saved_item.duties, 'making coffee') self.assertEqual(first_saved_item.description, 'Generic description') """ self.assertEqual(str(second_saved_item.date_start), str(models.DateField(models.DateField.auto_now_add))) """ self.assertEqual(second_saved_item.location, 'test road') self.assertEqual(second_saved_item.duties, 'doing important things') self.assertEqual(second_saved_item.description, 'more unique description')
class ExperienceTestCase(TestCase): """ Common setUp needed for testing Experience class """ def setUp(self): self.experience = Experience( company="Test Corp", role="Senior Test Executor", start_date="2016-04-02" ) self.experience.save() self.experience.projects.create(name='Test Project') self.experience.responsibilities.create(name="Test Responsibility")
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_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_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")
def cv(request): if request.method == "POST": new_skill_form = KeySkillForm(request.POST) new_education_form = EducationForm(request.POST) new_experience_form = ExperienceForm(request.POST) new_volunteering_form = VolunteeringForm(request.POST) new_project_form = ProjectForm(request.POST) new_hobby_form = HobbyForm(request.POST) new_reference_form = ReferenceForm(request.POST) new_profile_form = ProfileForm(request.POST) if new_skill_form.is_valid(): new_skill = KeySkill() new_skill.text = request.POST["skills_input_text"] new_skill.save() return redirect("/cv/") elif new_education_form.is_valid(): new_education = Education() new_education.start_year = request.POST["education_input_start_year"] new_education.end_year = request.POST["education_input_end_year"] new_education.institution = request.POST["education_input_institution"] new_education.course_title = request.POST["education_input_course_title"] new_education.text = request.POST["education_input_text"] new_education.save() return redirect("/cv/") elif new_experience_form.is_valid(): new_experience = Experience() new_experience.start_year = request.POST["experience_input_start_year"] new_experience.end_year = request.POST["experience_input_end_year"] new_experience.company = request.POST["experience_input_company"] new_experience.role = request.POST["experience_input_role"] new_experience.text = request.POST["experience_input_text"] new_experience.save() return redirect("/cv/") elif new_volunteering_form.is_valid(): new_volunteering_item = Volunteering() new_volunteering_item.start_year = request.POST["volunteering_input_start_year"] new_volunteering_item.end_year = request.POST["volunteering_input_end_year"] new_volunteering_item.company = request.POST["volunteering_input_company"] new_volunteering_item.role = request.POST["volunteering_input_role"] new_volunteering_item.text = request.POST["volunteering_input_text"] new_volunteering_item.save() return redirect("/cv/") elif new_project_form.is_valid(): new_project = Project() new_project.text = request.POST["projects_input_text"] new_project.save() return redirect("/cv/") elif new_hobby_form.is_valid(): new_hobby = Hobby() new_hobby.text = request.POST["hobbies_input_text"] new_hobby.save() return redirect("/cv/") elif new_reference_form.is_valid(): new_reference = Reference() new_reference.name = request.POST["references_input_name"] new_reference.relevance = request.POST["references_input_relevance"] new_reference.phone = request.POST["references_input_phone"] new_reference.email = request.POST["references_input_email"] new_reference.save() return redirect("/cv/") elif new_profile_form.is_valid(): if Profile.objects.count() == 0: profile = Profile() profile.text = request.POST["profile_input_text"] profile.save() else: profile = Profile.objects.first() profile.text = request.POST["profile_input_text"] profile.save() return redirect("/cv/") skills = KeySkill.objects.all() skills_form = KeySkillForm() education_items = Education.objects.all().order_by("-start_year") education_form = EducationForm() experience_items = Experience.objects.all().order_by("-start_year") experience_form = ExperienceForm() volunteering_items = Volunteering.objects.all().order_by("-start_year") volunteering_form = VolunteeringForm() project_items = Project.objects.all() project_form = ProjectForm() hobby_items = Hobby.objects.all() hobby_form = HobbyForm() reference_items = Reference.objects.all() reference_form = ReferenceForm() profile_item = Profile.objects.first() profile_form = ProfileForm() return render(request, "cv.html", {"skills": skills, "skills_form": skills_form, "education_items": education_items, "education_form": education_form, "experience_items": experience_items, "experience_form": experience_form, "volunteering_items": volunteering_items, "volunteering_form": volunteering_form, "project_items": project_items, "project_form": project_form, "hobby_items": hobby_items, "hobby_form": hobby_form, "reference_items": reference_items, "reference_form": reference_form, "profile_item": profile_item, "profile_form": profile_form})