def test_unexpire_expired_purchased_job(self): product = PurchasedProductFactory( product=self.product, owner=self.company) job = PurchasedJobFactory( owner=self.company, created_by=self.user, purchased_product=product) kwargs = {'pk': job.pk} self.assertFalse(job.is_expired) job.is_expired = True job.date_expired = date.today() job.max_expired_date = date.today() - timedelta(1) job.save() data = dict(self.purchasedjob_form_data) data['is_expired'] = False response = self.client.post(reverse('purchasedjob_update', kwargs=kwargs), data=self.purchasedjob_form_data, follow=True) self.assertEqual(response.status_code, 200) # Confirm that the job remains expired despite the attempt to # change it. job = Job.objects.get() self.assertTrue(job.is_expired)
def test_request_on_purchasedjob_update(self): # Creating a PurchasedJob for a Product that requires approval # creates a Request job = PurchasedJobFactory(owner=self.company, created_by=self.user) self.assertEqual(Request.objects.count(), 1) # Re-saving that job should not create a new request. job.save() self.assertEqual(Request.objects.count(), 1) # Approving the job should also not create a new request. job.is_approved = True job.save() self.assertEqual(Request.objects.count(), 1) # Marking the job as not approved and saving it should not create # a new request if no action was taken on the old request. job.is_approved = False job.save() self.assertEqual(Request.objects.count(), 1) # Marking the job as not approved and saving it should create # a new request if there is no pending request. request = Request.objects.get() request.action_taken = True request.save() job.save() self.assertEqual(Request.objects.count(), 2)
def test_purchasedjobs_active_expired(self): purchased_product = PurchasedProductFactory(product=self.product, owner=self.company) PurchasedJobFactory.create_batch( 3, purchased_product=purchased_product, owner=self.company, created_by=self.user ) expired_job = PurchasedJobFactory(purchased_product=purchased_product, owner=self.company, created_by=self.user) expired_job.is_expired = True expired_job.save() response = self.client.post(reverse("purchasedjobs", kwargs={"purchased_product": purchased_product.id})) self.assertEqual(response.status_code, 200) self.assertEqual(len(response.context["active_jobs"]), 3) self.assertEqual(len(response.context["expired_jobs"]), 1)
def test_purchasedjob_filter_by_sites(self): for x in range(8800, 8815): domain = 'testsite-%s.jobs' % x site = SeoSiteFactory(id=x, domain=domain, name=domain) site_package = SitePackageFactory(owner=self.company) site_package.make_unique_for_site(site) product = ProductFactory(package=site_package, owner=self.company) purchased_product = PurchasedProductFactory(product=product, owner=self.company) for y in range(1, 5): job = PurchasedJobFactory(owner=self.company, created_by=self.user, purchased_product=purchased_product) job.site_packages.add(site_package) job.save() count = PurchasedJob.objects.filter_by_sites([site]).count() self.assertEqual(count, 4) self.assertEqual(PurchasedJob.objects.all().count(), 60)