Exemple #1
0
    def login(self):
        logging.info("Trying to log in.")

        # GET API INFO
        self.api_key = CONFIG.get_api_info()
        self.token = CONFIG.get_token()
        if(self.api_key is None or self.token is None):
            self.refresh_credentials()
            return
        logging.info(
            "Trello API key and token: %s", [self.api_key, self.token])

        if self.connection_tries > 1:
            self.refresh_credentials()
            return
        self.connection_tries += 1
        logging.info("Connections tries: %s", self.connection_tries)

        self.login_petition()
        if self.is_logged_in():
            logging.info("Log in successful")
            self.connection_tries = 0
        else:
            logging.warning("Login failed.")
            self.login()
Exemple #2
0
def set_config():
    try:
        file = sys.argv[1]
    except IndexError:
        file = "config/config.yml"
    logging.info("using file: %s", file)
    CONFIG.init(cfile=file)
    logging.info("config successfully loaded: %s", CONFIG.config)
    def setUp(self):
        self.conf_file = "config/config.test.yml.tmp"
        self.db_file = 'test_sent_to_cal.db'

        self.t_client = Trello_Client(self.db_file)

        copyfile("config/config.test.yml", self.conf_file)
        CONFIG.init(self.conf_file)
Exemple #4
0
 def get_board_id(self, board_name):
     try:
         if self.boards()[board_name]['id'] is None:
             return self.find_board_id(board_name)
         return self.boards()[board_name]['id']
     except (KeyError, exceptions.ResourceUnavailable) as e:
         logging.warning("Exception %s at get_board_id", e)
         CONFIG.get_config(['TRELLO', 'boards', board_name, 'id'])
         return self.get_board_id(board_name)
Exemple #5
0
 def get_list_id(self, board_name, list_name):
     board_config = self.boards()[board_name]
     try:
         if board_config[list_name] is None:
             return self.find_list_id(board_config, board_name, list_name)
         return self.boards()[board_name][list_name]["id"]
     except KeyError:
         CONFIG.get_config(['TRELLO', 'boards', board_name, list_name])
         return self.get_list_id(board_name, list_name)
Exemple #6
0
    def refresh_credentials(self):
        logging.warning("Unauthorized. Client: %s", self.client)

        print("Time to refresh credentials!")
        print("Log in to trello at https://trello.com,\
            then visit https://trello.com/app-key")

        self.api_key = input("Trello API key: ")
        CONFIG.write_config(["TRELLO", "api_key"], self.api_key)

        self.token = input("Trello token: ")
        CONFIG.write_config(["TRELLO", "token"], self.token)

        self.login_petition()
Exemple #7
0
 def init(self, config_file=None):
     if config_file is not None:
         logging.info("Initialising config %s from Calendar_Client.",
                      config_file)
         CONFIG.init(cfile=config_file)
     url = CONFIG.get_cal_url()
     logging.info("connecting to %s", url)
     try:
         client = caldav.DAVClient(url)
     except KeyError:
         CONFIG.request_calendar()
         client = caldav.DAVClient(CONFIG.get_cal_url())
     principal = client.principal()
     calendars = principal.calendars()
     if calendars:
         self.calendar = calendars[0]
Exemple #8
0
 def test_write_config_saved_to_disc(self):
     CONFIG.write_config(["CALENDAR", "user"], "flamingo")
     CONFIG.load_config(self.conf_file)
     value = CONFIG.get_config(["CALENDAR", "user"])
     self.assertEqual(value, "flamingo")
Exemple #9
0
 def setUp(self):
     self.conf_file = "config/config.test.yml.tmp"
     copyfile("config/config.test.yml", self.conf_file)
     CONFIG.init(cfile=self.conf_file)
 def test_login__wrong_credentials(self, mock):
     CONFIG.write_config(['TRELLO', 'token'], "1")
     self.t_client.login()
     self.assertTrue(mock.called)
Exemple #11
0
 def test_load_correct_config(self):
     value = CONFIG.get_config(["CALENDAR", "user"])
     self.assertEqual(value, "test")
Exemple #12
0
 def boards(self):
     return CONFIG.get_config(['TRELLO', 'boards']) or dict()
Exemple #13
0
 def test_trello_config(self):
     value = CONFIG.get_config(["TRELLO", "boards", "default", "id"])
     self.assertEqual(value, "5bd9b0bbf266e64d059403fa")
Exemple #14
0
 def list_to_yaml(self, board_name, list_name, list_id):
     CONFIG.write_config(
         ['TRELLO', 'boards', board_name, list_name, 'id'], list_id)
Exemple #15
0
 def board_to_yaml(self, name, board_id):
     CONFIG.write_config(['TRELLO', 'boards', name, 'id'], board_id)
Exemple #16
0
 def test_write_config_running(self):
     CONFIG.write_config(["CALENDAR", "user"], "flamingo")
     value = CONFIG.get_config(["CALENDAR", "user"])
     self.assertEqual(value, "flamingo")
 def test_login__no_token(self, mock):
     CONFIG.write_config(['TRELLO', 'token'], None)
     self.t_client.login()
     self.assertTrue(mock.called)
Exemple #18
0
 def test_write_config_running_multi_inexistant_field(self):
     CONFIG.write_config(["CALENDAR", "box", "colour", "id"], "5")
     value = CONFIG.get_config(["CALENDAR", "box", "colour", "id"])
     self.assertEqual(value, "5")
Exemple #19
0
 def test_write_config_running_single_inexistant_field(self):
     CONFIG.write_config(["CALENDAR", "colour"], "pink")
     value = CONFIG.get_config(["CALENDAR", "colour"])
     self.assertEqual(value, "pink")