示例#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),
     }
示例#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')
示例#7
0
 def random_prisoner(self):
     full_name = random_prisoner_name()
     first_name = full_name.split(' ')[0]
     last_name = full_name.split(' ')[1]
     return {
         'given_name': first_name,
         'middle_names': '',
         'surname': last_name,
         'date_of_birth': str(random_prisoner_dob()),
         # HMPPS Prison API returns more information not included here
     }
 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'
     )
示例#9
0
 def get_invalid_string_prisoner_dob(self, cannot_equal):
     while True:
         prisoner_dob = random_prisoner_dob()
         prisoner_dob = format_date(prisoner_dob, 'Y-m-d')
         if prisoner_dob != cannot_equal:
             return prisoner_dob
 def get_invalid_string_prisoner_dob(self, cannot_equal):
     while True:
         prisoner_dob = random_prisoner_dob()
         prisoner_dob = format_date(prisoner_dob, 'Y-m-d')
         if prisoner_dob != cannot_equal:
             return prisoner_dob