def test_no_label_mail_context_creation():
    client = Client()
    context_gmail, _, _ = client.get_email_context(MOCK_MAIL_NO_LABELS, "some_mail")
    assert context_gmail.get('Labels') == EXPECTED_GMAIL_CONTEXT.get('Labels')
    assert context_gmail.get('To') == EXPECTED_GMAIL_CONTEXT.get('To')
    assert context_gmail.get('From') == EXPECTED_GMAIL_CONTEXT.get('From')
    assert context_gmail.get('Subject') == EXPECTED_GMAIL_CONTEXT.get('Subject')
Beispiel #2
0
def test_no_date_mail():
    with open('test_data/email_no_date.json', 'r') as f:
        msg = json.load(f)
    client = Client()
    context_gmail, _, _, occurred, is_valid = client.get_email_context(msg, "some_mail")
    # check that the x-received date was usd
    assert occurred.timestamp() == parsedate_to_datetime('Mon, 21 Dec 2020 12:11:57 -0800').timestamp()
    assert is_valid
    assert context_gmail.get('Date') == 'Mon, 21 Dec 2020 12:11:57 -0800'
Beispiel #3
0
def test_no_label_mail_context_creation():
    client = Client()
    context_gmail, _, _, occurred, is_internal = client.get_email_context(MOCK_MAIL_NO_LABELS, "some_mail")
    assert int(occurred.timestamp()) == 1572251535
    assert is_internal
    assert context_gmail.get('Labels') == EXPECTED_GMAIL_CONTEXT.get('Labels')
    assert context_gmail.get('To') == EXPECTED_GMAIL_CONTEXT.get('To')
    assert context_gmail.get('From') == EXPECTED_GMAIL_CONTEXT.get('From')
    assert context_gmail.get('Subject') == EXPECTED_GMAIL_CONTEXT.get('Subject')
Beispiel #4
0
def test_header_to_date():
    valid_header_date = Client.get_date_from_email_header("Mon, 26 Aug 2019 14:40:04 +0300")
    semi_valid_header_date = Client.get_date_from_email_header("26 Aug 2019 14:40:04 +0300")
    header_date_no_tz = Client.get_date_from_email_header("26 Aug 2019 11:40:04")
    header_x_received = Client.get_date_from_email_header('by 2002:a17:90a:77cb:0:0:0:0 with SMTP id e11csp4670216pjs;        '
                                                          'Mon, 26 Aug 2019 03:40:04 -0800 (PST)')
    # all should be the same
    assert valid_header_date == semi_valid_header_date
    assert valid_header_date == header_date_no_tz
    assert header_x_received == valid_header_date
def test_timestamp_to_date():
    client = Client()
    valid_timestamp = '1566819604000'
    valid_header_date = "Mon, 26 Aug 2019 14:40:04 +0300"
    # this does contain the utc time change
    invalid_header_date = "25 Aug 2019 06:25:38"
    # this does contain the utc time change
    semi_valid_header_date = "26 Aug 2019 14:40:04 +0300"
    assert str(client.create_base_time(valid_timestamp, valid_header_date)) == "Mon, 26 Aug 2019 14:40:04 +0300"
    assert str(client.create_base_time(valid_timestamp, semi_valid_header_date)) == "Mon, 26 Aug 2019 14:40:04 +0300"
    assert str(client.create_base_time(valid_timestamp, invalid_header_date)) == "Mon, 26 Aug 2019 11:40:04 -0000"
Beispiel #6
0
def test_extract_occurred_no_headers():
    occurred, is_valid = Client.get_occurred_date({
        'payload': {
            'headers': [{'name': 'stam', 'value': 'stam'}]
        },
        'internalDate': '1610642469000'
    })
    assert is_valid
    assert occurred.timestamp() == 1610642469
def test_generate_auth_link():
    client = Client()
    link, challange = client.generate_auth_link()
    assert link.startswith('https://accounts.google.com/o/oauth2/v2/auth?')
    assert challange in link
    assert 'code_challenge_method=S256' in link
def test_move_to_gmt():
    client = Client()
    valid_header_date = "Mon, 26 Aug 2019 14:40:04 +0300"
    no_utc_header_date = "Mon, 26 Aug 2019 14:40:04 -0000"
    assert str(client.move_to_gmt(valid_header_date)) == "2019-08-26T11:40:04Z"
    assert str(client.move_to_gmt(no_utc_header_date)) == "2019-08-26T14:40:04Z"
Beispiel #9
0
def gmail_client(mocker):
    client = Client()
    mocker.patch.object(client, 'get_access_token', return_value='token')
    return client