def test_delete_from_readonly_calendar(db, default_namespace, api_client): add_fake_event( db.session, default_namespace.id, calendar=db.session.query(Calendar).filter( Calendar.namespace_id == default_namespace.id, Calendar.read_only == True).first(), # noqa read_only=True) calendar_list = api_client.get_data('/calendars') read_only_calendar = None for c in calendar_list: if c['read_only']: read_only_calendar = c break events = api_client.get_data('/events?calendar_id={}'.format( read_only_calendar['id'])) for event in events: if event['read_only']: read_only_event = event break assert read_only_calendar assert read_only_event e_id = read_only_event['id'] resp = api_client.delete('/events/{}'.format(e_id)) assert resp.status_code == 400
def test_delete_from_readonly_calendar(db, default_namespace, api_client): add_fake_event(db.session, default_namespace.id, calendar=db.session.query(Calendar).filter( Calendar.namespace_id == default_namespace.id, Calendar.read_only == True).first(), # noqa read_only=True) calendar_list = api_client.get_data('/calendars') read_only_calendar = None for c in calendar_list: if c['read_only']: read_only_calendar = c break events = api_client.get_data('/events?calendar_id={}'.format( read_only_calendar['id'])) for event in events: if event['read_only']: read_only_event = event break assert read_only_calendar assert read_only_event e_id = read_only_event['id'] resp = api_client.delete('/events/{}'.format(e_id)) assert resp.status_code == 400
def test_action_scheduling(db, default_account): event = add_fake_event(db.session, default_account.namespace.id) schedule_action('create_event', event, default_account.namespace.id, db.session) db.session.commit() entry = db.session.query(ActionLog).filter( ActionLog.namespace_id == default_account.namespace.id, ActionLog.action == 'create_event').one() assert entry.discriminator == 'actionlog' assert entry.table_name == 'event' and entry.record_id == event.id assert not entry.extra_args schedule_action('delete_event', event, default_account.namespace.id, db.session, event_uid=event.uid, calendar_name=event.calendar.name, calendar_uid=event.calendar.uid) db.session.commit() entry = db.session.query(ActionLog).filter( ActionLog.namespace_id == default_account.namespace.id, ActionLog.action == 'delete_event').one() assert entry.discriminator == 'actionlog' assert entry.table_name == 'event' and entry.record_id == event.id assert entry.extra_args == \ dict(event_uid=event.uid, calendar_name=event.calendar.name, calendar_uid=event.calendar.uid)
def test_event_insert_creates_transaction(db, default_namespace): with db.session.no_autoflush: event = add_fake_event(db.session, default_namespace.id) transaction = get_latest_transaction(db.session, "event", event.id, default_namespace.id) assert transaction.record_id == event.id assert transaction.object_type == "event" assert transaction.command == "insert"
def test_event_insert_creates_transaction(db, default_namespace): with db.session.no_autoflush: event = add_fake_event(db.session, default_namespace.id) transaction = get_latest_transaction(db.session, 'event', event.id, default_namespace.id) assert transaction.record_id == event.id assert transaction.object_type == 'event' assert transaction.command == 'insert'
def test_api_update_read_only(db, api_client, calendar, default_namespace): add_fake_event(db.session, default_namespace.id, calendar=calendar, read_only=True) event_list = api_client.get_data('/events') read_only_event = None for e in event_list: if e['read_only']: read_only_event = e break assert read_only_event e_id = read_only_event['id'] e_update_data = {'title': 'new title'} e_put_resp = api_client.put_data('/events/' + e_id, e_update_data) assert e_put_resp.status_code != 200
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
def test_noop_event_update(db, default_namespace, calendar): event = add_fake_event(db.session, default_namespace.id, calendar=calendar, read_only=True) event.title = 'Test event' event.participants = [{'email': '*****@*****.**'}, {'email': '*****@*****.**'}] assert noop_event_update(event, {}) is True update = {'title': 'Test event'} assert noop_event_update(event, update) is True update = {'title': 'Different'} assert noop_event_update(event, update) is False update = {'location': 'Different'} assert noop_event_update(event, update) is False update = {'description': 'Different'} assert noop_event_update(event, update) is False update = {'when': {'start_time': 123453453, 'end_time': 1231231}} assert noop_event_update(event, update) is False event.when = {'start_time': 123453453, 'end_time': 1231231} update = {'when': {'start_time': 123453453, 'end_time': 1231231}} assert noop_event_update(event, update) is True update = {'participants': [{'email': '*****@*****.**'}, {'email': '*****@*****.**'}]} assert noop_event_update(event, update) is True update = {'participants': [{'email': '*****@*****.**', 'status': 'yes'}, {'email': '*****@*****.**'}]} assert noop_event_update(event, update) is False event.participants = [{'email': '*****@*****.**', 'status': 'yes'}, {'email': '*****@*****.**'}] update = {'participants': [{'email': '*****@*****.**', 'status': 'yes'}, {'email': '*****@*****.**'}]} assert noop_event_update(event, update) is True
def test_noop_event_update(db, default_namespace, calendar): event = add_fake_event(db.session, default_namespace.id, calendar=calendar, read_only=True) event.title = 'Test event' event.participants = [{ 'email': '*****@*****.**' }, { 'email': '*****@*****.**' }] assert noop_event_update(event, {}) is True update = {'title': 'Test event'} assert noop_event_update(event, update) is True update = {'title': 'Different'} assert noop_event_update(event, update) is False update = {'location': 'Different'} assert noop_event_update(event, update) is False update = {'description': 'Different'} assert noop_event_update(event, update) is False update = {'when': {'start_time': 123453453, 'end_time': 1231231}} assert noop_event_update(event, update) is False event.when = {'start_time': 123453453, 'end_time': 1231231} update = {'when': {'start_time': 123453453, 'end_time': 1231231}} assert noop_event_update(event, update) is True update = { 'participants': [{ 'email': '*****@*****.**' }, { 'email': '*****@*****.**' }] } assert noop_event_update(event, update) is True update = { 'participants': [{ 'email': '*****@*****.**', 'status': 'yes' }, { 'email': '*****@*****.**' }] } assert noop_event_update(event, update) is False event.participants = [{ 'email': '*****@*****.**', 'status': 'yes' }, { 'email': '*****@*****.**' }] update = { 'participants': [{ 'email': '*****@*****.**', 'status': 'yes' }, { 'email': '*****@*****.**' }] } assert noop_event_update(event, update) is True