示例#1
0
    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
示例#2
0
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"
示例#3
0
def test_with_group_B():
    lead = LeadModel(
        name="Maria Silva",
        phone_number="55912345678",
        email="*****@*****.**",
        is_term_accepted="True",
        origin="lpx",
    )
    assert lead.group == "B"
示例#4
0
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",
    }
示例#5
0
def test_raise_error_with_letter_in_phone_number():
    with pytest.raises(ValidationError) as ex:
        LeadModel(name="Maria Silva",
                  phone_number="aa912345678",
                  email="*****@*****.**")
示例#6
0
def test_raise_error_with_wrong_email():
    with pytest.raises(ValidationError) as ex:
        LeadModel(name="Maria Silva",
                  phone_number="55912345678",
                  email="maria@yahoo.")
示例#7
0
def test_raise_error_with_short_phone_number():
    with pytest.raises(ValidationError) as ex:
        LeadModel(name="Maria Silva",
                  phone_number="345678",
                  email="*****@*****.**")
示例#8
0
def test_raise_error_with_wrong_name():
    with pytest.raises(ValidationError) as ex:
        LeadModel(name="M",
                  phone_number="55912345678",
                  email="*****@*****.**")