예제 #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)
예제 #2
0
파일: test_core.py 프로젝트: atados/api
  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)
예제 #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)
예제 #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)
예제 #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)
예제 #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)