Example #1
0
    def test_create(self):
        user = self.prisoner_location_admins[0]

        repeated_p_num_1 = random_prisoner_number()
        repeated_p_num_2 = random_prisoner_number()
        # create two pre-existing PrisonerLocations so that we test the overwrite
        mommy.make(PrisonerLocation,
                   prisoner_number=repeated_p_num_1,
                   prison=self.prisons[0],
                   active=True)
        mommy.make(PrisonerLocation,
                   prisoner_number=repeated_p_num_2,
                   prison=self.prisons[0],
                   active=True)
        self.assertEqual(
            PrisonerLocation.objects.filter(active=True).count(), 2)
        self.assertEqual(
            PrisonerLocation.objects.filter(active=False).count(), 0)

        data = [
            {
                'prisoner_name': random_prisoner_name(),
                'prisoner_number': random_prisoner_number(),
                'prisoner_dob': random_prisoner_dob(),
                'prison': self.prisons[0].pk
            },
            {
                'prisoner_name': random_prisoner_name(),
                'prisoner_number': repeated_p_num_1,
                'prisoner_dob': random_prisoner_dob(),
                'prison': self.prisons[1].pk
            },
            {
                'prisoner_name': random_prisoner_name(),
                'prisoner_number': repeated_p_num_2,
                'prisoner_dob': random_prisoner_dob(),
                'prison': self.prisons[1].pk
            },
        ]
        response = self.client.post(
            self.list_url,
            data=data,
            format='json',
            HTTP_AUTHORIZATION=self.get_http_authorization_for_user(user))
        self.assertEqual(response.status_code, status.HTTP_201_CREATED)

        self.assertEqual(
            PrisonerLocation.objects.filter(active=True).count(), 2)
        # test that inactive prisoner location records is now 3
        latest_created = PrisonerLocation.objects.filter(active=False)
        self.assertEqual(latest_created.count(), 3)
        for item in data:
            self.assertEqual(latest_created.filter(**item).count(), 1)

        return data
    def test_create(self):
        user = self.prisoner_location_admins[0]

        repeated_p_num_1 = random_prisoner_number()
        repeated_p_num_2 = random_prisoner_number()
        # create two pre-existing PrisonerLocations so that we test the overwrite
        mommy.make(PrisonerLocation, prisoner_number=repeated_p_num_1,
                   prison=self.prisons[0], active=True)
        mommy.make(PrisonerLocation, prisoner_number=repeated_p_num_2,
                   prison=self.prisons[0], active=True)
        self.assertEqual(PrisonerLocation.objects.filter(active=True).count(), 2)
        self.assertEqual(PrisonerLocation.objects.filter(active=False).count(), 0)

        data = [
            {
                'prisoner_name': random_prisoner_name(),
                'prisoner_number': random_prisoner_number(),
                'prisoner_dob': random_prisoner_dob(),
                'prison': self.prisons[0].pk
            },
            {
                'prisoner_name': random_prisoner_name(),
                'prisoner_number': repeated_p_num_1,
                'prisoner_dob': random_prisoner_dob(),
                'prison': self.prisons[1].pk
            },
            {
                'prisoner_name': random_prisoner_name(),
                'prisoner_number': repeated_p_num_2,
                'prisoner_dob': random_prisoner_dob(),
                'prison': self.prisons[1].pk
            },
        ]
        response = self.client.post(
            self.list_url, data=data, format='json',
            HTTP_AUTHORIZATION=self.get_http_authorization_for_user(user)
        )
        self.assertEqual(response.status_code, status.HTTP_201_CREATED)

        self.assertEqual(PrisonerLocation.objects.filter(active=True).count(), 2)
        # test that inactive prisoner location records is now 3
        latest_created = PrisonerLocation.objects.filter(active=False)
        self.assertEqual(latest_created.count(), 3)
        for item in data:
            self.assertEqual(latest_created.filter(**item).count(), 1)

        return data
def make_prisoner():
    return mommy.make(
        PrisonerProfile,
        prisoner_name=random_prisoner_name(),
        prisoner_number=random_prisoner_number(),
        prisoner_dob=random_prisoner_dob(),
        current_prison=Prison.objects.order_by('?').first(),
    )
 def _get_credit_data(self):
     return {
         'amount': 1000,
         'prisoner_number': random_prisoner_number(),
         'prisoner_dob': random_prisoner_dob(),
         'prison': None,
         'received_at': timezone.now().replace(microsecond=0),
     }
 def _get_credit_data(self):
     return {
         'amount': 1000,
         'prisoner_number': random_prisoner_number(),
         'prisoner_dob': random_prisoner_dob(),
         'prison': None,
         'received_at': timezone.now().replace(microsecond=0),
     }
Example #6
0
 def test_create_error_invalid_prison(self):
     self._test_validation_error(
         data=[{
             'prisoner_name': random_prisoner_name(),
             'prisoner_number': random_prisoner_number(),
             'prisoner_dob': random_prisoner_dob(),
             'prison': 'invalid'
         }],
         assert_error_msg='Should fail because invalid prison')
Example #7
0
 def test_create_error_invalid_dob(self):
     self._test_validation_error(
         data=[{
             'prisoner_name': random_prisoner_name(),
             'prisoner_number': random_prisoner_number(),
             'prisoner_dob': '01//02//2015',
             'prison': self.prisons[0].pk
         }],
         assert_error_msg='Should fail because invalid dob')
 def test_create_error_invalid_prison(self):
     self._test_validation_error(
         data=[
             {
                 'prisoner_name': random_prisoner_name(),
                 'prisoner_number': random_prisoner_number(),
                 'prisoner_dob': random_prisoner_dob(),
                 'prison': 'invalid'
             }
         ],
         assert_error_msg='Should fail because invalid prison'
     )
 def test_create_error_invalid_dob(self):
     self._test_validation_error(
         data=[
             {
                 'prisoner_name': random_prisoner_name(),
                 'prisoner_number': random_prisoner_number(),
                 'prisoner_dob': '01//02//2015',
                 'prison': self.prisons[0].pk
             }
         ],
         assert_error_msg='Should fail because invalid dob'
     )
def _get_credit_values(credit_filters, sender_profile_id, prisoner_profile_id,
                       prisoner_name):
    return dict(
        {
            'amount': random.randint(100, 1000000),
            'prisoner_number': random_prisoner_number(),
            'prisoner_name': prisoner_name,
            'prisoner_profile_id': prisoner_profile_id,
            'sender_profile_id': sender_profile_id,
            'prison_id': random.choice(Prison.objects.all()).nomis_id
        },
        **{key: val
           for key, val in credit_filters.items() if '__' not in key})
Example #11
0
    def setUp(self):
        self.prison_ids = [
            'BWI',  # HMP Berwyn
            'NMI',  # HMP Nottingham
            'WLI',  # HMP Wayland
        ]
        prisoners_per_prison = {
            'BWI': 1,
            'NMI': 5,
            'WLI': 2,
        }
        # Dictionaries with data returned by mocked API
        self.api_live_roll = defaultdict(list)
        self.api_offenders_info = {}
        # Location of each test prisoner
        self.prisoner_location = {}

        for prison_id, n_prisoners in prisoners_per_prison.items():
            for _ in range(n_prisoners):
                prisoner_id = random_prisoner_number()
                prisoner_info = self.random_prisoner()

                self.api_live_roll[prison_id].append(prisoner_id)
                self.api_offenders_info[prisoner_id] = prisoner_info
                self.prisoner_location[prisoner_id] = prison_id

        self.n_prisoners_desired = 5
        # 1 prisoner from BWI
        self.expected_prisoner_ids = self.api_live_roll['BWI']
        # first 2 prisoners from NMI
        prisoners = copy(self.api_live_roll['NMI'])
        prisoners.sort()
        self.expected_prisoner_ids = self.expected_prisoner_ids + prisoners[:2]
        # another 2 prisoners from WLI
        self.expected_prisoner_ids = self.expected_prisoner_ids + self.api_live_roll[
            'WLI']
Example #12
0
 def get_invalid_prisoner_number(self, cannot_equal):
     while True:
         prisoner_number = random_prisoner_number()
         if prisoner_number != cannot_equal:
             return prisoner_number
 def get_invalid_prisoner_number(self, cannot_equal):
     while True:
         prisoner_number = random_prisoner_number()
         if prisoner_number != cannot_equal:
             return prisoner_number