From 22863c2a34c1ba04e13b0e3e6898bfede7fdfa4e Mon Sep 17 00:00:00 2001 From: Joshua Crowgey Date: Mon, 25 Jun 2018 20:17:40 -0700 Subject: [PATCH] bugfix #343 missing default color --- gcalcli/gcalcli.py | 4 ++-- tests/test_gcalcli.py | 32 +++++++++++++++++++++++++++++--- 2 files changed, 31 insertions(+), 5 deletions(-) diff --git a/gcalcli/gcalcli.py b/gcalcli/gcalcli.py index 73091685..9291b80c 100755 --- a/gcalcli/gcalcli.py +++ b/gcalcli/gcalcli.py @@ -165,7 +165,6 @@ def _select_cals(self, selected_names): for cal_name in selected_names: matches = [] for self_cal in self.allCals: - print(self_cal['summary']) # For exact match, we should match only 1 entry and accept # the first entry. Should honor access role order since # it happens after _GetCached() @@ -186,7 +185,7 @@ def _select_cals(self, selected_names): @staticmethod def _LocalizeDateTime(dt): - if not hasattr(dt, 'tzinfo'): + if not hasattr(dt, 'tzinfo'): # Why are we skipping these? return dt if dt.tzinfo is None: return dt.replace(tzinfo=tzlocal()) @@ -1633,6 +1632,7 @@ def parse_reminder(rem): def parse_cal_names(cal_names): cal_colors = {} for name in cal_names: + cal_color = 'default' parts = name.split("#") parts_count = len(parts) if parts_count >= 1: diff --git a/tests/test_gcalcli.py b/tests/test_gcalcli.py index 60373627..7f60ded6 100644 --- a/tests/test_gcalcli.py +++ b/tests/test_gcalcli.py @@ -1,6 +1,8 @@ import os import sys from json import load +from datetime import datetime +from dateutil.tz import tzutc import pytest from apiclient.discovery import HttpMock, build @@ -9,6 +11,7 @@ get_color_parser, get_cal_query_parser, get_output_parser, + parse_cal_names, parse_reminder) TEST_DATA_DIR = os.path.dirname(os.path.abspath(__file__)) + '/data' @@ -86,7 +89,7 @@ def test_list(capsys, PatchedGCalI): def test_agenda(PatchedGCalI): - PatchedGCalI(calendar=['jcrowgey*#green']).AgendaQuery() + PatchedGCalI().AgendaQuery() def test_cal_query(capsys, PatchedGCalI): @@ -109,7 +112,7 @@ def test_cal_query(capsys, PatchedGCalI): def test_add_event(PatchedGCalI): - gcal = PatchedGCalI(calendar=['jcrowgey*#green']) + gcal = PatchedGCalI() title = 'test event' where = 'anywhere' start = 'now' @@ -121,7 +124,7 @@ def test_add_event(PatchedGCalI): def test_quick_add(PatchedGCalI): - gcal = PatchedGCalI(calendar=['jcrowgey*#green']) + gcal = PatchedGCalI() event_text = 'quick test event' reminder = '5m sms' gcal.QuickAddEvent(event_text, reminder=[reminder]) @@ -158,3 +161,26 @@ def test_parse_reminder(): rem = 'invalid reminder' assert parse_reminder(rem) is None + + +def test_parse_cal_names(PatchedGCalI): + cal_names = parse_cal_names(['j*#green']) + gcal = PatchedGCalI(cal_names=cal_names) + gcal.AgendaQuery() + + cal_names = parse_cal_names(['j*']) + gcal = PatchedGCalI(cal_names=cal_names) + gcal.AgendaQuery() + + cal_names = parse_cal_names(['jcrowgey@uw.edu']) + gcal = PatchedGCalI(cal_names=cal_names) + gcal.AgendaQuery() + + +def test_localized_datetime(PatchedGCalI): + dt = GoogleCalendarInterface._LocalizeDateTime(datetime.now()) + assert dt.tzinfo is not None + + dt = datetime.now(tzutc()) + dt = GoogleCalendarInterface._LocalizeDateTime(dt) + assert dt.tzinfo is not None