def test_get_company_profile_ok_saves_to_session(mock_get_company_profile):
    session = {}
    data = {
        'company_number': '12345678',
        'company_name': 'Example corp',
        'sic_codes': ['1234'],
        'date_of_creation': '2001-01-20',
        'registered_office_address': {'one': '555', 'two': 'fake street'},
    }

    mock_get_company_profile.return_value = create_response(200, data)
    helpers.get_company_profile('123456', session)

    assert session['COMPANY_PROFILE-123456'] == data
Exemplo n.º 2
0
 def clean(self):
     cleaned_data = super().clean()
     if 'company_number' in cleaned_data:
         company_data = helpers.get_company_profile(
             number=self.cleaned_data['company_number'],
             session=self.session,
         )
         if company_data['company_status'] != 'active':
             raise ValidationError(
                 {'company_name': self.MESSAGE_COMPANY_NOT_ACTIVE})
     else:
         url = reverse('enrolment-business-type')
         message = self.MESSAGE_COMPANY_NOT_FOUND.format(url=url)
         raise ValidationError({'company_name': mark_safe(message)})
Exemplo n.º 3
0
 def get_form_kwargs(self, step=None):
     form_kwargs = super().get_form_kwargs(step=step)
     if step == BUSINESS_INFO:
         previous_data = self.get_cleaned_data_for_step(COMPANY_SEARCH)
         if previous_data:
             form_kwargs['company_data'] = helpers.get_company_profile(
                 number=previous_data['company_number'],
                 session=self.request.session,
             )
             form_kwargs['is_enrolled'] = helpers.get_is_enrolled(
                 company_number=previous_data['company_number'],
                 session=self.request.session,
             )
     return form_kwargs
Exemplo n.º 4
0
 def clean(self):
     cleaned_data = super().clean()
     if 'company_number' in cleaned_data:
         try:
             company_type_validator(cleaned_data['company_number'])
         except ValidationError as error:
             raise ValidationError({'company_name': error})
         company_data = helpers.get_company_profile(
             number=self.cleaned_data['company_number'],
             session=self.session,
         )
         if company_data['company_status'] != 'active':
             raise ValidationError(
                 {'company_name': self.MESSAGE_COMPANY_NOT_ACTIVE})
     elif 'company_name' in cleaned_data:
         raise ValidationError(
             {'company_name': mark_safe(self.MESSAGE_COMPANY_NOT_FOUND)})
def test_get_company_profile_not_ok(mock_get_company_profile):
    mock_get_company_profile.return_value = create_response(400)
    with pytest.raises(HTTPError):
        helpers.get_company_profile('123456', {})