Esempio n. 1
0
 def test_apply_volunteer_to_project_view_after_canceled(self):
     """
 Apply again after canceled.
 """
     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})
     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)
     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, {'Canceled'})
     self.assertEqual(response.status_code, status.HTTP_200_OK)
     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, {'Applied'})
     self.assertEqual(response.status_code, status.HTTP_200_OK)
Esempio n. 2
0
 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)
Esempio n. 3
0
 def test_apply_creation(self):
     """
 Tests Apply.
 """
     u = User(name="Voluntario", slug="voluntario")
     u.save()
     v = Volunteer(user=u)
     v.save()
     p = Project(name="Project")
     a = Apply(status=ApplyStatus(), volunteer=v, project=p)
     self.assertTrue(isinstance(a, Apply))
     self.assertEqual(a.__unicode__(), "[False] Voluntario - Project")
Esempio n. 4
0
 def test_apply_volunteer_to_project_view_without_project(self):
     """
 Apply volunteer to project without project id.
 """
     u = User(email="*****@*****.**", name="test", slug="test")
     u.is_email_verified = True
     u.save()
     volunteer = Volunteer(user=u)
     volunteer.save()
     factory = APIRequestFactory()
     request = factory.post("/apply_volunteer_to_project/", {"project": ''})
     force_authenticate(request, user=volunteer.user)
     response = views.apply_volunteer_to_project(request)
     self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)
Esempio n. 5
0
 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)
Esempio n. 6
0
 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)