Example #1
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)
Example #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)

    project = Project.objects.get(pk=project.id)
    self.assertEqual(project.applied_count, 1)
Example #3
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)
Example #4
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)
Example #5
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)
Example #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)
Example #7
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")