Ran test to ensure it works

This commit is contained in:
Austin Marino 2019-10-14 17:02:39 -07:00
parent db5d21620b
commit 0d818eced5
2 changed files with 50 additions and 25 deletions

View file

@ -67,13 +67,11 @@ class ExportPlugin(BeetsPlugin):
# XML module formatting options.
'formatting': {
# The output encoding.
'encoding': 'unicode',
'encoding': 'utf-8',
# Controls if XML declaration should be added to the file.
'xml_declaration': True,
# Can be either "xml", "html" or "text" (default is "xml").
'method': 'xml',
# Controls formatting of elements that contain no content.
'short_empty_elements': True
'method': 'xml'
}
}
# TODO: Use something like the edit plugin

View file

@ -20,6 +20,8 @@ from __future__ import division, absolute_import, print_function
import unittest
from test.helper import TestHelper
import re
class ExportPluginTest(unittest.TestCase, TestHelper):
def setUp(self):
@ -31,36 +33,61 @@ class ExportPluginTest(unittest.TestCase, TestHelper):
self.teardown_beets()
def execute_command(self, format_type, artist):
options = ' -f %s -i "track,album" s'.format(format_type, artist)
actual = self.run_with_output('export', options)
return actual.replace(" ", "")
def create_item(self, album='talbum', artist='tartist', track='ttrack'):
item1, = self.add_item_fixtures()
item1.album = album
item1.artist = artist
item1.track = track
item1.write()
item1.store()
return item1
actual = self.run_with_output(
'export',
'-f', format_type,
'-i', 'album,title',
artist
)
return re.sub("\\s+", '', actual)
def create_item(self):
item, = self.add_item_fixtures()
item.artist = 'xartist'
item.title = 'xtitle'
item.album = 'xalbum'
item.write()
item.store()
return item
def test_json_output(self):
item1 = self.create_item()
actual = self.execute_command(format_type='json',artist=item1.artist)
expected = '[{"track":%s,"album":%s}]'.format(item1.track,item1.album)
self.assertIn(first=expected,second=actual,msg="export in JSON format failed")
actual = self.execute_command(
format_type='json',
artist=item1.artist
)
expected = u'[{"album":"%s","title":"%s"}]'\
% (item1.album, item1.title)
self.assertIn(
expected,
actual
)
def test_csv_output(self):
item1 = self.create_item()
actual = self.execute_command(format_type='json',artist=item1.artist)
expected = 'track,album\n%s,%s'.format(item1.track,item1.album)
self.assertIn(first=expected,second=actual,msg="export in CSV format failed")
actual = self.execute_command(
format_type='csv',
artist=item1.artist
)
expected = u'album,title%s,%s'\
% (item1.album, item1.title)
self.assertIn(
expected,
actual
)
def test_xml_output(self):
item1 = self.create_item()
actual = self.execute_command(format_type='json',artist=item1.artist)
expected = '<title>%s</title><album>%s</album>'.format(item1.track,item1.album)
self.assertIn(first=expected,second=actual,msg="export in XML format failed")
actual = self.execute_command(
format_type='xml',
artist=item1.artist
)
expected = u'<album>%s</album><title>%s</title>'\
% (item1.album, item1.title)
self.assertIn(
expected,
actual
)
def suite():