Beispiel #1
0
 def test_format_date(self):
     date = datetime.date(2015, 1, 30)
     cases = {
         "d. M. yyyy": "30. 1. 2015",
         "d.M.yyyy": "30.1.2015",
         "d.MM.yyyy": "30.01.2015",
         "d/M/yy": "30/1/15",
         "d/M/yyyy": "30/1/2015",
         "d/MM/yyyy": "30/01/2015",
         "dd MMM yy": "30 Jan 15",
         "dd.MM.yyyy": "30.01.2015",
         "dd.MM.yyyy.": "30.01.2015.",
         "dd.MMM.yyyy": "30.Jan.2015",
         "dd/MM/yy": "30/01/15",
         "dd/MM/yyyy": "30/01/2015",
         "dd/MMM/yyyy": "30/Jan/2015",
         "dd-MM-yy": "30-01-15",
         "dd-MM-yyyy": "30-01-2015",
         "d-M-yyyy": "30-1-2015",
         "M/d/yyyy": "1/30/2015",
         "MM/dd/yyyy": "01/30/2015",
         "MMM/dd/yyyy": "Jan/30/2015",
         "yyyy.MM.dd.": "2015.01.30.",
         "yyyy/MM/dd": "2015/01/30",
         "yyyy-MM-dd": "2015-01-30",
     }
     for user_format, ref_result in cases.items():
         self.assertEqual(format_date(date, user_format), ref_result)
Beispiel #2
0
    def post_log(self, log, tracking_code):
        """Post a log for this trackable.

        :param .Log log: Previously created :class:`Log` filled with data.
        :param str tracking_code: A tracking code to verify current trackable holder.
        """
        if not log.text:
            raise errors.ValueError("Log text is empty")

        valid_types, hidden_inputs, date_format = self._load_log_page()
        if log.type.value not in valid_types:
            raise errors.ValueError(
                "The trackable does not accept this type of log")

        # assemble post data
        post = hidden_inputs
        formatted_date = format_date(log.visited, date_format)
        post[
            "ctl00$ContentBody$LogBookPanel1$btnSubmitLog"] = "Submit Log Entry"
        post["ctl00$ContentBody$LogBookPanel1$ddLogType"] = log.type.value
        post["ctl00$ContentBody$LogBookPanel1$uxDateVisited"] = formatted_date
        post["ctl00$ContentBody$LogBookPanel1$tbCode"] = tracking_code
        post["ctl00$ContentBody$LogBookPanel1$uxLogInfo"] = log.text

        self.geocaching._request(self._log_page_url, method="POST", data=post)
Beispiel #3
0
    def test_load_log_page(self):
        expected_types = {
            t.value
            for t in (LogType.grabbed_it, LogType.note, LogType.discovered_it)
        }
        expected_inputs = "__EVENTTARGET", "__VIEWSTATE"  # and more ...

        # make request
        with self.recorder.use_cassette("trackable_load_page"):
            valid_types, hidden_inputs, user_date_format = self.t._load_log_page(
            )

        self.assertSequenceEqual(expected_types, valid_types)
        for i in expected_inputs:
            self.assertIn(i, hidden_inputs.keys())

        # user_date_format should not raise an exception when further processed
        format_date(date(2020, 12, 31), user_date_format)
Beispiel #4
0
    def post_log(self, log):
        """Post a log for this cache.

        :param .Log log: Previously created :class:`Log` filled with data.
        """
        if not log.text:
            raise errors.ValueError("Log text is empty")

        valid_types, hidden_inputs, date_format = self._load_log_page()
        if log.type.value not in valid_types:
            raise errors.ValueError("The Cache does not accept this type of log")

        # assemble post data
        post = hidden_inputs
        formatted_date = format_date(log.visited, date_format)
        post["ctl00$ContentBody$LogBookPanel1$btnSubmitLog"] = "Submit Log Entry"
        post["ctl00$ContentBody$LogBookPanel1$ddLogType"] = valid_types[log.type.value]
        post["ctl00$ContentBody$LogBookPanel1$uxDateVisited"] = formatted_date
        post["ctl00$ContentBody$LogBookPanel1$uxLogInfo"] = log.text

        self.geocaching._request(self._log_page_url, method="POST", data=post)