def test_change_contracting(self): consultant = FakeConsultantFactory.create() ContractingData.objects.create( profile=consultant.exo_profile, name=faker.name(), address=faker.address(), company_name=faker.company(), ) self.client.login( username=self.super_user.username, password='******', ) url = reverse( 'api:profile:change-contracting', kwargs={'pk': consultant.user.pk}, ) data = { 'name': faker.name(), 'address': faker.address(), 'company_name': faker.company(), } response = self.client.put(url, data=data, format='json') self.assertTrue(status.is_success(response.status_code)) self.assertTrue( consultant.exo_profile.contracting_data.name, data['name'], ) self.assertEqual(ContractingData.objects.count(), 1)
def test_edit_contracting_data(self): # PREPARE DATA consultant = FakeConsultantFactory.create( status=settings.CONSULTANT_STATUS_CH_ACTIVE) contracting_data = ContractingData.objects.create( profile=consultant.exo_profile, name=faker.name(), address=faker.address(), company_name=faker.company(), ) url = reverse( 'api:accounts:user-contracting-data', kwargs={'uuid': consultant.user.uuid.__str__()}) new_data = { 'name': faker.name(), 'address': faker.address(), 'company_name': faker.company(), 'tax_id': '2522', } # DO ACTION response = self.client.put( url, format='json', data=new_data, HTTP_USERNAME=settings.AUTH_SECRET_KEY) # ASSERTS contracting_data.refresh_from_db() self.assertTrue(status.is_success(response.status_code)) self.assertEqual(contracting_data.name, new_data['name'])
def create_application(self, consultant=None, level=None): certification_level = level or settings.EXO_CERTIFICATION_CERTIFICATION_CH_LEVEL_2 cert_request = CertificationRequest.objects.create( user=consultant.user, requester_email=consultant.user.email, requester_name=consultant.user.full_name, certification=ExOCertification.objects.get( level=certification_level), ) if certification_level == settings.EXO_CERTIFICATION_CERTIFICATION_CH_LEVEL_2: cohort = self.cohort_lvl_2.pk elif certification_level == settings.EXO_CERTIFICATION_CERTIFICATION_CH_LEVEL_3: cohort = self.cohort_lvl_3.pk payload = { 'country': 'NO', 'recaptcha': faker.word(), 'billingName': faker.name(), 'taxId': faker.word(), 'billingAddress': faker.address(), 'companyName': faker.name(), 'cohort': cohort, 'application_details': { 'reasons': ' '.join(faker.words()), 'whereMetUs': faker.word(), } } self.client.put( reverse('api:exo-certification:applications-detail', kwargs={'pk': cert_request.pk}), data=payload, )
def test_pending_user_non_consultant_application_consultant(self, mock_request, mock_email): # PREPARE DATA mock_request.register_uri( 'POST', get_root_payments_url() + settings.EXO_CERTIFICATION_PAYMENTS_API_URL, json=get_payment_mock() ) user = FakeUserFactory.create() cert_request = CertificationRequest.objects.create( requester_email=user.email, requester_name=user.full_name, user=user, certification=ExOCertification.objects.get( level=settings.EXO_CERTIFICATION_CERTIFICATION_CH_LEVEL_2 ), ) payload = { 'country': 'PT', 'recaptcha': faker.word(), 'billingName': faker.name(), 'taxId': faker.word(), 'billingAddress': faker.address(), 'companyName': faker.name(), 'cohort': self.cohort_lvl_2.pk, 'application_details': self.generate_application_details_data(), } url = reverse('api:exo-certification:applications-detail', kwargs={'pk': cert_request.pk}) # DO ACTION response = self.client.put(url, data=payload) # ASSERTS self.assertTrue(status.is_success(response.status_code)) data = response.json() self.assertIsNotNone(data.get('nextUrl'))
class FakeContactFactoryMixin(factory.Factory): phone = factory.LazyAttribute(lambda x: faker.phone_number()) website = factory.LazyAttribute(lambda x: faker.url()) address = factory.LazyAttribute(lambda x: faker.address()) postcode = factory.LazyAttribute(lambda x: faker.postcode()) contact_person = factory.LazyAttribute(lambda x: '{},\n{},\n{}'.format( faker.name(), faker.company_email(), faker.phone_number(), ))
def get_payment_data(self): return { 'amount': '2000', 'currency': settings.PAYMENTS_CH_USD, 'concept': faker.sentence(), 'detail': faker.sentence(), 'email': faker.email(), 'full_name': faker.name(), 'tax_id': faker.word(), 'address': faker.address(), 'country': faker.country(), 'country_code': 'ES', 'company_name': faker.word(), 'send_by_email': False, 'send_invoice': True, '_type': settings.PAYMENTS_TYPE_CERTIFICATION, 'notes': faker.sentence(), }
def test_assert_multiple_calls_for_same_user_and_cohort_do_not_duplicate_requests_for_level_3(self): consultant = FakeConsultantFactory.create() cert_request = CertificationRequest.objects.create( user=consultant.user, requester_email=consultant.user.email, requester_name=consultant.user.full_name, certification=ExOCertification.objects.get( level=settings.EXO_CERTIFICATION_CERTIFICATION_CH_LEVEL_3 ), ) payload = { 'country': 'NO', 'recaptcha': faker.word(), 'billingName': faker.name(), 'taxId': faker.word(), 'billingAddress': faker.address(), 'companyName': faker.name(), 'cohort': self.cohort_lvl_3.pk, 'application_details': self.generate_application_details_data(), } url = reverse('api:exo-certification:applications-detail', kwargs={'pk': cert_request.pk}) # DO ACTION self.client.put(url, data=payload) payload = { 'email': consultant.user.email, 'password': consultant.user.short_name, 'level': settings.EXO_CERTIFICATION_CERTIFICATION_CH_LEVEL_3, 'recaptcha': faker.word(), } url = reverse('api:exo-certification:applications-existing-user') # DO ACTION response = self.client.post(url, data=payload) # ASSERTS self.assertTrue(status.is_success(response.status_code)) self.assertEqual(CertificationRequest.objects.count(), 1) self.assertEqual( CertificationRequest.objects.first().status, settings.EXO_CERTIFICATION_REQUEST_STATUS_CH_PENDING, )
def test_contracting_data(self): # PREPARE DATA consultant = FakeConsultantFactory.create( status=settings.CONSULTANT_STATUS_CH_ACTIVE) ContractingData.objects.create( profile=consultant.exo_profile, name=faker.name(), address=faker.address(), company_name=faker.company(), ) url = reverse( 'api:accounts:user-contracting-data', kwargs={'uuid': consultant.user.uuid.__str__()}) # DO ACTION response = self.client.get(url, HTTP_USERNAME=settings.AUTH_SECRET_KEY) # ASSERTS data = response.json() self.assertTrue(status.is_success(response.status_code)) self.assertIsNotNone(data['name'])
def test_contracting_data_ok_filled(self): # PREPARE DATA consultant = FakeConsultantFactory.create(user__password='******') contracting_data = ContractingData.objects.create( profile=consultant.exo_profile, name=faker.name(), address=faker.address(), company_name=faker.company(), ) data = {'username': consultant.user.email, 'password': '******'} url = reverse('api:accounts:public-contracting-data') # DO ACTION response = self.client.post(url, data) # ASSERTS self.assertTrue(status.is_success(response.status_code)) data = response.json() self.assertEqual(data['fullName'], consultant.user.full_name) self.assertEqual(data['contractingData']['name'], contracting_data.name)