def test_random_nhs_numbers_arguments(self):
     """Test that we can specify the range of random NHS numbers."""
     gen = random_nhs_number_generator([(489000000, 489999999)])
     for i in range(100):
         nhs_number = next(gen)
         self.assertTrue(
             nhs_number.startswith('489')
             and is_valid_nhs_number(nhs_number))
    def test_default_amount(self):
        """Test the default number of NHS numbers generated when calling as a script."""
        with patch('sys.stdout', new=StringIO()) as fakeOutput:
            generate_nhs_numbers.main()
            output = fakeOutput.getvalue().strip().split("\n")

        for nhs_num in output:
            self.assertTrue(is_valid_nhs_number(nhs_num))
        self.assertEqual(10, len(output))
 def test_is_valid(self):
     """Test that we can tell a valid number from an invalid one."""
     self.assertTrue(is_valid_nhs_number('0000000000'))
     self.assertFalse(
         is_valid_nhs_number('0000000001'))  # invalid check digit
     self.assertFalse(is_valid_nhs_number('000000r000'))  # not a number
     self.assertFalse(is_valid_nhs_number('000000000'))  # too short
     self.assertFalse(is_valid_nhs_number('00000000000'))  # too long
     self.assertFalse(
         is_valid_nhs_number('0000000060'))  # check digit would be 10
 def test_random_nhs_numbers_are_valid(self):
     """Test that all of the random NHS numbers are valid."""
     for i in range(100):
         self.assertTrue(
             is_valid_nhs_number(next(self.random_nhs_generator)))
 def test_all_deterministic_nums_are_valid(self):
     """Test that all numbers generated by the deterministic generator are valid."""
     for i in range(100):
         self.assertTrue(
             is_valid_nhs_number(next(self.deterministic_nhs_generator)))