def test_apply_volunteer_to_project_view(self): """ Ensure we can apply a volunteer to a project. """ a = ApplyStatus(name="Candidato", id=2) a.save() u = User(email="*****@*****.**", name="test", slug="test") u.is_email_verified = True u.save() volunteer = Volunteer(user=u) volunteer.save() project = self.create_project() factory = APIRequestFactory() request = factory.post("/apply_volunteer_to_project/", { "project": project.id, 'name': 'new name', 'phone': '3444-3434' }) force_authenticate(request, user=volunteer.user) response = views.apply_volunteer_to_project(request) self.assertEqual(response.data, {'Applied'}) self.assertEqual(response.status_code, status.HTTP_200_OK) u = User.objects.get(slug='test') self.assertEqual('new name', u.name) self.assertEqual('3444-3434', u.phone)
def test_apply_volunteer_to_project_view(self): """ Ensure we can apply a volunteer to a project. """ a = ApplyStatus(name="Candidato", id=2) a.save() u = User(email="*****@*****.**", name="test", slug="test") u.is_email_verified = True u.save() volunteer = Volunteer(user=u) volunteer.save() project = self.create_project() factory = APIRequestFactory() request = factory.post("/apply_volunteer_to_project/", {"project": project.id, 'name': 'new name', 'phone': '3444-3434'}) force_authenticate(request, user=volunteer.user) response = views.apply_volunteer_to_project(request) self.assertEqual(response.data, {'Applied'}) self.assertEqual(response.status_code, status.HTTP_200_OK) u = User.objects.get(slug='test') self.assertEqual('new name', u.name) self.assertEqual('3444-3434', u.phone) project = Project.objects.get(pk=project.id) self.assertEqual(project.applied_count, 1)
def test_apply_volunteer_to_project_view_without_auth(self): """ Apply no volunteer to a project. """ a = ApplyStatus(name="Candidato", id=2) a.save() u = User(email="*****@*****.**", name="test", slug="test") u.save() volunteer = Volunteer(user=u) volunteer.save() project = self.create_project() factory = APIRequestFactory() request = factory.post("/apply_volunteer_to_project/", {"project": project.id}) response = views.apply_volunteer_to_project(request) self.assertEqual(response.data, {"No user logged in."}) self.assertEqual(response.status_code, status.HTTP_403_FORBIDDEN)
def test_apply_volunteer_to_project_view_not_verified(self): """ Apply a volunteer not verified to a project. """ a = ApplyStatus(name="Candidato", id=2) a.save() u = User(email="*****@*****.**", name="test", slug="test") u.save() volunteer = Volunteer(user=u) volunteer.save() project = self.create_project() factory = APIRequestFactory() request = factory.post("/apply_volunteer_to_project/", {"project": project.id}) force_authenticate(request, user=volunteer.user) response = views.apply_volunteer_to_project(request) self.assertEqual(response.data, {"403": "Volunteer has not actived its account by email."}) self.assertEqual(response.status_code, status.HTTP_403_FORBIDDEN)
def test_apply_volunteer_to_project_view_not_verified(self): """ Apply a volunteer not verified to a project. """ a = ApplyStatus(name="Candidato", id=2) a.save() u = User(email="*****@*****.**", name="test", slug="test") u.save() volunteer = Volunteer(user=u) volunteer.save() project = self.create_project() factory = APIRequestFactory() request = factory.post("/apply_volunteer_to_project/", {"project": project.id}) force_authenticate(request, user=volunteer.user) response = views.apply_volunteer_to_project(request) self.assertEqual( response.data, {"403": "Volunteer has not actived its account by email."}) self.assertEqual(response.status_code, status.HTTP_403_FORBIDDEN)