async def execute(token: str, lead: LeadModel) -> Union[bool, Tuple[Dict[str, Union[str, List[str]]], bool]]: cache = await RedisBackend(settings.REDIS_URL).get_instance() is_valid: bool = await cache.is_valid_token(token) if is_valid: logger.info(f"Is valid token with data") res = await PublisherService.publish(lead.dict(), lead.by) logger.info(f"sent_to_queue: {bool(res)}, lead: {lead}") return lead.dict(), True return {"status": "error", "message": f"Token {token} is invalid"}, False
def test_with_group_A_yahoo(): lead = LeadModel(name="Maria Silva", phone_number="55912345678", email="*****@*****.**", is_term_accepted="True", origin="lpx") assert lead.group == "A"
def test_with_group_B(): lead = LeadModel( name="Maria Silva", phone_number="55912345678", email="*****@*****.**", is_term_accepted="True", origin="lpx", ) assert lead.group == "B"
def test_good_data(): lead = LeadModel(name="Maria Silva", phone_number="55912345678", email="*****@*****.**", is_term_accepted="True", origin="lpx") assert lead == { "name": "Maria Silva", "phone_number": "55912345678", "email": "*****@*****.**", "group": "A", "is_term_accepted": "True", "origin": "lpx", "by": "salesforce", }
def test_raise_error_with_letter_in_phone_number(): with pytest.raises(ValidationError) as ex: LeadModel(name="Maria Silva", phone_number="aa912345678", email="*****@*****.**")
def test_raise_error_with_wrong_email(): with pytest.raises(ValidationError) as ex: LeadModel(name="Maria Silva", phone_number="55912345678", email="maria@yahoo.")
def test_raise_error_with_short_phone_number(): with pytest.raises(ValidationError) as ex: LeadModel(name="Maria Silva", phone_number="345678", email="*****@*****.**")
def test_raise_error_with_wrong_name(): with pytest.raises(ValidationError) as ex: LeadModel(name="M", phone_number="55912345678", email="*****@*****.**")