Пример #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="*****@*****.**")