예제 #1
0
def test_parse_to_list_tuple_of_dict():
    data = [{
        'email': '*****@*****.**',
        'name': 'Ivan1'
    }, {
        'email': '*****@*****.**',
        'name': 'Ivan2'
    }, {
        'email': '*****@*****.**',
        'name': 'Ivan3'
    }]
    result = [{
        'email': '*****@*****.**',
        'name': 'Ivan1'
    }, {
        'email': '*****@*****.**',
        'name': 'Ivan2'
    }, {
        'email': '*****@*****.**',
        'name': 'Ivan3'
    }]
    parsed_list = Sendgrid()._parse_to_emails(data)
    assert parsed_list == result
    data_tuple = tuple(data)
    parsed_tuple = Sendgrid()._parse_to_emails(data_tuple)
    assert parsed_tuple == result
예제 #2
0
def sendgrid():
    sg = Sendgrid(api_key="blah")

    async def mock_post(_, __, payload):
        return payload

    sg._post = mock_post
    return sg
def send_email_async(from_address: str, to_addresses: list, subject: str, body_html: str,
                     cc_addresses: list=None, bcc_addresses: list=None):
    api_key = config.sendgrid['api_token']

    mailer = Sendgrid(api_key=api_key)

    email = mailer.send(to=to_addresses, sender=from_address, subject=subject, content=body_html)
    loop = asyncio.get_event_loop()
    loop.run_until_complete(email)
예제 #4
0
def test_parse_from_wrong_input():
    no_email = {'hello': 'world'}
    with pytest.raises(TypeError):
        Sendgrid()._parse_from_email(no_email)
    integer = 1
    val_set = {1}
    with pytest.raises(ValueError):
        Sendgrid()._parse_from_email(integer)
        Sendgrid()._parse_from_email(val_set)
예제 #5
0
def test_parse_to_wrong_input():
    no_email = {'hello': 'world'}
    with pytest.raises(TypeError):
        Sendgrid()._parse_to_emails(no_email)
    integer = 1
    val_set = {1}
    invalid_list = ['*****@*****.**', 1]
    invalid_tuple = ('*****@*****.**', 1)
    with pytest.raises(ValueError):
        Sendgrid()._parse_to_emails(integer)
        Sendgrid()._parse_to_emails(val_set)
        Sendgrid()._parse_to_emails(invalid_list)
        Sendgrid()._parse_to_emails(invalid_tuple)
예제 #6
0
def test_parse_to_str():
    data = '*****@*****.**'
    parsed_email = Sendgrid()._parse_to_emails(data)
    assert parsed_email == [{'email': '*****@*****.**'}]
예제 #7
0
def test_parse_to_dict_no_name():
    data = {'email': '*****@*****.**'}
    parsed_email = Sendgrid()._parse_to_emails(data)
    assert parsed_email == [{'email': '*****@*****.**'}]
예제 #8
0
def test_generate_email_with_name():
    email = '*****@*****.**'
    name = 'Ivan'
    generated_email = Sendgrid._generate_email(email=email, name=name)
    assert generated_email == {'email': '*****@*****.**', 'name': 'Ivan'}
예제 #9
0
def test_generate_email_no_name():
    email = '*****@*****.**'
    generated_email = Sendgrid._generate_email(email=email)
    assert generated_email == {'email': '*****@*****.**'}
예제 #10
0
def mailer():
    mailer = Sendgrid()
    return mailer
예제 #11
0
def test_parse_from_str():
    data = '*****@*****.**'
    parsed_email = Sendgrid()._parse_from_email(data)
    assert parsed_email == {'email': '*****@*****.**'}
예제 #12
0
def test_parse_from_dict():
    data = {'email': '*****@*****.**', 'name': 'Ivan'}
    parsed_email = Sendgrid()._parse_from_email(data)
    assert parsed_email == {'email': '*****@*****.**', 'name': 'Ivan'}