def test_creation(existing_lead, resps): resps.add( resps.GET, member_url, json={ 'type': 'http://developer.mailchimp.com/documentation/mailchimp/guides/error-glossary/', 'title': 'Resource Not Found', 'status': 404, 'detail': 'The requested resource could not be found.', 'instance': 'b2b05bea-464c-4774-ab7b-40ae9466fb03' }, status=404) resps.add(resps.POST, 'https://us17.api.mailchimp.com/3.0/lists/list_id/members', json=existing_lead, status=200) expected_on_request = { 'email_address': '*****@*****.**', 'status': 'subscribed', 'merge_fields': { "FNAME": 'Renzo', }, 'interests': { roles_to_ids[facade._LEAD]: True }, 'tags': ['never-watched-video'] } facade.create_or_update_lead('Renzo', '*****@*****.**') assert json.loads(resps.calls[-1].request.body) == expected_on_request
def lead_form(request): if request.method == 'GET': form = UserSignupForm() return render(request, 'core/lead_form_errors.html', context={'form': form}) form = UserSignupForm(request.POST) if form.is_valid(): user = form.save() assign_role(user, 'lead') facade.create_or_update_lead(user.first_name, user.email) return redirect(reverse('core:thanks')) return render(request, 'core/lead_form_errors.html', context={'form': form})
def force_register_lead(first_name: str, email: str, source: str = 'unknown') -> _User: """ Create a new user on the system generation a random password. An Welcome email is sent to the user informing his password with the link to change it. User is also registered on Mailchimp. But she will be registeres even if api call fails :param first_name: User's first name :param email: User's email :param source: source of User traffic :return: User """ user = _core_facade.register_lead(first_name, email, source) try: _mailchimp_facade.create_or_update_lead(first_name, email) except _MailChimpError: pass return user
def test_update_user_no_role(existing_lead, resps): for id_ in roles_to_ids.values(): existing_lead['interests'][id_] = False resps.add(resps.GET, member_url, json=existing_lead, status=200) resps.add(resps.PATCH, member_url, json=existing_lead, status=200) interests = facade.create_or_update_lead('Renzo', '*****@*****.**')['interests'] assert_member_roles(expected_lead=True, expected_client=False, expected_member=False, interests=interests)
def register_lead(first_name: str, email: str, source: str = 'unknown') -> _User: """ Create a new user on the system generation a random password. An Welcome email is sent to the user informing his password with the link to change it. User is also registered on Mailchimp and subscribed to LeadWorkflow and is not registered on system in case api call fails Check force_register_lead if Maichimp validation is not mandatory :param first_name: User's first name :param email: User's email :param source: source of User traffic :return: User """ if not source: source = 'unknown' form = _core_facade.validate_user(first_name, email, source) try: _mailchimp_facade.create_or_update_lead(first_name, email) except _MailChimpError: form.add_error('email', 'Email Inválido') raise UserCreationException(form) return _core_facade.register_lead(first_name, email, source)