def test_get_iso_date_throws_unhandled(self, url_read_mock):
        """ Test that file with ISO date returns the min date when url opener throws. """

        fake_url = 'http://fake_url'
        url_read_mock.side_effect = Exception()
        file_with_date = FileWithDate()

        self.assertRaises(Exception, lambda: file_with_date.get_datetime_from_content(fake_url))
        url_read_mock.assert_called_once_with(fake_url)
    def test_get_invalid_iso_date_json_throws(self, url_read_mock):
        """ Test that file with invalid ISO date in json format returns the min date."""

        fake_url = 'http://fake_url'
        url_read_mock.return_value = '{"date":"2008-13-32T00:42:18.000"}'
        file_with_date = FileWithDate()

        result = file_with_date.get_datetime_from_content(fake_url)

        url_read_mock.assert_called_once_with(fake_url)
        self.assertEqual(datetime.datetime.min, result)
    def test_get_iso_date_json_throws(self, url_read_mock):
        """ Test that file with ISO date returns the min date when json loader opener throws. """

        fake_url = 'http://fake_url'
        url_read_mock.return_value = "{date:X:" + datetime.datetime.now().isoformat() + "}"
        file_with_date = FileWithDate()

        result = file_with_date.get_datetime_from_content(fake_url)

        self.assertTrue(url_read_mock.assert_called_once)
        self.assertEqual(datetime.datetime.min, result)
    def test_get_iso_date_throws(self, url_read_mock):
        """ Test that file with ISO date returns the min date when url opener throws. """

        fake_url = 'http://fake_url'
        url_read_mock.side_effect = urllib.error.HTTPError(None, None, None, None, None)
        file_with_date = FileWithDate()

        result = file_with_date.get_datetime_from_content(fake_url)

        url_read_mock.assert_called_once_with(fake_url)
        self.assertEqual(datetime.datetime.min, result)
    def test_get_invalid_iso_date_json_throws(self, url_read_mock):
        """ Test that file with invalid ISO date in json format returns the min date."""

        fake_url = 'http://fake_url'
        url_read_mock.return_value = '{"date":"2008-13-32T00:42:18.000"}'
        file_with_date = FileWithDate()

        result = file_with_date.get_datetime_from_content(fake_url)

        url_read_mock.assert_called_once_with(fake_url)
        self.assertEqual(datetime.datetime.min, result)
    def test_get_iso_date_throws_unhandled(self, url_read_mock):
        """ Test that file with ISO date returns the min date when url opener throws. """

        fake_url = 'http://fake_url'
        url_read_mock.side_effect = Exception()
        file_with_date = FileWithDate()

        self.assertRaises(
            Exception,
            lambda: file_with_date.get_datetime_from_content(fake_url))
        url_read_mock.assert_called_once_with(fake_url)
    def test_get_iso_date(self, url_read_mock):
        """ Test that file with just ISO date returns the correct date. """

        fake_url = 'http://fake_url'
        expected_date = datetime.datetime.now()
        url_read_mock.return_value = expected_date.isoformat()
        file_with_date = FileWithDate()

        result = file_with_date.get_datetime_from_content(fake_url)

        url_read_mock.assert_called_once_with(fake_url)
        self.assertEqual(expected_date, result)
    def test_get_iso_date_json_throws(self, url_read_mock):
        """ Test that file with ISO date returns the min date when json loader opener throws. """

        fake_url = 'http://fake_url'
        url_read_mock.return_value = "{date:X:" + datetime.datetime.now(
        ).isoformat() + "}"
        file_with_date = FileWithDate()

        result = file_with_date.get_datetime_from_content(fake_url)

        self.assertTrue(url_read_mock.assert_called_once)
        self.assertEqual(datetime.datetime.min, result)
    def test_get_iso_date_throws(self, url_read_mock):
        """ Test that file with ISO date returns the min date when url opener throws. """

        fake_url = 'http://fake_url'
        url_read_mock.side_effect = urllib.error.HTTPError(
            None, None, None, None, None)
        file_with_date = FileWithDate()

        result = file_with_date.get_datetime_from_content(fake_url)

        url_read_mock.assert_called_once_with(fake_url)
        self.assertEqual(datetime.datetime.min, result)
    def test_get_iso_date(self, url_read_mock):
        """ Test that file with just ISO date returns the correct date. """

        fake_url = 'http://fake_url'
        expected_date = datetime.datetime.now()
        url_read_mock.return_value = expected_date.isoformat()
        file_with_date = FileWithDate()

        result = file_with_date.get_datetime_from_content(fake_url)

        url_read_mock.assert_called_once_with(fake_url)
        self.assertEqual(expected_date, result)