From 2be0e7715fcfd735415cd7ee155d122bdf12357d Mon Sep 17 00:00:00 2001 From: multikatt Date: Tue, 2 Jun 2015 23:03:37 -0400 Subject: [PATCH] Adding tests --- test/test_ipfs.py | 94 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 94 insertions(+) create mode 100644 test/test_ipfs.py diff --git a/test/test_ipfs.py b/test/test_ipfs.py new file mode 100644 index 000000000..cfb74f203 --- /dev/null +++ b/test/test_ipfs.py @@ -0,0 +1,94 @@ +# This file is part of beets. +# +# Permission is hereby granted, free of charge, to any person obtaining +# a copy of this software and associated documentation files (the +# "Software"), to deal in the Software without restriction, including +# without limitation the rights to use, copy, modify, merge, publish, +# distribute, sublicense, and/or sell copies of the Software, and to +# permit persons to whom the Software is furnished to do so, subject to +# the following conditions: +# +# The above copyright notice and this permission notice shall be +# included in all copies or substantial portions of the Software. + +from mock import patch + +from beets import library +from beetsplug.ipfs import IPFSPlugin + +from test import _common +from test._common import unittest +from test.helper import TestHelper +import os + + +class IPFSPluginTest(unittest.TestCase, TestHelper): + + def setUp(self): + self.setup_beets() + self.load_plugins('ipfs') + self.patcher = patch('beets.util.command_output') + self.command_output = self.patcher.start() + self.lib = library.Library(":memory:") + + def tearDown(self): + self.unload_plugins() + self.teardown_beets() + self.patcher.stop() + + def test_stored_hashes(self): + test_album = self.mk_test_album() + ipfs = IPFSPlugin() + added_albums = ipfs.ipfs_added_albums(self.lib, self.lib.path) + added_album = added_albums.get_album(1) + self.assertEqual(added_album.ipfs, test_album.ipfs) + found = False + want_item = test_album.items()[2] + for check_item in added_album.items(): + try: + if check_item.ipfs: + want_path = '/ipfs/{0}/{1}'.format(test_album.ipfs, + os.path.basename( + want_item.path)) + self.assertEqual(check_item.path, want_path) + self.assertEqual(check_item.ipfs, want_item.ipfs) + self.assertEqual(check_item.title, want_item.title) + found = True + except AttributeError: + pass + self.assertTrue(found) + + def mk_test_album(self): + items = [_common.item() for _ in range(3)] + items[0].title = 'foo bar' + items[0].artist = 'one' + items[0].album = 'baz' + items[0].year = 2001 + items[0].comp = True + items[1].title = 'baz qux' + items[1].artist = 'two' + items[1].album = 'baz' + items[1].year = 2002 + items[1].comp = True + items[2].title = 'beets 4 eva' + items[2].artist = 'three' + items[2].album = 'foo' + items[2].year = 2003 + items[2].comp = False + items[2].ipfs = 'QmfM9ic5LJj7V6ecozFx1MkSoaaiq3PXfhJoFvyqzpLXSk' + + for item in items: + self.lib.add(item) + + album = self.lib.add_album(items) + album.ipfs = "QmfM9ic5LJj7V6ecozFx1MkSoaaiq3PXfhJoFvyqzpLXSf" + album.store() + + return album + + +def suite(): + return unittest.TestLoader().loadTestsFromName(__name__) + +if __name__ == b'__main__': + unittest.main(defaultTest='suite')