Fix #1218
Output a track's Last-Modified stamp in ISO 8601 format, as MPD does. Output nothing if track has no last-modified stamp. The test has to use datetime to work out what the output will look like, because it is local-time zone dependant.
This commit is contained in:
parent
5c6ab0846e
commit
6d2ac7a100
@ -89,7 +89,7 @@ def track_to_mpd_format(track, position=None, stream_title=None):
|
||||
|
||||
if track.last_modified is not None:
|
||||
datestring = datetime.datetime.fromtimestamp(
|
||||
track.last_modified // 1000).strftime('%Y-%m-%dT%H:%M:%S%Z')
|
||||
track.last_modified // 1000).isoformat()
|
||||
result.append(('Last-Modified', datestring))
|
||||
|
||||
if track.musicbrainz_id is not None:
|
||||
|
||||
@ -1,5 +1,6 @@
|
||||
from __future__ import absolute_import, unicode_literals
|
||||
|
||||
import datetime
|
||||
import unittest
|
||||
|
||||
from mopidy.internal import path
|
||||
@ -81,6 +82,12 @@ class TrackMpdFormatTest(unittest.TestCase):
|
||||
|
||||
def test_track_to_mpd_format_with_last_modified(self):
|
||||
track = self.track.replace(last_modified=995303899000)
|
||||
# Due to this being local time-zone dependant, we have
|
||||
# to calculate what the Last-Modified output will look like
|
||||
# on the machine where the tests are being run. So this only tests
|
||||
# that the output is actually there.
|
||||
datestring = datetime.datetime.fromtimestamp(
|
||||
track.last_modified // 1000).isoformat()
|
||||
result = translator.track_to_mpd_format(track)
|
||||
self.assertIn(('file', 'a uri'), result)
|
||||
self.assertIn(('Time', 137), result)
|
||||
@ -94,7 +101,7 @@ class TrackMpdFormatTest(unittest.TestCase):
|
||||
self.assertIn(('Track', '7/13'), result)
|
||||
self.assertIn(('Date', '1977-01-01'), result)
|
||||
self.assertIn(('Disc', 1), result)
|
||||
self.assertIn(('Last-Modified', '2001-07-16T18:18:19'), result)
|
||||
self.assertIn(('Last-Modified', datestring), result)
|
||||
self.assertNotIn(('Comment', 'a comment'), result)
|
||||
self.assertEqual(len(result), 13)
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user