def test_calc_return_requests(self): """Test calculating the return requests""" composer = FOIAComposerFactory( status='submitted', agencies=AgencyFactory.create_batch(6), num_org_requests=1, num_monthly_requests=2, num_reg_requests=3, user__profile__num_requests=5, user__profile__monthly_requests=10, user__profile__organization=OrganizationFactory(num_requests=100), ) values = [ (7, 4, 2, 1), (6, 3, 2, 1), (5, 3, 2, 0), (4, 3, 1, 0), (3, 3, 0, 0), (2, 2, 0, 0), (1, 1, 0, 0), ] for total, reg, monthly, org in values: eq_( composer._calc_return_requests(total), { 'regular': reg, 'monthly': monthly, 'org': org, }, )
def test_return_requests(self): """Test return requests""" organization = OrganizationFactory(num_requests=100) composer = FOIAComposerFactory( status='submitted', num_org_requests=1, num_monthly_requests=2, num_reg_requests=3, user__profile__num_requests=5, user__profile__monthly_requests=10, user__profile__organization=organization, ) composer._return_requests({ 'regular': 2, 'monthly': 0, 'org': 1, }) composer.user.profile.refresh_from_db() composer.user.profile.organization.refresh_from_db() eq_(composer.num_reg_requests, 1) eq_(composer.num_monthly_requests, 2) eq_(composer.num_org_requests, 0) eq_(composer.user.profile.num_requests, 7) eq_(composer.user.profile.monthly_requests, 10) eq_(composer.user.profile.organization.num_requests, 101)
def test_org_invoice_receipt(self, mock_send): """A receipt should be sent after an org subscription payment is made.""" mock_subscription.plan.id = 'org' customer_id = 'test-org' owner = UserFactory(profile__customer_id=customer_id) OrganizationFactory(owner=owner) mock_invoice.customer = customer_id tasks.send_invoice_receipt(mock_invoice.id) mock_send.assert_called_with(fail_silently=False)
def setUp(self): self.agencies = AgencyFactory.create_batch(6) self.organization = OrganizationFactory(num_requests=100) self.composer = FOIAComposerFactory( status='submitted', agencies=self.agencies, num_org_requests=1, num_monthly_requests=2, num_reg_requests=3, user__profile__num_requests=5, user__profile__monthly_requests=10, user__profile__organization=self.organization, ) self.task = MultiRequestTask.objects.create(composer=self.composer)
def test_org_share(self): """Test sharing with your organization""" org = OrganizationFactory() self.foia.embargo = True org.owner.profile.organization = org self.foia.user.profile.organization = org # fellow org member cannot view it before sharing is turned on assert_false(self.foia.has_perm(org.owner, 'view')) self.creator.profile.org_share = True # now org member can view it assert_true(self.foia.has_perm(org.owner, 'view')) # non-org member still cannot view it assert_false(self.foia.has_perm(self.editor, 'view'))
def test_last_attempt_org(self, mock_cancel, mock_send): """After the last attempt at payment, cancel the user's org subscription""" self.profile.payment_failed = True self.profile.save() ok_(self.profile.payment_failed, 'The payment failed flag should be raised.') OrganizationFactory(owner=self.profile.user) mock_invoice.attempt_count = 4 mock_invoice.lines.data[0].plan.id = 'org' tasks.failed_payment(mock_invoice.id) self.profile.refresh_from_db() mock_cancel.assert_called_with() mock_send.assert_called_with(fail_silently=False) ok_(not self.profile.payment_failed, 'The payment failed flag should be lowered.')
def test_foia_viewable_org_share(self): """Test all the viewable and embargo functions""" org = OrganizationFactory() org.owner.profile.organization = org foia = FOIARequestFactory( embargo=True, composer__user__profile__organization=org, ) foias = FOIARequest.objects.get_viewable(org.owner) nose.tools.assert_not_in(foia, foias) foia.user.profile.org_share = True foia.user.profile.save() foias = FOIARequest.objects.get_viewable(org.owner) nose.tools.assert_in(foia, foias)
def test_get_viewable_org_not_shared(self): """Test get viewable for an org not shared composer""" org = OrganizationFactory() org_user1 = UserFactory( profile__organization=org, profile__org_share=False, ) org_user2 = UserFactory(profile__organization=org, ) FOIARequestFactory( composer__status='filed', embargo=True, composer__user=org_user1, ) assert_true(FOIAComposer.objects.get_viewable(self.staff).exists()) assert_false(FOIAComposer.objects.get_viewable(self.user).exists()) assert_false(FOIAComposer.objects.get_viewable(org_user2).exists()) assert_false(FOIAComposer.objects.get_viewable(self.anon).exists())
def setUp(self): self.user = UserFactory(profile__acct_type='pro') self.user.profile.organization = OrganizationFactory(active=True) self.foia = FOIARequestFactory(composer__user=self.user) self.request_factory = RequestFactory() self.url = self.foia.get_absolute_url()