Example #1
0
def test_event_update(db, default_account, message):
    add_fake_calendar(db.session,
                      default_account.namespace.id,
                      name="Emailed events",
                      read_only=True)

    with open(absolute_path(FIXTURES + 'gcal_v1.ics')) as fd:
        ics_data = fd.read()

    msg = add_fake_msg_with_calendar_part(db.session, default_account,
                                          ics_data)

    import_attached_events(db.session, default_account, msg)
    db.session.commit()

    ev = db.session.query(Event).filter(
        Event.uid == "*****@*****.**").one()

    assert ev.location == ("Olympia Hall, 28 Boulevard des Capucines, "
                           "75009 Paris, France")

    with open(absolute_path(FIXTURES + 'gcal_v2.ics')) as fd:
        ics_data = fd.read()

    msg = add_fake_msg_with_calendar_part(db.session, default_account,
                                          ics_data)

    import_attached_events(db.session, default_account, msg)
    db.session.commit()

    ev = db.session.query(Event).filter(
        Event.uid == "*****@*****.**").one()

    assert ev.location == (u"Le Zenith, 211 Avenue Jean Jaures, "
                           "75019 Paris, France")
Example #2
0
def test_event_update(db, default_account, message):
    add_fake_calendar(db.session, default_account.namespace.id, name="Emailed events", read_only=True)

    with open(absolute_path(FIXTURES + "gcal_v1.ics")) as fd:
        ics_data = fd.read()

    msg = add_fake_msg_with_calendar_part(db.session, default_account, ics_data)

    import_attached_events(db.session, default_account, msg)
    db.session.commit()

    ev = db.session.query(Event).filter(Event.uid == "*****@*****.**").one()

    assert ev.location == ("Olympia Hall, 28 Boulevard des Capucines, " "75009 Paris, France")

    with open(absolute_path(FIXTURES + "gcal_v2.ics")) as fd:
        ics_data = fd.read()

    msg = add_fake_msg_with_calendar_part(db.session, default_account, ics_data)

    import_attached_events(db.session, default_account, msg)
    db.session.commit()

    ev = db.session.query(Event).filter(Event.uid == "*****@*****.**").one()

    assert ev.location == (u"Le Zenith, 211 Avenue Jean Jaures, " "75019 Paris, France")
Example #3
0
def test_self_sent_update(db, default_account, message):

    # Create the calendars
    add_fake_calendar(db.session,
                      default_account.namespace.id,
                      name="Emailed events",
                      read_only=True)

    default_calendar = add_fake_calendar(db.session,
                                         default_account.namespace.id,
                                         name="Calendar",
                                         read_only=False)

    # Import the self-sent event.
    with open(absolute_path(FIXTURES + 'self_sent_v1.ics')) as fd:
        ics_data = fd.read()

    msg = add_fake_msg_with_calendar_part(db.session, default_account,
                                          ics_data)
    msg.from_addr = [(default_account.name, default_account.email_address)]
    import_attached_events(db.session, default_account, msg)
    db.session.commit()

    evs = db.session.query(Event).filter(
        Event.uid == "*****@*****.**").all()

    assert len(evs) == 1
    ev = evs[0]
    assert ev.location == ("Olympia Hall, 28 Boulevard des Capucines, "
                           "75009 Paris, France")

    # Create a copy of the event, and store it in the default calendar.
    event_copy = Event()
    event_copy.update(ev)
    event_copy.calendar = default_calendar
    db.session.add(event_copy)
    db.session.commit()

    with open(absolute_path(FIXTURES + 'self_sent_v2.ics')) as fd:
        ics_data = fd.read()

    msg = add_fake_msg_with_calendar_part(db.session, default_account,
                                          ics_data)

    import_attached_events(db.session, default_account, msg)
    db.session.commit()

    evs = db.session.query(Event).filter(
        Event.uid == "*****@*****.**").all()

    # Check that the event in the default calendar didn't get updated.
    assert len(evs) == 2
    for ev in evs:
        db.session.refresh(ev)
        if ev.calendar_id == default_calendar.id:
            assert ev.location == ("Olympia Hall, 28 Boulevard des Capucines, "
                                   "75009 Paris, France")
        else:
            assert ev.location == (u"Le Zenith, 211 Avenue Jean Jaures, "
                                   "75019 Paris, France")
Example #4
0
def test_icalendar_import(db, generic_account, message):
    add_fake_calendar(db.session, generic_account.namespace.id, name="Emailed events", read_only=True)

    with open(absolute_path(FIXTURES + "invite_w_rsvps1.ics")) as fd:
        ics_data = fd.read()

    msg = add_fake_msg_with_calendar_part(db.session, generic_account, ics_data)

    import_attached_events(db.session, generic_account, msg)

    ev = (
        db.session.query(Event)
        .filter(
            Event.uid
            == (
                "040000008200E00074C5B7101A82E00800000000"
                "F9125A30B06BD001000000000000000010000000"
                "9D791C7548BFD144BFA54F14213CAD25"
            )
        )
        .one()
    )

    assert len(ev.participants) == 2
    for participant in ev.participants:
        assert participant["status"] == "noreply"
Example #5
0
def test_self_sent_update(db, default_account, message):

    # Create the calendars
    add_fake_calendar(db.session, default_account.namespace.id, name="Emailed events", read_only=True)

    default_calendar = add_fake_calendar(db.session, default_account.namespace.id, name="Calendar", read_only=False)

    # Import the self-sent event.
    with open(absolute_path(FIXTURES + "self_sent_v1.ics")) as fd:
        ics_data = fd.read()

    msg = add_fake_msg_with_calendar_part(db.session, default_account, ics_data)
    msg.from_addr = [(default_account.name, default_account.email_address)]
    import_attached_events(db.session, default_account, msg)
    db.session.commit()

    evs = db.session.query(Event).filter(Event.uid == "*****@*****.**").all()

    assert len(evs) == 1
    ev = evs[0]
    assert ev.location == ("Olympia Hall, 28 Boulevard des Capucines, " "75009 Paris, France")

    # Create a copy of the event, and store it in the default calendar.
    event_copy = Event()
    event_copy.update(ev)
    event_copy.calendar = default_calendar
    db.session.add(event_copy)
    db.session.commit()

    with open(absolute_path(FIXTURES + "self_sent_v2.ics")) as fd:
        ics_data = fd.read()

    msg = add_fake_msg_with_calendar_part(db.session, default_account, ics_data)

    import_attached_events(db.session, default_account, msg)
    db.session.commit()

    evs = db.session.query(Event).filter(Event.uid == "*****@*****.**").all()

    # Check that the event in the default calendar didn't get updated.
    assert len(evs) == 2
    for ev in evs:
        db.session.refresh(ev)
        if ev.calendar_id == default_calendar.id:
            assert ev.location == ("Olympia Hall, 28 Boulevard des Capucines, " "75009 Paris, France")
        else:
            assert ev.location == (u"Le Zenith, 211 Avenue Jean Jaures, " "75019 Paris, France")
Example #6
0
def test_icalendar_import(db, generic_account, message):
    add_fake_calendar(db.session,
                      generic_account.namespace.id,
                      name="Emailed events",
                      read_only=True)

    with open(absolute_path(FIXTURES + 'invite_w_rsvps1.ics')) as fd:
        ics_data = fd.read()

    msg = add_fake_msg_with_calendar_part(db.session, generic_account,
                                          ics_data)

    import_attached_events(db.session, generic_account, msg)

    ev = db.session.query(Event).filter(
        Event.uid == ("040000008200E00074C5B7101A82E00800000000"
                      "F9125A30B06BD001000000000000000010000000"
                      "9D791C7548BFD144BFA54F14213CAD25")).one()

    assert len(ev.participants) == 2
    for participant in ev.participants:
        assert participant['status'] == 'noreply'
Example #7
0
def add_completely_fake_account(db, email='*****@*****.**'):
    from inbox.models.backends.gmail import GmailAuthCredentials
    fake_account = add_fake_gmail_account(db.session, email_address=email)
    calendar = add_fake_calendar(db.session, fake_account.namespace.id)
    for i in random_range(1, 10):
        add_fake_event(db.session,
                       fake_account.namespace.id,
                       calendar=calendar,
                       title='%s' % i)

    # Add fake Threads, Messages and ImapUids.
    folder = add_fake_folder(db.session, fake_account)
    for i in random_range(1, 4):
        th = add_fake_thread(db.session, fake_account.namespace.id)

        for j in random_range(1, 3):
            msg = add_fake_msg_with_calendar_part(db.session,
                                                  fake_account,
                                                  'fake part',
                                                  thread=th)
            db.session.add(msg)
            db.session.flush()

            for k in random_range(1, 2):
                add_fake_imapuid(db.session, fake_account.id, msg, folder,
                                 int('%s%s' % (msg.id, k)))
    # Add fake contacts
    for i in random_range(1, 5):
        add_fake_contact(db.session, fake_account.namespace.id, uid=str(i))

    auth_creds = GmailAuthCredentials()
    auth_creds.gmailaccount = fake_account
    auth_creds.scopes = "email"
    auth_creds.g_id_token = "test"
    auth_creds.client_id = "test"
    auth_creds.client_secret = "test"
    auth_creds.refresh_token = "test"
    auth_creds.is_valid = True
    db.session.add(auth_creds)
    db.session.commit()

    return fake_account
Example #8
0
def add_completely_fake_account(db, email='*****@*****.**'):
    from inbox.models.backends.gmail import GmailAuthCredentials
    fake_account = add_fake_gmail_account(db.session, email_address=email)
    calendar = add_fake_calendar(db.session, fake_account.namespace.id)
    for i in random_range(1, 10):
        add_fake_event(db.session, fake_account.namespace.id,
                       calendar=calendar, title='%s' % i)

    # Add fake Threads, Messages and ImapUids.
    folder = add_fake_folder(db.session, fake_account)
    for i in random_range(1, 4):
        th = add_fake_thread(db.session, fake_account.namespace.id)

        for j in random_range(1, 3):
            msg = add_fake_msg_with_calendar_part(db.session,
                                                  fake_account,
                                                  'fake part', thread=th)
            db.session.add(msg)
            db.session.flush()

            for k in random_range(1, 2):
                add_fake_imapuid(db.session, fake_account.id, msg, folder,
                                 int('%s%s' % (msg.id, k)))
    # Add fake contacts
    for i in random_range(1, 5):
        add_fake_contact(db.session, fake_account.namespace.id, uid=str(i))

    auth_creds = GmailAuthCredentials()
    auth_creds.gmailaccount = fake_account
    auth_creds.scopes = "email"
    auth_creds.g_id_token = "test"
    auth_creds.client_id = "test"
    auth_creds.client_secret = "test"
    auth_creds.refresh_token = "test"
    auth_creds.is_valid = True
    db.session.add(auth_creds)
    db.session.commit()

    return fake_account
Example #9
0
def test_rsvp_merging(db, generic_account, message):
    # This test checks that RSVPs to invites we sent get merged.
    # It does some funky stuff around calendars because by default
    # autoimported invites end up in the "emailed events" calendar.
    # However, we're simulating invite sending, which supposes using
    # an event from another calendar.
    add_fake_calendar(db.session,
                      generic_account.namespace.id,
                      name="Emailed events",
                      read_only=True)
    cal2 = add_fake_calendar(db.session,
                             generic_account.namespace.id,
                             name="Random calendar",
                             read_only=True)

    with open(absolute_path(FIXTURES + 'invite_w_rsvps1.ics')) as fd:
        ics_data = fd.read()

    msg = add_fake_msg_with_calendar_part(db.session, generic_account,
                                          ics_data)

    import_attached_events(db.session, generic_account, msg)

    ev = db.session.query(Event).filter(
        Event.uid == ("040000008200E00074C5B7101A82E00800000000"
                      "F9125A30B06BD001000000000000000010000000"
                      "9D791C7548BFD144BFA54F14213CAD25")).one()

    assert len(ev.participants) == 2
    for participant in ev.participants:
        assert participant['status'] == 'noreply'

    ev.public_id = "cccc"
    ev.calendar = cal2

    with open(absolute_path(FIXTURES + 'invite_w_rsvps2.ics')) as fd:
        ics_data = fd.read()

    msg2 = add_fake_msg_with_calendar_part(db.session, generic_account,
                                           ics_data)

    import_attached_events(db.session, generic_account, msg2)

    ev = db.session.query(Event).filter(
        Event.uid == ("040000008200E00074C5B7101A82E00800000000"
                      "F9125A30B06BD001000000000000000010000000"
                      "9D791C7548BFD144BFA54F14213CAD25")).one()

    assert len(ev.participants) == 2
    for participant in ev.participants:
        if participant['email'] == '*****@*****.**':
            assert participant['status'] == 'maybe'
            assert participant['name'] == 'Inbox Apptest'
        elif participant['email'] == '*****@*****.**':
            assert participant['status'] == 'noreply'

    with open(absolute_path(FIXTURES + 'invite_w_rsvps3.ics')) as fd:
        ics_data = fd.read()

    msg3 = add_fake_msg_with_calendar_part(db.session, generic_account,
                                           ics_data)

    import_attached_events(db.session, generic_account, msg3)

    ev = db.session.query(Event).filter(
        Event.uid == ("040000008200E00074C5B7101A82E00800000000"
                      "F9125A30B06BD001000000000000000010000000"
                      "9D791C7548BFD144BFA54F14213CAD25")).one()

    assert len(ev.participants) == 2

    for participant in ev.participants:
        if participant['email'] == '*****@*****.**':
            assert participant['status'] == 'maybe'
            assert participant['name'] == 'Inbox Apptest'
        elif participant['email'] == '*****@*****.**':
            assert participant['name'] == 'Karim Hamidou'
            assert participant['status'] == 'yes'

    # Check that we're handling sequence numbers correctly - i.e: an RSVP
    # with a sequence number < to the event's sequence number should be
    # discarded.
    ev.sequence_number += 1

    with open(absolute_path(FIXTURES + 'invite_w_rsvps_4.ics')) as fd:
        ics_data = fd.read()

    msg4 = add_fake_msg_with_calendar_part(db.session, generic_account,
                                           ics_data)

    import_attached_events(db.session, generic_account, msg3)

    ev = db.session.query(Event).filter(
        Event.uid == ("040000008200E00074C5B7101A82E00800000000"
                      "F9125A30B06BD001000000000000000010000000"
                      "9D791C7548BFD144BFA54F14213CAD25")).one()

    assert len(ev.participants) == 2
    for participant in ev.participants:
        if participant['email'] == '*****@*****.**':
            assert participant['status'] == 'maybe'
            assert participant['name'] == 'Inbox Apptest'
        elif participant['email'] == '*****@*****.**':
            assert participant['name'] == 'Karim Hamidou'
            assert participant['status'] == 'yes'
Example #10
0
def test_rsvp_merging(db, generic_account, message):
    # This test checks that RSVPs to invites we sent get merged.
    # It does some funky stuff around calendars because by default
    # autoimported invites end up in the "emailed events" calendar.
    # However, we're simulating invite sending, which supposes using
    # an event from another calendar.
    add_fake_calendar(db.session, generic_account.namespace.id, name="Emailed events", read_only=True)
    cal2 = add_fake_calendar(db.session, generic_account.namespace.id, name="Random calendar", read_only=True)

    with open(absolute_path(FIXTURES + "invite_w_rsvps1.ics")) as fd:
        ics_data = fd.read()

    msg = add_fake_msg_with_calendar_part(db.session, generic_account, ics_data)

    import_attached_events(db.session, generic_account, msg)

    ev = (
        db.session.query(Event)
        .filter(
            Event.uid
            == (
                "040000008200E00074C5B7101A82E00800000000"
                "F9125A30B06BD001000000000000000010000000"
                "9D791C7548BFD144BFA54F14213CAD25"
            )
        )
        .one()
    )

    assert len(ev.participants) == 2
    for participant in ev.participants:
        assert participant["status"] == "noreply"

    ev.public_id = "cccc"
    ev.calendar = cal2

    with open(absolute_path(FIXTURES + "invite_w_rsvps2.ics")) as fd:
        ics_data = fd.read()

    msg2 = add_fake_msg_with_calendar_part(db.session, generic_account, ics_data)

    import_attached_events(db.session, generic_account, msg2)

    ev = (
        db.session.query(Event)
        .filter(
            Event.uid
            == (
                "040000008200E00074C5B7101A82E00800000000"
                "F9125A30B06BD001000000000000000010000000"
                "9D791C7548BFD144BFA54F14213CAD25"
            )
        )
        .one()
    )

    assert len(ev.participants) == 2
    for participant in ev.participants:
        if participant["email"] == "*****@*****.**":
            assert participant["status"] == "maybe"
            assert participant["name"] == "Inbox Apptest"
        elif participant["email"] == "*****@*****.**":
            assert participant["status"] == "noreply"

    with open(absolute_path(FIXTURES + "invite_w_rsvps3.ics")) as fd:
        ics_data = fd.read()

    msg3 = add_fake_msg_with_calendar_part(db.session, generic_account, ics_data)

    import_attached_events(db.session, generic_account, msg3)

    ev = (
        db.session.query(Event)
        .filter(
            Event.uid
            == (
                "040000008200E00074C5B7101A82E00800000000"
                "F9125A30B06BD001000000000000000010000000"
                "9D791C7548BFD144BFA54F14213CAD25"
            )
        )
        .one()
    )

    assert len(ev.participants) == 2

    for participant in ev.participants:
        if participant["email"] == "*****@*****.**":
            assert participant["status"] == "maybe"
            assert participant["name"] == "Inbox Apptest"
        elif participant["email"] == "*****@*****.**":
            assert participant["name"] == "Karim Hamidou"
            assert participant["status"] == "yes"

    # Check that we're handling sequence numbers correctly - i.e: an RSVP
    # with a sequence number < to the event's sequence number should be
    # discarded.
    ev.sequence_number += 1

    with open(absolute_path(FIXTURES + "invite_w_rsvps_4.ics")) as fd:
        ics_data = fd.read()

    msg4 = add_fake_msg_with_calendar_part(db.session, generic_account, ics_data)

    import_attached_events(db.session, generic_account, msg3)

    ev = (
        db.session.query(Event)
        .filter(
            Event.uid
            == (
                "040000008200E00074C5B7101A82E00800000000"
                "F9125A30B06BD001000000000000000010000000"
                "9D791C7548BFD144BFA54F14213CAD25"
            )
        )
        .one()
    )

    assert len(ev.participants) == 2
    for participant in ev.participants:
        if participant["email"] == "*****@*****.**":
            assert participant["status"] == "maybe"
            assert participant["name"] == "Inbox Apptest"
        elif participant["email"] == "*****@*****.**":
            assert participant["name"] == "Karim Hamidou"
            assert participant["status"] == "yes"