def setUp(self): super().setUp() make_test_users() self.credit = Credit.objects.create( **self._get_credit_data() )
def setUp(self): super().setUp() make_test_users(clerks_per_prison=1) load_random_prisoner_locations() generate_transactions(transaction_batch=50) self.superuser = User.objects.create_superuser(username='******', password='******', email='*****@*****.**') self.client.login(username='******', password='******')
def test_will_not_check_non_initial_credits(self): make_test_users(clerks_per_prison=1) load_random_prisoner_locations(number_of_prisoners=1) generate_payments() for credit in Credit.objects.credit_pending(): self.assertFalse(credit.should_check()) for credit in Credit.objects.credited(): self.assertFalse(credit.should_check())
def test_will_not_check_non_pending_payments(self): make_test_users(clerks_per_prison=1) load_random_prisoner_locations(number_of_prisoners=1) generate_payments(10) credit = Credit.objects.credited().first() credit.owner = None credit.resolution = CREDIT_RESOLUTION.INITIAL credit.payment.status = PAYMENT_STATUS.FAILED credit.save() self.assertFalse(credit.should_check())
def _make_candidate_credit(self): make_test_users(clerks_per_prison=1) load_random_prisoner_locations(number_of_prisoners=1) generate_payments(10) call_command('update_security_profiles') credit = Credit.objects.credited().first() credit.owner = None credit.resolution = CREDIT_RESOLUTION.INITIAL payment = credit.payment payment.status = PAYMENT_STATUS.PENDING credit.log_set.filter(action=CREDIT_LOG_ACTIONS.CREDITED).delete() return credit
def test_will_not_check_transactions(self): make_test_users(clerks_per_prison=1) load_random_prisoner_locations(number_of_prisoners=1) generate_transactions(consistent_history=True) for credit in Credit.objects.credit_pending(): self.assertFalse(credit.should_check()) for credit in Credit.objects.credited(): self.assertFalse(credit.should_check()) for credit in Credit.objects.refund_pending(): self.assertFalse(credit.should_check()) for credit in Credit.objects.refunded(): self.assertFalse(credit.should_check())
def setUp(self): super().setUp() test_users = make_test_users() self.prison_clerks = test_users['prison_clerks'] self.send_money_users = test_users['send_money_users'] load_random_prisoner_locations(50) generate_payments(50, days_of_history=1)
def setUp(self): super().setUp() test_users = make_test_users() self.security_staff = test_users['security_staff'] load_random_prisoner_locations() generate_payments(payment_batch=200, days_of_history=3) generate_disbursements(disbursement_batch=200, days_of_history=3)
def make_2days_of_random_models(self): test_users = make_test_users() load_random_prisoner_locations() generate_payments(payment_batch=20, days_of_history=2) while not Disbursement.objects.sent().exists(): generate_disbursements(disbursement_batch=20, days_of_history=2) return test_users['security_staff']
def setUp(self): super().setUp() self.private_prison = mommy.make(Prison, name='Private', private_estate=True) self.private_bank_account = mommy.make(PrisonBankAccount, prison=self.private_prison) test_users = make_test_users(clerks_per_prison=2) self.prison_clerks = test_users['prison_clerks'] self.bank_admins = test_users['bank_admins'] load_random_prisoner_locations() transaction_credits = [ t.credit for t in generate_transactions(transaction_batch=20, days_of_history=4) if t.credit ] payment_credits = [ p.credit for p in generate_payments(payment_batch=20, days_of_history=4) if p.credit and p.credit.resolution != 'initial' ] self.credits = transaction_credits + payment_credits self.prisons = Prison.objects.all() self.latest_date = timezone.now().replace(hour=0, minute=0, second=0, microsecond=0) date = Credit.objects.earliest().received_at.replace(hour=0, minute=0, second=0, microsecond=0) while date < self.latest_date: end_of_date = date + datetime.timedelta(days=1) PrivateEstateBatch.objects.create_batches(date, end_of_date) date = end_of_date
def setUp(self): super().setUp() test_users = make_test_users(clerks_per_prison=2) self.prison_clerks = test_users['prison_clerks'] self.prisoner_location_admins = test_users['prisoner_location_admins'] self.bank_admins = test_users['bank_admins'] self.refund_bank_admins = test_users['refund_bank_admins'] self.send_money_users = test_users['send_money_users'] self.security_staff = test_users['security_staff'] self.latest_transaction_date = latest_transaction_date() self.latest_payment_date = latest_payment_date() load_random_prisoner_locations() transaction_credits = [ t.credit for t in generate_transactions( transaction_batch=self.transaction_batch, days_of_history=5) if t.credit ] payment_credits = [ p.credit for p in generate_payments(payment_batch=self.transaction_batch, days_of_history=5) if p.credit and p.credit.resolution != 'initial' ] self.credits = transaction_credits + payment_credits self.prisons = Prison.objects.all()
def test_empty_rejection_reason_raises_error(self): """ Test that rejecting a check without reason raises ValidationError. """ users = make_test_users(clerks_per_prison=1) check = mommy.make( Check, status=CHECK_STATUS.PENDING, actioned_at=None, actioned_by=None, ) # Execute response = self.client.post( reverse('security-check-reject', kwargs={'pk': check.id}), { 'decision_reason': 'thisshouldntmatter', 'rejection_reasons': { } }, format='json', HTTP_AUTHORIZATION=self.get_http_authorization_for_user(users['security_fiu_users'][0]) ) self.assertEqual(response.status_code, 400) self.assertEqual( response.json(), {'rejection_reasons': ['This field cannot be blank.']}, )
def setUp(self): super().setUp() self.users = make_test_users(clerks_per_prison=1) prisoner_locations = load_random_prisoner_locations(number_of_prisoners=1) generate_payments(payment_batch=1) prisoner_profiles = generate_prisoner_profiles_from_prisoner_locations(prisoner_locations) sender_profiles = generate_sender_profiles_from_payments(number_of_senders=1, reassign_dcsd=True) prisoner_profiles[0].monitoring_users.add(self.users['security_fiu_users'][0].id) sender_profiles[0].debit_card_details.first().monitoring_users.add(self.users['security_fiu_users'][0].id) response = self.client.post( reverse( 'security-check-auto-accept-list' ), data={ 'prisoner_profile_id': prisoner_profiles[0].id, 'debit_card_sender_details_id': sender_profiles[0].debit_card_details.first().id, 'states': [ { 'reason': 'This person has amazing hair', } ] }, format='json', HTTP_AUTHORIZATION=self.get_http_authorization_for_user(self.users['security_fiu_users'][0]), ) self.assertEqual(response.status_code, 201) self.auto_accept_rule = CheckAutoAcceptRule.objects.get(id=response.json()['id'])
def setUp(self): super().setUp() test_users = make_test_users() self.prison_clerks = test_users['prison_clerks'] self.bank_admins = test_users['disbursement_bank_admins'] self.user = self.prison_clerks[0] self.prison = Prison.objects.get(pk='IXB')
def setUp(self): super().setUp() test_users = make_test_users() self.user = test_users['security_staff'][0] load_random_prisoner_locations() generate_disbursements(200) call_command('update_security_profiles')
def test_cannot_accept_check_with_rejection_reason(self): # Setup users = make_test_users(clerks_per_prison=1) prisoner_locations = load_random_prisoner_locations() generate_payments(payment_batch=50) generate_prisoner_profiles_from_prisoner_locations(prisoner_locations) generate_sender_profiles_from_payments(number_of_senders=1, reassign_dcsd=True) generate_checks(number_of_checks=1, create_invalid_checks=False, overrides={'status': 'pending'}) check = Check.objects.filter(status='pending').first() # Execute response = self.client.post( reverse('security-check-accept', kwargs={'pk': check.id}), { 'decision_reason': 'computer says no', 'rejection_reasons': { 'payment_source_linked_other_prisoners': True, } }, format='json', HTTP_AUTHORIZATION=self.get_http_authorization_for_user(users['security_fiu_users'][0]) ) # Assert Response self.assertEqual(response.status_code, 400) self.assertEqual( response.json(), {'non_field_errors': ['You cannot give rejection reasons when accepting a check']} ) # Assert Lack of State Change check.refresh_from_db() self.assertEqual(check.status, 'pending') self.assertEqual(check.rejection_reasons, {}) self.assertEqual(check.decision_reason, '')
def setUp(self): super().setUp() # make 1 prisoner in a public prison and in a private one public_prison = Prison.objects.get(nomis_id='INP') public_prison.private_estate = False public_prison.save() private_prison = Prison.objects.get(nomis_id='IXB') private_prison.private_estate = True private_prison.use_nomis_for_balances = False private_prison.save() load_random_prisoner_locations(number_of_prisoners=2) prisoner_locations = PrisonerLocation.objects.order_by('?')[0:2] prisoner_location_public, prisoner_location_private = prisoner_locations prisoner_location_public.prison = public_prison prisoner_location_public.save() prisoner_location_private.prison = private_prison prisoner_location_private.save() self.prisoner_location_public = prisoner_location_public self.prisoner_location_private = prisoner_location_private # make standard users test_users = make_test_users(clerks_per_prison=1, num_security_fiu_users=0) send_money_users = test_users.pop('send_money_users') self.send_money_user = send_money_users[0] self.other_users = itertools.chain.from_iterable(test_users.values())
def setUp(self): super().setUp() test_users = make_test_users() self.prison_clerks = test_users['prison_clerks'] self.security_staff = test_users['security_staff'] load_random_prisoner_locations() generate_transactions(transaction_batch=100, days_of_history=5) generate_payments(payment_batch=100, days_of_history=5) call_command('update_security_profiles')
def setUp(self): super().setUp() test_users = make_test_users(clerks_per_prison=2) self.prison_clerks = test_users['prison_clerks'] self.prisoner_location_admins = test_users['prisoner_location_admins'] self.bank_admins = test_users['bank_admins'] self.refund_bank_admins = test_users['refund_bank_admins'] self.send_money_users = test_users['send_money_users'] self.prisons = Prison.objects.all()
def setUp(self): super().setUp() test_users = make_test_users() self.prison_clerks = test_users['prison_clerks'] self.security_staff = test_users['security_staff'] load_random_prisoner_locations() generate_transactions(transaction_batch=100, days_of_history=5) generate_payments(payment_batch=100, days_of_history=5) generate_disbursements(disbursement_batch=150, days_of_history=5) call_command('update_security_profiles')
def setUp(self): super().setUp() test_users = make_test_users(clerks_per_prison=2) prison_clerks = test_users['prison_clerks'] bank_admins = test_users['bank_admins'] send_money_users = test_users['send_money_users'] security_staff = test_users['security_staff'] self.users = prison_clerks[0], bank_admins[0], send_money_users[0], security_staff[0] self.send_money_user = send_money_users[0] load_random_prisoner_locations(number_of_prisoners=2 * Prison.objects.count())
def setUp(self): super().setUp() test_users = make_test_users(clerks_per_prison=2) self.prison_clerks = test_users['prison_clerks'] self.prisoner_location_admins = test_users['prisoner_location_admins'] self.bank_admins = test_users['bank_admins'] self.refund_bank_admins = test_users['refund_bank_admins'] self.send_money_users = test_users['send_money_users'] load_random_prisoner_locations(50) self.assertEqual(PrisonerLocation.objects.filter(active=True).count(), 50)
def setUp(self): super().setUp() self.url = reverse('token-detail', kwargs={'pk': 'nomis'}) self.normal_users = make_test_users(clerks_per_prison=1) self.token = self.make_client_token({ 'key': 'abc', 'access': ['^some-url$'], 'iat': time.time() - 1000, 'exp': time.time() + 1000, }) Token.objects.create(name='nomis', token=self.token)
def setUp(self): super().setUp() test_users = make_test_users() self.security_staff = test_users['security_staff'] load_random_prisoner_locations() generate_payments(payment_batch=20, days_of_history=2, overrides={ 'status': PAYMENT_STATUS.TAKEN, 'credited': True }) generate_disbursements(disbursement_batch=20, days_of_history=1)
def setUp(self): super().setUp() test_users = make_test_users(clerks_per_prison=2) self.prison_clerks = test_users['prison_clerks'] self.prisoner_location_admins = test_users['prisoner_location_admins'] self.bank_admins = test_users['bank_admins'] self.refund_bank_admins = test_users['refund_bank_admins'] self.send_money_users = test_users['send_money_users'] self.security_staff = test_users['security_staff'] self.latest_transaction_date = latest_transaction_date() self.prisons = Prison.objects.all() load_random_prisoner_locations()
def setUp(self): super().setUp() self.private_prison = mommy.make(Prison, name='Private', private_estate=True) self.private_bank_account = mommy.make(PrisonBankAccount, prison=self.private_prison) test_users = make_test_users(clerks_per_prison=2) self.prison_clerks = test_users['prison_clerks'] self.bank_admins = test_users['bank_admins'] load_random_prisoner_locations() transaction_credits = [ t.credit for t in generate_transactions(transaction_batch=20, days_of_history=4) if t.credit ] payment_credits = [ p.credit for p in generate_payments(payment_batch=20, days_of_history=4) if p.credit and p.credit.resolution != 'initial' ] self.credits = transaction_credits + payment_credits self.prisons = Prison.objects.all() creditable = Credit.STATUS_LOOKUP[ CREDIT_STATUS.CREDITED] | Credit.STATUS_LOOKUP[ CREDIT_STATUS.CREDIT_PENDING] private_estate_credit_set = Credit.objects.filter( prison__private_estate=True).filter(creditable) if not private_estate_credit_set.exists(): public_estate_credits = Credit.objects.filter( prison__private_estate=False).filter(creditable) public_estate_credits[public_estate_credits.count() // 2:].update(prison=self.private_prison) self.latest_date = timezone.now().replace(hour=0, minute=0, second=0, microsecond=0) date = Credit.objects.earliest().received_at.replace(hour=0, minute=0, second=0, microsecond=0) while date < self.latest_date: end_of_date = date + datetime.timedelta(days=1) PrivateEstateBatch.objects.create_batches(date, end_of_date) date = end_of_date
def setUp(self): super().setUp() test_users = make_test_users() self.user = test_users['security_staff'][0] load_random_prisoner_locations() # generate random data which may or may not match amount rules generate_transactions(transaction_batch=200, days_of_history=3) generate_payments(payment_batch=200, days_of_history=3) generate_disbursements(disbursement_batch=200, days_of_history=3) # £1 does not match NWN or HA rules and no monitoring exists, i.e. no non-counting rules can trigger Payment.objects.update(amount=100) Transaction.objects.update(amount=100) Credit.objects.update(amount=100) Disbursement.objects.update(amount=100)
def setUp(self): super().setUp() test_users = make_test_users(clerks_per_prison=2) self.prison_clerks = test_users['prison_clerks'] self.prisoner_location_admins = test_users['prisoner_location_admins'] self.bank_admins = test_users['bank_admins'] self.refund_bank_admins = test_users['refund_bank_admins'] self.send_money_users = test_users['send_money_users'] self.security_staff = test_users['security_staff'] self.latest_transaction_date = latest_transaction_date() self.latest_payment_date = latest_payment_date() load_random_prisoner_locations() transaction_credits = [t.credit for t in generate_transactions( transaction_batch=self.transaction_batch, days_of_history=5 ) if t.credit] payment_credits = [p.credit for p in generate_payments( payment_batch=self.transaction_batch, days_of_history=5 ) if p.credit and p.credit.resolution != 'initial'] self.credits = transaction_credits + payment_credits self.prisons = Prison.objects.all()
def setUp(self): super().setUp() self.prison_clerks = make_test_users()['prison_clerks']
def setUp(self): super().setUp() make_test_users() make_test_user_admins()
def setUp(self): super().setUp() test_users = make_test_users() self.bank_admins = test_users['bank_admins']
def setUp(self): super().setUp() test_users = make_test_users() self.prison_clerks = test_users['prison_clerks'] self.bank_admins = test_users['bank_admins']
def setUp(self): super().setUp() test_users = make_test_users() self.prison_clerks = test_users['prison_clerks'] self.send_money_users = test_users['send_money_users'] load_random_prisoner_locations(2)
def setUp(self): super().setUp() self.bank_admins = make_test_users()['bank_admins'] load_random_prisoner_locations(2)
def setUp(self): super().setUp() test_users = make_test_users() self.prison_clerks = test_users['prison_clerks'] self.security_staff = test_users['security_staff']
def setUp(self): super().setUp() self.users = list(itertools.chain.from_iterable( make_test_users(clerks_per_prison=1).values()) )
def handle(self, *args, **options): if settings.ENVIRONMENT == 'prod': return self.handle_prod(**options) verbosity = options.get('verbosity', 1) protect_superusers = options['protect_superusers'] protect_usernames = options['protect_usernames'] protect_credits = options['protect_credits'] prisons = options['prisons'] prisoners = options['prisoners'] number_of_prisoners = options['number_of_prisoners'] clerks_per_prison = options['clerks_per_prison'] credits = options['credits'] print_message = self.stdout.write if verbosity else lambda m: m if not protect_credits: print_message('Deleting all credits') Balance.objects.all().delete() Transaction.objects.all().delete() Payment.objects.all().delete() Credit.objects_all.all().delete() Batch.objects.all().delete() SenderProfile.objects.all().delete() PrisonerProfile.objects.all().delete() SavedSearch.objects.all().delete() Disbursement.objects.all().delete() RecipientProfile.objects.all().delete() user_set = get_user_model().objects.exclude(username__in=protect_usernames or []) if protect_superusers: user_set = user_set.exclude(is_superuser=True) print_message('Deleting %d users' % user_set.count()) user_set.delete() print_message('Deleting all prisons') Prison.objects.all().delete() fixtures = ['initial_groups.json', 'initial_types.json'] if 'sample' in prisons: fixtures.append('test_prisons.json') if 'nomis' in prisons: fixtures.append('test_nomis_prisons.json') if 'mtp' in prisons: fixtures.append('test_nomis_mtp_prisons.json') if 'nomis-api-dev' in prisons: fixtures.append('dev_nomis_api_prisons.json') print_message('Loading default user group and selected prison fixtures') call_command('loaddata', *fixtures, verbosity=verbosity) print_message('Giving super users full API access') give_superusers_full_access() print_message('Making test users') make_test_users(clerks_per_prison=clerks_per_prison) print_message('Making test user admins') make_test_user_admins() print_message('Making token retrieval user') make_token_retrieval_user() if 'nomis' in prisoners: load_prisoner_locations_from_file('test_nomis_prisoner_locations.csv') if 'nomis-api-dev' in prisoners: load_prisoner_locations_from_file('dev_nomis_api_prisoner_locations.csv') if 'sample' in prisoners: load_random_prisoner_locations(number_of_prisoners=number_of_prisoners) number_of_transactions = options['number_of_transactions'] number_of_payments = options['number_of_payments'] number_of_disbursements = options['number_of_disbursements'] days_of_history = options['days_of_history'] if credits == 'random': print_message('Generating random credits') generate_transactions(transaction_batch=number_of_transactions) generate_payments(payment_batch=number_of_payments) elif credits == 'nomis': print_message('Generating test NOMIS credits') generate_transactions( transaction_batch=number_of_transactions, predetermined_transactions=True, consistent_history=True, include_debits=False, include_administrative_credits=False, include_unidentified_credits=True, days_of_history=days_of_history ) generate_payments( payment_batch=number_of_payments, consistent_history=True, days_of_history=days_of_history ) generate_disbursements( disbursement_batch=number_of_disbursements, days_of_history=days_of_history ) call_command('update_security_profiles') digital_takeup = options['digital_takeup'] if digital_takeup: print_message('Generating digital take-up') generate_digital_takeup(days_of_history=days_of_history)
def setUp(self): super().setUp() make_test_users() load_random_prisoner_locations() generate_transactions(transaction_batch=100, days_of_history=21)
def setUp(self): make_test_users(1) load_random_prisoner_locations(1) self.payments = generate_payments(self.payment_count, days_of_history=10)
def setUp(self): super().setUp() test_users = make_test_users() self.prison_clerks = test_users['prison_clerks'] self.bank_admins = test_users['disbursement_bank_admins'] load_random_prisoner_locations()
def setUp(self): super().setUp() test_users = make_test_users() self.prison_clerks = test_users['prison_clerks'] self.bank_admins = test_users['disbursement_bank_admins']
def handle(self, *args, **options): # noqa: C901 if settings.ENVIRONMENT == 'prod': return self.handle_prod(**options) verbosity = options.get('verbosity', 1) no_protect_superusers = options['no_protect_superusers'] protect_usernames = options['protect_usernames'] protect_credits = options['protect_credits'] prisons = options['prisons'] prisoners = options['prisoners'] number_of_prisoners = options['number_of_prisoners'] number_of_senders = options['number_of_senders'] clerks_per_prison = options['clerks_per_prison'] credits = options['credits'] number_of_transactions = options['number_of_transactions'] number_of_payments = options['number_of_payments'] number_of_disbursements = options['number_of_disbursements'] number_of_checks = options['number_of_checks'] days_of_history = options['days_of_history'] extra_generate_checks_args = {} print_message = self.stdout.write if verbosity else lambda m: m if not protect_credits and credits != 'production-scale': print_message('Deleting all credits') Balance.objects.all().delete() Transaction.objects.all().delete() Payment.objects.all().delete() Credit.objects_all.all().delete() Batch.objects.all().delete() SenderProfile.objects.all().delete() PrisonerProfile.objects.all().delete() SavedSearch.objects.all().delete() Disbursement.objects.all().delete() RecipientProfile.objects.all().delete() Check.objects.all().delete() if credits == 'production-scale': # N.B. This scenario will eat your RAM like there's no tomorrow. ~13GB usage is # about as far as I've got before it's keeled over and i've had to rerun # If running it outside your development environment, be sure that it's not using the same # resource pool as a production service # If running it on your development environment you may need to tweak oom-killer so it # doesn't kill this process as soon as you near the memory limit of your system number_of_existing_transactions = Transaction.objects.count() number_of_existing_payments = Payment.objects.count() number_of_existing_prisoner_locations = PrisonerLocation.objects.count() number_of_existing_prisoners_profiles = PrisonerProfile.objects.count() number_of_existing_disbursements = Disbursement.objects.count() number_of_existing_checks = Check.objects.count() number_of_existing_senders = SenderProfile.objects.count() number_of_existing_prisoners = min( [number_of_existing_prisoner_locations, number_of_existing_prisoners_profiles] ) number_of_desired_transactions = 300000 number_of_desired_payments = 3000000 number_of_desired_prisoners = 80000 number_of_desired_senders = 700000 number_of_desired_disbursements = 20000 number_of_desired_checks = 900000 number_of_prisoners = max( 0, number_of_desired_prisoners - number_of_existing_prisoners ) print_message( f'Number of prisoners to be created is {number_of_desired_prisoners} - {number_of_existing_prisoners}' f' <= {number_of_prisoners}' ) number_of_transactions = max( 0, number_of_desired_transactions - number_of_existing_transactions ) print_message( f'Number of transactions to be created is {number_of_desired_transactions} - ' f'{number_of_existing_transactions} <= {number_of_transactions}' ) number_of_payments = max( 0, number_of_desired_payments - number_of_existing_payments ) print_message( f'Number of payments to be created is {number_of_desired_payments} - {number_of_existing_payments}' f' <= {number_of_payments}' ) number_of_disbursements = max( 0, number_of_desired_disbursements - number_of_existing_disbursements ) print_message( f'Number of disbursements to be created is {number_of_desired_disbursements} - ' f'{number_of_existing_disbursements} <= {number_of_disbursements}' ) number_of_senders = max( 0, number_of_desired_senders - number_of_existing_senders ) print_message( f'Number of senders to be created is {number_of_desired_senders} - {number_of_existing_senders}' f' <= {number_of_senders}' ) number_of_checks = max( 0, number_of_desired_checks - number_of_existing_checks ) print_message( f'Number of checks to be created is {number_of_desired_checks} - {number_of_existing_checks}' f' <= {number_of_checks}' ) assert number_of_desired_checks <= 3 * number_of_desired_payments, ( 'Due to constraints on the number of payments with a billing address ' 'in mtp_api/payments/tests/utils.py::setup_payment you must have checks <= 3*payments' ) days_of_history = 1300 prisons.append('nomis-api-dev') prisoners.append('sample') else: user_set = get_user_model().objects.exclude(username__in=protect_usernames or []) if not no_protect_superusers: user_set = user_set.exclude(is_superuser=True) print_message('Deleting %d users' % user_set.count()) user_set.delete() print_message('Deleting all prisons') Prison.objects.all().delete() fixtures = ['initial_groups.json', 'initial_types.json'] if 'sample' in prisons: fixtures.append('test_prisons.json') if 'nomis' in prisons: fixtures.append('test_nomis_prisons.json') if 'mtp' in prisons: fixtures.append('test_nomis_mtp_prisons.json') if 'nomis-api-dev' in prisons: fixtures.append('dev_nomis_api_prisons.json') if 'dev-prison-api' in prisons: fixtures.append('dev_prison_api_prisons.json') print_message('Loading default user group and selected prison fixtures') call_command('loaddata', *fixtures, verbosity=verbosity) print_message('Giving super users full API access') create_super_admin(self.stdout, self.style.SUCCESS) give_superusers_full_access() if credits != 'production-scale' or User.objects.count() < 2: print_message('Making test users') make_test_users(clerks_per_prison=clerks_per_prison) print_message('Making test user admins') make_test_user_admins() print_message('Making token retrieval user') prisoner_locations = None if 'nomis' in prisoners: prisoner_locations = load_prisoner_locations_from_file('test_nomis_prisoner_locations.csv') if 'nomis-api-dev' in prisoners: prisoner_locations = load_prisoner_locations_from_file('dev_nomis_api_prisoner_locations.csv') if 'dev-prison-api' in prisoners: prisoner_locations = load_prisoner_locations_from_dev_prison_api(number_of_prisoners=number_of_prisoners) if 'sample' in prisoners: prisoner_locations = load_random_prisoner_locations(number_of_prisoners=number_of_prisoners) if not prisoner_locations: prisoner_locations = PrisonerLocation.objects.all() if credits == 'random': print_message('Generating random credits') generate_transactions(transaction_batch=number_of_transactions) generate_payments(payment_batch=number_of_payments) elif credits == 'nomis': print_message('Generating test NOMIS credits') generate_transactions( transaction_batch=number_of_transactions, predetermined_transactions=True, consistent_history=True, include_debits=False, include_administrative_credits=False, include_unidentified_credits=True, days_of_history=days_of_history ) generate_payments( payment_batch=number_of_payments, consistent_history=True, days_of_history=days_of_history ) elif credits == 'production-scale': print_message('Generating production-like transactions') generate_transactions( transaction_batch=number_of_transactions, predetermined_transactions=True, consistent_history=True, include_debits=True, include_administrative_credits=True, include_unidentified_credits=True, days_of_history=days_of_history ) print_message('Generating production-like payments/credits') generate_payments( payment_batch=number_of_payments, consistent_history=True, days_of_history=days_of_history, attach_profiles_to_individual_credits=False, number_of_senders=number_of_senders ) print_message(f'Generating (at least) {number_of_prisoners} prisoner profiles') prisoner_profiles = generate_prisoner_profiles_from_prisoner_locations(prisoner_locations) print_message(f'Generated {len(prisoner_profiles)} prisoner profiles') print_message(f'Generating {number_of_senders} sender profiles') sender_profiles = generate_sender_profiles_from_payments(number_of_senders) print_message(f'Generated {len(sender_profiles)} sender profiles') prisoner_profiles_count = PrisonerProfile.objects.count() sender_profiles_count = SenderProfile.objects.count() extra_generate_checks_args.update({ 'create_invalid_checks': False, 'number_of_senders_to_use': int((number_of_checks * 5) / sender_profiles_count), 'number_of_prisoners_to_use': int((number_of_checks * 5) / prisoner_profiles_count) }) print_message('Generating disbursements') generate_disbursements( disbursement_batch=number_of_disbursements, days_of_history=days_of_history ) print_message('Generating checks') generate_checks( number_of_checks=number_of_checks, **extra_generate_checks_args ) print_message('Associating credits with profiles') with silence_logger(level=logging.WARNING): call_command('update_security_profiles') digital_takeup = options['digital_takeup'] if digital_takeup: print_message('Generating digital take-up') generate_digital_takeup(days_of_history=days_of_history)
def setUp(self): super().setUp() test_users = make_test_users() self.security_staff = test_users['security_staff']
def setUp(self): super().setUp() test_users = make_test_users() self.prison_clerks = test_users['prison_clerks'] self.security_staff = test_users['security_staff'] load_random_prisoner_locations()