def test_validation_exemption_code_or_cla_ref_required(self):

        validator = v.ProviderCSVValidator(self.data)

        cleaned_data = self.dummy_cleaned_data.copy()
        cleaned_data['Date Opened'] = datetime.datetime(2014, 1, 1)
        cleaned_data['Determination'] = False

        validator._validate_exemption(cleaned_data, u'debt')


        with self.assertRaisesRegexp(
                serializers.ValidationError,
                "[u'An Exemption Reason can only be entered for Debt, Discrimination and Education matter]"):
            validator._validate_exemption(cleaned_data, u'welfare')

        cleaned_data['Exempted Reason Code'] = u''
        cleaned_data['CLA Reference Number'] = u''

        with self.assertRaisesRegexp(
                serializers.ValidationError,
                "[u'Exempt Code Reason or CLA Reference number required before case was opened after 1st Apr 2013']"):
            validator._validate_exemption(cleaned_data, u'debt')


        cleaned_data['Date Opened'] = datetime.datetime(2011, 1, 1)
        cleaned_data['Exceptional Cases (ref)'] = u'foo'

        validator._validate_exemption(cleaned_data, u'debt')
        with self.assertRaisesRegexp(
                serializers.ValidationError,
                "[u'An Exemption Reason can only be entered for Debt, Discrimination and Education matter]"):
            validator._validate_exemption(cleaned_data, u'welfare')
    def test_staged_reached_validate_not_allowed_mt1s(self):

        validator = v.ProviderCSVValidator(self.data)

        cleaned_data = self.dummy_cleaned_data.copy()
        cleaned_data['Matter Type 1'] = u'WBAA'

        with self.assertRaisesRegexp(serializers.ValidationError, r'.*is not allowed because Matter Type 1: WBAA was specified.*'):
            validator._validate_stage_reached(cleaned_data)
    def test_staged_reached_validate_required_mt1s(self):

        validator = v.ProviderCSVValidator(self.data)

        cleaned_data = self.dummy_cleaned_data.copy()
        cleaned_data['Matter Type 1'] = u'DMCA'
        cleaned_data['Stage Reached'] = u''

        with self.assertRaisesRegexp(serializers.ValidationError, r'.*is required because Matter Type 1: DMCA was specified.*'):
            validator._validate_stage_reached(cleaned_data)
    def test_category_consistency_validation(self):

        validator = v.ProviderCSVValidator(self.data)

        cleaned_data = self.dummy_cleaned_data.copy()
        cleaned_data['Matter Type 1'] = u'S'
        cleaned_data['Matter Type 2'] = u'P'

        with self.assertRaisesRegexp(serializers.ValidationError, r'fields must be of the same category'):
            validator._validate_category_consistency(cleaned_data)
 def test_closed_date_after_opened_date_invariant(self):
     validator = v.ProviderCSVValidator([
         [u'3333333', u'0001', u'2B222B', u'A N Other', u'Corgi',
          u'02/01/1901', u'E', u'M', u'1', u'', u'', u'SW1A 1AA',
          u'X', u'EADM', u'ESOS', u'EB', u'EB', u'', u'01/01/2014',
          u'01/01/1902', u'99', u'99.5', u'', u'ILL', u'0', u'0',
          u'', u'N', u'', u'', u'NAR', u'', u'DK', u'TA' ],
     ])
     with self.assertRaisesRegexp(serializers.ValidationError, 'Row: 1 - .*must be after'):
         validator.validate()
    def test_service_adapation_validation_required(self):

        validator = v.ProviderCSVValidator(self.data)


        cleaned_data = self.dummy_cleaned_data.copy()

        cleaned_data['Adjustments / Adaptations '] = u''

        with self.assertRaisesRegexp(serializers.ValidationError, r'Adjustments / Adaptations field is required'):
            validator._validate_service_adaptation(cleaned_data)
    def test_validation_time_spent_less_than_18(self):

        validator = v.ProviderCSVValidator(self.data)

        cleaned_data = self.dummy_cleaned_data.copy()
        cleaned_data['Eligibility Code'] = u'S'
        cleaned_data['Determination'] = False

        validator._validate_eligibility_code(cleaned_data)
        cleaned_data['Time Spent'] = 999

        with self.assertRaisesRegexp(serializers.ValidationError, r'The eligibility code .* you have entered is not valid with'):
            validator._validate_eligibility_code(cleaned_data)
    def test_eligibility_code_validation_required(self):

        validator = v.ProviderCSVValidator(self.data)


        cleaned_data = self.dummy_cleaned_data.copy()

        validator._validate_eligibility_code(cleaned_data)

        cleaned_data['Eligibility Code'] = u''

        with self.assertRaisesRegexp(serializers.ValidationError, r'Eligibility Code field is required'):
            validator._validate_eligibility_code(cleaned_data)
    def test_validation_time_spent_more_than_18_with_determination_not_valid(self):

        validator = v.ProviderCSVValidator(self.data)

        cleaned_data = self.dummy_cleaned_data.copy()
        cleaned_data['Eligibility Code'] = u'S'
        cleaned_data['Determination'] = True

        cleaned_data['Time Spent'] = 9
        validator._validate_time_spent(cleaned_data)
        cleaned_data['Time Spent'] = 999

        with self.assertRaisesRegexp(serializers.ValidationError, "[u'Time spent (999) must not be greater than 18 minutes']"):
            validator._validate_time_spent(cleaned_data)
    def test_validate_ta_oa_ff_not_valid_for_edu_and_dis(self):

        validator = v.ProviderCSVValidator(self.data)
        cleaned_data = self.dummy_cleaned_data.copy()

        validator._validate_eligibility_code(cleaned_data)

        cleaned_data['Telephone / Online'] = u'FF'

        validator._validate_telephone_or_online_advice(cleaned_data, u'education')
        validator._validate_telephone_or_online_advice(cleaned_data, u'discrimination')

        with self.assertRaisesRegexp(serializers.ValidationError, r'.*code FF only valid for.*'):
            validator._validate_telephone_or_online_advice(cleaned_data, u'ssss')
    def test_service_adapation_validation_valid(self):
        validator = v.ProviderCSVValidator([
            [u'3333333', u'0001', u'2B222B', u'A N Other', u'Corgi',
             u'02/01/1901', u'E', u'M', u'1', u'', u'', u'SW1A 1AA',
             u'X', u'EPRO', u'ESOS', u'EB', u'EB', u'', u'01/01/2014',
             u'02/01/2014', u'99', u'99.5', u'', u'ILL', u'0', u'0',
             u'', u'N', u'', u'',

             u'LOL',

             u'', u'DK', u'TA' ],
            ])
        with self.assertRaisesRegexp(serializers.ValidationError, r'Adjustments / Adaptations - LOL must be one of'):
            validator.validate()
    def test_invalid_account_number(self):
        validator = v.ProviderCSVValidator([
            [u'3333333', u'0001',

             u'22222B',

             u'A N Other', u'Corgi',
             u'02/01/1901', u'E', u'M', u'1', u'', u'', u'SW1A 1AA',
             u'X', u'EPRO', u'ESOS', u'EB', u'EB', u'', u'01/01/1901',
             u'01/01/1902', u'99', u'99.5', u'', u'ILL', u'0', u'0',
             u'', u'N', u'', u'', u'NAR', u'', u'DK', u'TA' ],
        ])
        with self.assertRaises(serializers.ValidationError):
            validator.validate()
 def test_invalid_field_count(self):
     validator = v.ProviderCSVValidator([[],[]])
     with self.assertRaisesRegexp(serializers.ValidationError,
                                  r'Row: 1 - Incorrect number of columns'):
         validator.validate()
 def test_validator_valid(self):
     validator = v.ProviderCSVValidator(self.data)
     self.assertEqual(len(validator.validate()), 2)