def test_get_jobs_many(self): JobFactory.create() # TODO could automatically create n JobFactory.create(title="Trail builder") client = APIClient() response = client.get('%s/jobs' % (self.base_url), format='json', secure=True) r = json.loads(response.content) self.assertEqual(r['count'], 2) self.assertEqual(response.status_code, 200)
def test_get_results_many_location_only(self): JobFactory() JobFactory(title="Butterfly catcher", url="http://www.example.com/") response = self.client.get('/results/wellington/nature', secure=True) self.assertEqual(response.context[0]['job_count'], 2) self.assertEqual(response.context[0]['matched_intersection'], 0) self.assertEqual(response.context[0]['matched_interests_count'], 0) self.assertEqual(response.context[0]['location_matches'], 2) self.assertEqual(response.status_code, 200)
def test_get_results_many_complete_match(self): label = LabelsFactory(name="nature") job_one = JobFactory() job_one.labels.add(label.id) job_two = JobFactory(title="Butterfly catcher", url="http://www.example.com/") job_two.labels.add(label.id) response = self.client.get('/results/wellington/nature', secure=True) self.assertEqual(response.context[0]['job_count'], 2) self.assertEqual(response.context[0]['matched_intersection'], 2) self.assertEqual(response.context[0]['matched_interests_count'], 1) self.assertEqual(response.context[0]['location_matches'], 2) self.assertEqual(response.status_code, 200)
def test_get_results_many_label_only(self): label = LabelsFactory(name="nature") job_one = JobFactory(city="Dunedin") job_one.labels.add(label.id) job_two = JobFactory(title="Butterfly catcher", city="Amsterdam") job_two.labels.add(label.id) response = self.client.get('/results/wellington/nature', secure=True) self.assertEqual(response.context[0]['job_count'], 2) self.assertEqual(response.context[0]['matched_intersection'], 0) self.assertEqual(response.context[0]['matched_interests_count'], 1) self.assertEqual(response.context[0]['location_matches'], 0) self.assertEqual(response.status_code, 200)
def test_update_jobs_requires_authentications(self): job = JobFactory.create() client = APIClient() data = self.job_json response = client.put('%s/jobs/%s' % (self.base_url, job.id), data=data, format='json', secure=True) self.assertEqual(response.status_code, 401)
def test_get_jobs_one(self): job = JobFactory.create() client = APIClient() response = client.get('%s/jobs/%s' % (self.base_url, job.id), format='json', secure=True) r = json.loads(response.content) self.assertEqual(r['title'], job.title) self.assertEqual(response.status_code, 200)
def test_delete_jobs(self): job = JobFactory.create() client = APIClient() client.credentials(HTTP_AUTHORIZATION='Token ' + self.token.key) length = Job.objects.count() response = client.delete('%s/jobs/%s' % (self.base_url, job.id), format='json', secure=True) length -= 1 self.assertEqual(Job.objects.count(), length) self.assertEqual(response.status_code, 204)
def test_get_results_one_location_only(self): label = LabelsFactory() job = JobFactory() job.labels.add(label.id) response = self.client.get('/results/wellington/Nature', secure=True) self.assertEqual(response.context[0]['job_count'], 1) self.assertEqual(response.context[0]['matched_intersection'], 0) self.assertEqual(response.context[0]['matched_interests_count'], 0) self.assertEqual(response.context[0]['location_matches'], 1) self.assertEqual(response.status_code, 200)
def test_update_jobs(self): site = SiteFactory() label = LabelsFactory() job = JobFactory.create() client = APIClient() client.credentials(HTTP_AUTHORIZATION='Token ' + self.token.key) data = self.job_json # TODO: currently fails because json referes to org id that is not there data["title"] = "Clown" data["organisation_id"] = job.organisation_id data["sites"] = [site.id] data["labels"] = [label.id] response = client.put('%s/jobs/%s' % (self.base_url, job.id), data=data, format='json', secure=True) r = json.loads(response.content) self.assertEqual(r['title'], "Clown") self.assertEqual(response.status_code, 200)
def test_job_creation(self): j = JobFactory() self.assertTrue(isinstance(j, Job)) self.assertEqual(j.__str__(), j.title)