Exemplo n.º 1
0
 def test_get_organisation_many(self):
     OrganisationFactory()  # TODO: refactor to create n orgs
     OrganisationFactory(name="Another Organisation")
     client = APIClient()
     response = client.get('%s/organisations' % self.base_url, format='json', secure=True)
     r = json.loads(response.content)
     self.assertEqual(r['count'], 2)
     self.assertEqual(response.status_code, 200)
Exemplo n.º 2
0
 def test_delete_organisation_requires_authentications(self):
     organisation = OrganisationFactory()
     client = APIClient()
     response = client.delete(
         '%s/organisations/%s' % (self.base_url, organisation.id),
         format='json', secure=True)
     self.assertEqual(response.status_code, 401)
Exemplo n.º 3
0
 def test_delete_organisation(self):
     organisation = OrganisationFactory()
     client = APIClient()
     client.credentials(HTTP_AUTHORIZATION='Token ' + self.token.key)
     response = client.delete(
         '%s/organisations/%s' % (self.base_url, organisation.id),
         format='json', secure=True)
     self.assertEqual(Site.objects.count(), 0)
     self.assertEqual(response.status_code, 204)
Exemplo n.º 4
0
 def test_get_organisation_one(self):
     organisation = OrganisationFactory()
     client = APIClient()
     response = client.get(
         '%s/organisations/%s' % (self.base_url, organisation.id),
         format='json', secure=True)
     r = json.loads(response.content)
     self.assertEqual(r['name'], organisation.name)
     self.assertEqual(response.status_code, 200)
Exemplo n.º 5
0
 def test_update_organisation(self):
     organisation = OrganisationFactory()
     client = APIClient()
     client.credentials(HTTP_AUTHORIZATION='Token ' + self.token.key)
     data = self.organisation_json
     data["name"] = "The body snatchers"
     response = client.put(
         '%s/organisations/%s' % (self.base_url, organisation.id), data=data,
         format='json', secure=True)
     r = json.loads(response.content)
     self.assertEqual(r['name'], "The body snatchers")
     self.assertEqual(response.status_code, 200)
Exemplo n.º 6
0
    def test_create_job_auth(self):
        label = LabelsFactory()
        organisation = OrganisationFactory()
        site = SiteFactory()

        data = self.job_json
        data['labels'] = [label.id]
        data['sites'] = [site.id]
        data['organisation_id'] = organisation.id

        client = APIClient()
        client.credentials(HTTP_AUTHORIZATION='Token ' + self.token.key)

        response = client.post('%s/jobs' % self.base_url, data=data, format='json', secure=True)
        r = json.loads(response.content)
        self.assertEqual(r['title'], "Eternal Gardener")
        self.assertEqual(r['text'], "for the nature lover")
        self.assertEqual(r['sites'], data['sites'])
        self.assertEqual(r['labels'], data['labels'])
        self.assertEqual(response.status_code, 201)
Exemplo n.º 7
0
 def test_organisation_creation(self):
     o = OrganisationFactory()
     self.assertTrue(isinstance(o, Organisation))
     self.assertEqual(o.__str__(), o.name)