Exemplo n.º 1
0
 def test_edit_project_view_with_only_required_fields_job(self):
     """
 Project edit job with only required fields and no availabilites.
 """
     factory = APIRequestFactory()
     project = {
         'name': "Name",
         'details': 'This needs to be big',
         'description': 'This needs to be big',
         'responsible': 'Marjori',
         'phone': '123123',
         'email': '*****@*****.**',
         'skills': [1],
         'causes': [2],
         'job': {
             'start_date': 20140416,
             'end_date': 20140417
         },
         'nonprofit': 1
     }
     n = self.create_nonprofit()
     p = Project(nonprofit=n,
                 name=project['name'],
                 slug="name",
                 details=project['details'])
     p.save()
     project['id'] = p.id
     request = factory.put("/save/project/", {'project': project})
     force_authenticate(request, user=n.user)
     response = views.save_project(request)
     self.assertEqual(response.status_code, status.HTTP_201_CREATED)
Exemplo n.º 2
0
 def test_edit_projec_view_with_changing_roles(self):
     """
 Project edit with deleting and adding new roles.
 """
     project = {
         'name': "Name",
         'details': 'This needs to be big',
         'description': 'This needs to be big',
         'responsible': 'Marjori',
         'phone': '123123',
         'email': '*****@*****.**',
         'skills': [1],
         'causes': [2],
         'job': {
             'start_date': 20140416,
             'end_date': 20140417
         },
         'nonprofit': 1
     }
     factory = APIRequestFactory()
     n = self.create_nonprofit()
     r = Role(name="role name")
     r.save()
     p = Project(nonprofit=n, name='name', slug="name")
     p.save()
     p.roles.add(r)
     project['id'] = p.id
     request = factory.put("/save/project/", {'project': project})
     force_authenticate(request, user=n.user)
     response = views.save_project(request)
     newP = Project.objects.get(id=p.id)
     self.assertEqual(newP.roles.count(), 0)
     self.assertEquals(response.status_code, status.HTTP_201_CREATED)
Exemplo n.º 3
0
 def test_edit_projec_view_with_changing_roles(self):
   """
   Project edit with deleting and adding new roles.
   """
   project = {
     'name': "Name",
     'details': 'This needs to be big',
     'description': 'This needs to be big',
     'responsible': 'Marjori',
     'phone': '123123',
     'email': '*****@*****.**',
     'skills': [1],
     'causes': [2],
     'job': {
       'start_date': 20140416,
       'end_date': 20140417
     },
     'nonprofit': 1
   }
   factory = APIRequestFactory()
   n = self.create_nonprofit()
   r = Role(name="role name")
   r.save()
   p = Project(nonprofit=n, name='name', slug="name")
   p.save()
   p.roles.add(r)
   project['id'] = p.id
   request = factory.put("/save/project/", {'project': project})
   force_authenticate(request, user=n.user)
   response = views.save_project(request)
   newP = Project.objects.get(id=p.id)
   self.assertEqual(newP.roles.count(), 0)
   self.assertEquals(response.status_code, status.HTTP_201_CREATED)
Exemplo n.º 4
0
 def test_edit_project_view_with_only_required_fields_job(self):
   """
   Project edit job with only required fields and no availabilites.
   """
   factory = APIRequestFactory()
   project = {
     'name': "Name",
     'details': 'This needs to be big',
     'description': 'This needs to be big',
     'responsible': 'Marjori',
     'phone': '123123',
     'email': '*****@*****.**',
     'skills': [1],
     'causes': [2],
     'job': {
       'start_date': 20140416,
       'end_date': 20140417
     },
     'nonprofit': 1
   }
   n = self.create_nonprofit()
   p = Project(nonprofit=n, name=project['name'], slug="name", details=project['details'])
   p.save()
   project['id'] = p.id
   request = factory.put("/save/project/", {'project': project})
   force_authenticate(request, user=n.user)
   response = views.save_project(request)
   self.assertEqual(response.status_code, status.HTTP_201_CREATED)
Exemplo n.º 5
0
 def test_edit_project_view_with_changing_roles_one_stays(self):
   """
   Project edit with deleting 1 role but keeping another.
   """
   project = {
     'name': "Name",
     'details': 'This needs to be big',
     'description': 'This needs to be big',
     'responsible': 'Marjori',
     'phone': '123123',
     'email': '*****@*****.**',
     'skills': [{'id': 1}],
     'causes': [{'id': 1}],
     'job': {
       'start_date': 20140416,
       'end_date': 20140417,
       'can_be_done_remotely': True,
     },
     'nonprofit': 1
   }
   factory = APIRequestFactory()
   n = self.create_nonprofit()
   r = Role(name="role name")
   r.save()
   r1 = Role(name="role name 1")
   r1.save()
   p = Project(nonprofit=n, name='name', slug="name")
   p.save()
   p.roles.add(r)
   p.roles.add(r1)
   project['id'] = p.id
   project['roles'] = [{'id': r.id}]
   request = factory.put("/save/project/", {'project': json.dumps(project)})
   force_authenticate(request, user=n.user)
   with transaction.atomic():
     response = views.save_project(request)
   newP = Project.objects.get(id=p.id)
   #self.assertEqual(newP.roles.count(), 1)
   self.assertEquals(response.status_code, status.HTTP_201_CREATED)