Exemple #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)
Exemple #2
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)
Exemple #3
0
  def test_apply_volunteer_to_project_view_already_apply(self):
    """
    Unaply when apply already exists.
    """
    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)
    project = Project.objects.get(pk=project.id)
    nonprofit = Nonprofit.objects.get(user__slug="hahah")
    self.assertEqual(response.data, {'Applied'})
    self.assertEqual(response.status_code, status.HTTP_200_OK)
    self.assertEqual(project.applied_count, 1)

    # We only test if volunteer count increases, we don't test if it lowers
    # when unapplying because Nonprofit.get_volunteers and N.get_volunteers_numbers
    # doesn't filter applies by cancelled
    self.assertEqual(nonprofit.volunteer_count, 1)

    request = factory.post("/apply_volunteer_to_project/", {"project": project.id})
    force_authenticate(request, user=volunteer.user)
    response = views.apply_volunteer_to_project(request)
    project = Project.objects.get(pk=project.id)
    self.assertEqual(response.data, {'Canceled'})
    self.assertEqual(response.status_code, status.HTTP_200_OK)
    self.assertEqual(project.applied_count, 0)
Exemple #4
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)
Exemple #5
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)
Exemple #6
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)
Exemple #7
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)
Exemple #8
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)
Exemple #9
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)
Exemple #10
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)
Exemple #11
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)