def test_delete_interest_unauthenticated(self): item = Interest() item.title = "Test No Auth Interest 3" item.save() self.assertEqual(Interest.objects.count(), 1) new_item = Interest.objects.first() url = "/cv/interest/" + str(new_item.pk) + "/remove/" response = self.client.get(url) self.assertEqual(Interest.objects.count(), 1) self.assertNotEqual(response['location'], "/cv/") self.assertEqual(response['location'], "/accounts/login/?next=" + url)
def test_edit_buttons_interest_auth(self): item = Interest() item.title = "Test No Auth Interest EDIT 1" item.save() self.assertEqual(Interest.objects.count(), 1) response = self.client.get('/cv/') html = response.content.decode('utf8') self.assertNotIn('class="fa icon-switch fa-pencil edit_btn"', html) self.assertNotIn('class="fa icon-switch fa-trash delete_btn"', html) self.client.login(username='******', password='******') response = self.client.get('/cv/') html = response.content.decode('utf8') self.assertIn('class="fa icon-switch fa-pencil edit_btn"', html) self.assertIn('class="fa icon-switch fa-trash delete_btn"', html) self.client.logout()
def test_edit_interest_post_unauthenticated(self): item = Interest() item.title = "Test No Auth Interest 2" item.save() self.assertEqual(Interest.objects.count(), 1) new_item = Interest.objects.first() url = "/cv/interest/" + str(new_item.pk) + "/edit/" data = { 'title': "Test No Auth Interest 20", } response = self.client.post(url, data) self.assertEqual(Interest.objects.count(), 1) self.assertNotEqual(response['location'], "/cv/") self.assertEqual(response['location'], "/accounts/login/?next=" + url) unedited_item = Interest.objects.first() self.assertEqual(unedited_item.title, "Test No Auth Interest 2")
def test_saving_and_retrieving_interest(self): first_item = Interest() first_item.title = "Test Interest 1" first_item.save() second_item = Interest() second_item.title = "Test Interest 2" second_item.save() saved_items = Interest.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 Interest 1') self.assertEqual(second_saved_item.title, 'Test Interest 2')
def test_saving_interest(self): first_interest = Interest() first_interest.interest = 'Testing' first_interest.save() second_interest = Interest() second_interest.interest = 'Second testing' second_interest.save() saved_interests = Interest.objects.all() self.assertEqual(2, saved_interests.count()) first_saved_interest = saved_interests[0] second_saved_interest = saved_interests[1] self.assertEqual(first_saved_interest.interest, 'Testing') self.assertEqual(second_saved_interest.interest, 'Second testing')
def interests(p, offset, language="IS"): offset -= yp p.setFillColorRGB(*black) p.setFont(*giantFont) middle = xp * marginRatio + third p.drawString(middle, offset, Interest.FieldName(language)) offset -= marginRatio * yp interests = Interest.objects.filter(language=language).order_by("interest") intTest = "" for interest in interests: intTest += interest.interest + ", " intTest = intTest[:-2] + (", og fleira" if language == "IS" else ", and more") p.setFont(*smallFont) drawStringExt(p, middle + 2 * xp, offset, intTest, third * 2 - 2 * xp * marginRatio, standard_line_seperation)
def test_can_you_get_to_edit_interest_after_created_one(self): first_interest = Interest() first_interest.interest = 'Testing' first_interest.save() response = self.client.get('/cv/interests/edit/1/') self.assertTemplateUsed(response, 'cv/interest_edit.html')