def test_edit_education_post_unauthenticated(self): item = Education() item.title = "Test No Auth Education 2" item.location = "Institution No Auth 2" item.start_date = "Test No Auth 02" item.end_date = "Test No Auth 20" item.brief_text = "Test No Auth 2 Brief" item.detailed_text = "Test No Auth 2 Detailed" item.save() self.assertEqual(Education.objects.count(), 1) new_item = Education.objects.first() url = "/cv/education/" + str(new_item.pk) + "/edit/" data = { 'title': "Test No Auth Education", 'location': "Institution", 'start_date': "Test date", 'end_date': "Test end", 'brief_text': "Test Brief", 'detailed_text': "Test Detailed", } response = self.client.post(url, data) self.assertEqual(Education.objects.count(), 1) self.assertNotEqual(response['location'], "/cv/") self.assertEqual(response['location'], "/accounts/login/?next=" + url) unedited_item = Education.objects.first() self.assertEqual(unedited_item.title, "Test No Auth Education 2") self.assertEqual(unedited_item.location, "Institution No Auth 2") self.assertEqual(unedited_item.detailed_text, "Test No Auth 2 Detailed")
class EducationTestCase(TestCase): """ Common stuff needed for testing education class """ def setUp(self): self.education = Education( institution="Test University", start_date="2006-08-01", end_date="2009-06-01" ) self.education.save() self.education.courses.create(name="BA (Hons) Testing", mark="First") self.education.projects.create(name="Test Driven Development")
def test_edit_education_form_unauthenticated(self): item = Education() item.title = "Test No Auth Education 1" item.location = "Institution No Auth 1" item.start_date = "Test No Auth 01" item.end_date = "Test No Auth 10" item.brief_text = "Test No Auth 1 Brief" item.detailed_text = "Test No Auth 1 Detailed" item.save() self.assertEqual(Education.objects.count(), 1) new_item = Education.objects.first() url = "/cv/education/" + str(new_item.pk) + "/edit/" response = self.client.get(url) self.assertEqual(Education.objects.count(), 1) self.assertNotEqual(response['location'], url) self.assertEqual(response['location'], "/accounts/login/?next=" + url)
def test_can_you_get_to_edit_education_after_created_one(self): first_school = Education() first_school.name = 'Testing School' first_school.description = 'I have studied in the Testing School where I had tests' first_school.begin_date = '2013' first_school.end_date = '2018' first_school.save() response = self.client.get('/cv/education/edit/1/') self.assertTemplateUsed(response, 'cv/education_edit.html')
def setUp(self): self.education = Education( institution="Test University", start_date="2006-08-01", end_date="2009-06-01" ) self.education.save() self.education.courses.create(name="BA (Hons) Testing", mark="First") self.education.projects.create(name="Test Driven Development")
def test_edit_buttons_education_auth(self): item = Education() item.title = "Test No Auth Education 1 EDIT" item.location = "Placeholder" item.start_date = "Placeholder" item.end_date = "Placeholder" item.brief_text = "Placeholder" item.detailed_text = "Placeholder" item.save() self.assertEqual(Education.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 education(p, off, language="IS"): ##education off -= marginRatio * yp p.setFont(*giantFont) third = (100.00 / 3.00) * xp p.drawString(third + xp * marginRatio, off, Education.FieldName(language)) degrees = Education.objects.filter(language=language).order_by("-end") off -= marginRatio * yp for degree in degrees: p.setFont(*largeFont) p.drawString(third + 2 * xp * marginRatio, off, degree.degree) p.drawRightString(100 * xp - xp * marginRatio, off, degree.start + "-" + degree.end) off -= marginRatio * yp p.setFont(*midFont) p.drawString(third + 2 * xp * marginRatio, off, degree.school) off -= marginRatio * yp return off
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})
def test_saving_educations(self): #Create the first institution first_school = Education() first_school.name = 'Testing School' first_school.description = 'I have studied in the Testing School where I had tests' first_school.begin_date = '2013' first_school.end_date = '2018' first_school.save() #Create the second institution second_school = Education() second_school.name = 'Examing School' second_school.description = 'I have studied in the Examing School' second_school.begin_date = '2018' second_school.end_date = 'Present' second_school.save() #Check if all the objects are in the database saved_schools = Education.objects.all() self.assertEqual(saved_schools.count(), 2) first_saved_school = saved_schools[0] second_saved_school = saved_schools[1] #Check if the first school matches the description self.assertEqual(first_saved_school.name, 'Testing School') self.assertEqual(first_saved_school.description, 'I have studied in the Testing School where I had tests') self.assertEqual(first_saved_school.begin_date, '2013') self.assertEqual(first_saved_school.end_date, '2018') #Check if the second school matches the description self.assertEqual(second_saved_school.name, 'Examing School') self.assertEqual(second_saved_school.description, 'I have studied in the Examing School') self.assertEqual(second_saved_school.begin_date, '2018') self.assertEqual(second_saved_school.end_date, 'Present')
def test_saving_and_retrieving_education(self): first_item = Education() first_item.title = "Test Education 1" first_item.location = "Institution 1" first_item.start_date = "Test 01" first_item.end_date = "Test 10" first_item.brief_text = "Test 1 Brief" first_item.detailed_text = "Test 1 Detailed" first_item.save() second_item = Education() second_item.title = "Test Education 2" second_item.location = "Institution 2" second_item.start_date = "Test 02" second_item.end_date = "Test 20" second_item.brief_text = "Test 2 Brief" second_item.detailed_text = "Test 2 Detailed" second_item.save() saved_items = Education.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 Education 1') self.assertEqual(second_saved_item.title, 'Test Education 2')
def test_saving_and_retrieving_data(self): hk_tz = pytz.timezone("Asia/Hong_Kong") uni = Education() uni.program_title = 'computer science' uni.organization = 'uob' uni.program_desc = 'study computer related stuff' uni.start_date = hk_tz.localize(datetime(2019, 9, 30)) uni.finish_date = hk_tz.localize(datetime(2020, 7, 30)) uni.save() secondary_school = Education() secondary_school.program_title = 'HKDSE' secondary_school.organization = 'pooitun' secondary_school.program_desc = 'study different foundation subjects' secondary_school.start_date = hk_tz.localize(datetime(2011, 9, 30)) secondary_school.finish_date = hk_tz.localize(datetime(2017, 7, 30)) secondary_school.save() saved_education = Education.objects.all() self.assertEqual(saved_education.count(), 2) first_saved_education = saved_education[0] second_saved_education = saved_education[1] self.assertEqual(first_saved_education.organization, 'uob') self.assertEqual(second_saved_education.organization, 'pooitun') python = Skill() python.skill_title = 'python' python.skill_area = 'programming' python.save() sql = Skill() sql.skill_title = 'sql' sql.skill_area = 'database mangement' sql.save() saved_skill = Skill.objects.all() self.assertEqual(saved_skill.count(), 2) first_saved_skill = saved_skill[0] second_saved_skill = saved_skill[1] self.assertEqual(first_saved_skill.skill_title, 'python') self.assertEqual(second_saved_skill.skill_title, 'sql') qbs = WorkExperience() qbs.job_title = 'DataScienceIntern' qbs.company = 'qbs' qbs.job_desc = 'car plate regconition project' qbs.start_date = hk_tz.localize(datetime(2018, 8, 1)) qbs.finish_date = hk_tz.localize(datetime(2018, 8, 30)) qbs.save() saved_job = WorkExperience.objects.all() self.assertEqual(saved_job.count(), 1) first_saved_job = saved_job[0] self.assertEqual(first_saved_job.company, 'qbs') ashf = Achievement() ashf.achievement_title = 'ashf' ashf.achievement_desc = 'scholar' ashf.achieve_date = hk_tz.localize(datetime(2019, 5, 17)) ashf.save() saved_achievement = Achievement.objects.all() self.assertEqual(saved_achievement.count(), 1) first_saved_achievement = saved_achievement[0] self.assertEqual(first_saved_achievement.achievement_title, 'ashf') self.assertEqual(first_saved_achievement.achievement_desc, 'scholar') self.assertEqual(first_saved_achievement.achieve_date, hk_tz.localize(datetime(2019, 5, 17)))
def __init__(self, *args, **kwargs): super(EducationForm, self).__init__(*args, **kwargs) # If the form.instance.pk it's None means that the form came from CreateView, so generate the Max value Order if self.instance.pk is None: self.initial['order'] = Education.GetOrderMaxValue(Education)