def test_get_bids_no_bids(self): bob = JobPoster.objects.get(name="Bob") posting = new_job_posting() post.create_job_posting(bob, posting) self.assertEquals(0, len(post.get_bids(bob, posting.pk)))
def test_delete_job_posting_wrong_owner(self): bob = JobPoster.objects.get(name="Bob") frank = JobPoster.objects.get(name="Frank") posting = new_job_posting() post.create_job_posting(bob, posting) with self.assertRaises(PermissionDenied): post.delete_job_posting(frank, posting.pk)
def test_delete_job_posting(self): bob = JobPoster.objects.get(name="Bob") posting = new_job_posting() post.create_job_posting(bob, posting) post.delete_job_posting(bob, posting.pk) self.assertEquals(0, len(bob.jobposting_set.all()))
def test_update_job_posting(self): bob = JobPoster.objects.get(name="Bob") posting = new_job_posting(description="old description") post.create_job_posting(bob, posting) posting.description = "new_description" post.update_job_posting(bob, posting) self.assertEquals("new_description", bob.jobposting_set.get().description)
def test_rate_contractor_job_not_completed(self): bob = JobPoster.objects.get(name="Bob") emily = Contractor.objects.get(name="Emily") posting = new_job_posting(contractor=emily) post.create_job_posting(bob, posting) with self.assertRaises(PermissionDenied): post.rate_contractor(bob, emily, 5) self.assertEquals(0, len(emily.contractorrating_set.all()))
def test_rate_contractor(self): bob = JobPoster.objects.get(name="Bob") emily = Contractor.objects.get(name="Emily") posting = new_job_posting(contractor=emily, completed=True, completion_date=now()) post.create_job_posting(bob, posting) post.rate_contractor(bob, emily, 5) self.assertEquals(5, emily.contractorrating_set.get(poster=bob).rating)
def test_update_job_posting_wrong_owner(self): bob = JobPoster.objects.get(name="Bob") frank = JobPoster.objects.get(name="Frank") posting = new_job_posting(description="old_description") post.create_job_posting(bob, posting) posting.description = "new_description" with self.assertRaises(PermissionDenied): post.update_job_posting(frank, posting) self.assertEquals("old_description", bob.jobposting_set.get().description)
def test_accept_bid_wrong_owner(self): bob = JobPoster.objects.get(name="Bob") frank = JobPoster.objects.get(name="Frank") emily = Contractor.objects.get(name="Emily") posting = new_job_posting() post.create_job_posting(bob, posting) bid = Bid(contractor=emily, job=posting) bid.save() with self.assertRaises(PermissionDenied): post.accept_bid(frank, bid.pk) self.assertEquals(bob.jobposting_set.get().contractor, None)
def test_get_bids_wrong_owner(self): bob = JobPoster.objects.get(name="Bob") frank = JobPoster.objects.get(name="Frank") emily = Contractor.objects.get(name="Emily") joseph = Contractor.objects.get(name="Joseph") posting = new_job_posting() post.create_job_posting(bob, posting) bid1 = Bid(contractor=emily, job=posting) bid2 = Bid(contractor=joseph, job=posting) bid1.save() bid2.save() with self.assertRaises(PermissionDenied): post.get_bids(frank, posting.pk)
def test_accept_bid(self): bob = JobPoster.objects.get(name="Bob") emily = Contractor.objects.get(name="Emily") joseph = Contractor.objects.get(name="Joseph") posting = new_job_posting() post.create_job_posting(bob, posting) bid1 = Bid(contractor=emily, job=posting) bid2 = Bid(contractor=joseph, job=posting) bid1.save() bid2.save() post.accept_bid(bob, bid1.pk) self.assertEquals(bob.jobposting_set.get().contractor, emily) self.assertEquals(0, len(posting.bid_set.all()))
def test_get_bids(self): bob = JobPoster.objects.get(name="Bob") emily = Contractor.objects.get(name="Emily") joseph = Contractor.objects.get(name="Joseph") posting1 = new_job_posting() posting2 = new_job_posting() post.create_job_posting(bob, posting1) post.create_job_posting(bob, posting2) bid1 = Bid(contractor=emily, job=posting1) bid2 = Bid(contractor=joseph, job=posting1) bid3 = Bid(contractor=emily, job=posting2) bid1.save() bid2.save() bid3.save() self.assertEquals({bid1, bid2}, set(post.get_bids(bob, posting1.pk)))
def test_get_active_jobs(self): bob = JobPoster.objects.get(name="Bob") emily = Contractor.objects.get(name="Emily") joseph = Contractor.objects.get(name="Joseph") active1 = new_job_posting(contractor=emily) active2 = new_job_posting(contractor=joseph) posting = new_job_posting() completed = new_job_posting(contractor=emily, completed=True, completion_date=now()) post.create_job_posting(bob, active1) post.create_job_posting(bob, active2) post.create_job_posting(bob, posting) post.create_job_posting(bob, completed) self.assertEquals({active1, active2}, set(post.get_active_jobs(bob)))
def test_get_job_postings(self): bob = JobPoster.objects.get(name="Bob") emily = Contractor.objects.get(name="Emily") posting1 = new_job_posting() posting2 = new_job_posting() active = new_job_posting(short_description="active", contractor=emily) completed = new_job_posting(short_description="completed", contractor=emily, completed=True, completion_date=now()) post.create_job_posting(bob, posting1) post.create_job_posting(bob, posting2) post.create_job_posting(bob, active) post.create_job_posting(bob, completed) self.assertEquals({posting1, posting2}, set(post.get_job_postings(bob)))
def test_create_job_posting_field_too_long(self): with self.assertRaises(SuspiciousOperation): bob = JobPoster.objects.get(name="Bob") posting = new_job_posting(short_description="toolong" * 50) post.create_job_posting(bob, posting)
def test_create_job_posting_missing_required_field(self): with self.assertRaises(SuspiciousOperation): bob = JobPoster.objects.get(name="Bob") posting = new_job_posting(description=None) post.create_job_posting(bob, posting)
def test_create_job_posting(self): bob = JobPoster.objects.get(name="Bob") posting = new_job_posting() post.create_job_posting(bob, posting) self.assertTrue(posting in bob.jobposting_set.all())