Completely reworked event contractor
This commit is contained in:
parent
f801fcb81e
commit
a6f1d4b7ec
7 changed files with 100 additions and 34 deletions
|
@ -1,19 +1,15 @@
|
|||
import shutil
|
||||
import subprocess
|
||||
# The tests rely on a lot of absolute paths and other garbage so this file
|
||||
# configures all of that
|
||||
|
||||
music_folder = u'/home/rudi/music'
|
||||
o_path = u'/home/rudi/throwaway/ACDC_-_Back_In_Black-sample-64kbps.ogg'
|
||||
watch_path = u'/home/rudi/throwaway/fucking_around/watch/',
|
||||
real_path1 = u'/home/rudi/throwaway/fucking_around/watch/unknown/unknown/ACDC_-_Back_In_Black-sample-64kbps-64kbps.ogg'
|
||||
opath = u"/home/rudi/Airtime/python_apps/media-monitor2/tests/"
|
||||
ppath = u"/home/rudi/Airtime/python_apps/media-monitor2/media/"
|
||||
sample_config = u'/home/rudi/Airtime/python_apps/media-monitor2/tests/api_client.cfg'
|
||||
real_config = u'/home/rudi/Airtime/python_apps/media-monitor2/tests/live_client.cfg'
|
||||
|
||||
api_client_path = '/etc/airtime/api_client.cfg'
|
||||
|
||||
if __name__ == "__main__":
|
||||
shutil.copy(api_client_path, real_config)
|
||||
# TODO : fix this to use liberal permissions
|
||||
subprocess.call(["chown","rudi",real_config])
|
||||
# holdover from the time we had a special config for testing
|
||||
sample_config = api_client_path
|
||||
real_config = api_client_path
|
||||
|
||||
|
|
|
@ -9,7 +9,8 @@ import prepare_tests
|
|||
|
||||
class TestApiClient(unittest.TestCase):
|
||||
def setUp(self):
|
||||
test_path = prepare_tests.real_config
|
||||
test_path = prepare_tests.api_client_path
|
||||
print("Running from api_config: %s" % test_path)
|
||||
if not os.path.exists(test_path):
|
||||
print("path for config does not exist: '%s' % test_path")
|
||||
# TODO : is there a cleaner way to exit the unit testing?
|
||||
|
|
|
@ -3,48 +3,37 @@ from media.monitor.eventcontractor import EventContractor
|
|||
#from media.monitor.exceptions import BadSongFile
|
||||
from media.monitor.events import FakePyinotify, NewFile, MoveFile, \
|
||||
DeleteFile
|
||||
from mock import patch
|
||||
|
||||
class TestMMP(unittest.TestCase):
|
||||
def test_event_registered(self):
|
||||
ev = EventContractor()
|
||||
e1 = NewFile( FakePyinotify('bullshit.mp3') )
|
||||
e2 = MoveFile( FakePyinotify('bullshit.mp3') )
|
||||
e1 = NewFile( FakePyinotify('bullshit.mp3') ).proxify()
|
||||
e2 = MoveFile( FakePyinotify('bullshit.mp3') ).proxify()
|
||||
ev.register(e1)
|
||||
self.assertTrue( ev.event_registered(e2) )
|
||||
|
||||
def test_get_old_event(self):
|
||||
ev = EventContractor()
|
||||
e1 = NewFile( FakePyinotify('bullshit.mp3') )
|
||||
e2 = MoveFile( FakePyinotify('bullshit.mp3') )
|
||||
e1 = NewFile( FakePyinotify('bullshit.mp3') ).proxify()
|
||||
e2 = MoveFile( FakePyinotify('bullshit.mp3') ).proxify()
|
||||
ev.register(e1)
|
||||
self.assertEqual( ev.get_old_event(e2), e1 )
|
||||
|
||||
def test_register(self):
|
||||
ev = EventContractor()
|
||||
e1 = NewFile( FakePyinotify('bullshit.mp3') )
|
||||
e2 = DeleteFile( FakePyinotify('bullshit.mp3') )
|
||||
e1 = NewFile( FakePyinotify('bullshit.mp3') ).proxify()
|
||||
e2 = DeleteFile( FakePyinotify('bullshit.mp3') ).proxify()
|
||||
self.assertTrue( ev.register(e1) )
|
||||
|
||||
# Check that morph_into is called when it should be
|
||||
with patch.object(NewFile, 'morph_into', return_value='kimchi') \
|
||||
as mock_method:
|
||||
ret = ev.register(e2)
|
||||
self.assertFalse(ret)
|
||||
mock_method.assert_called_once_with(e2)
|
||||
|
||||
# This time we are not patching morph
|
||||
self.assertFalse( ev.register(e2) )
|
||||
# We did not an element
|
||||
self.assertTrue( len(ev.store.keys()) == 1 )
|
||||
morphed = ev.get_old_event(e2)
|
||||
self.assertTrue( isinstance(morphed, DeleteFile) )
|
||||
|
||||
self.assertEqual( len(ev.store.keys()), 1 )
|
||||
|
||||
delete_ev = e1.safe_pack()[0]
|
||||
self.assertEqual( delete_ev['mode'], u'delete')
|
||||
self.assertTrue( len(ev.store.keys()) == 0 )
|
||||
self.assertEqual( len(ev.store.keys()), 0 )
|
||||
|
||||
e3 = DeleteFile( FakePyinotify('horseshit.mp3') )
|
||||
e3 = DeleteFile( FakePyinotify('horseshit.mp3') ).proxify()
|
||||
self.assertTrue( ev.register(e3) )
|
||||
self.assertTrue( ev.register(e2) )
|
||||
|
||||
|
@ -58,11 +47,12 @@ class TestMMP(unittest.TestCase):
|
|||
DeleteFile( FakePyinotify(p) ),
|
||||
NewFile( FakePyinotify(p) ),
|
||||
NewFile( FakePyinotify(p) ), ]
|
||||
events = map(lambda x: x.proxify(), events)
|
||||
actual_events = []
|
||||
for e in events:
|
||||
if ev.register(e):
|
||||
actual_events.append(e)
|
||||
self.assertEqual( len(ev.store.keys()), 1 )
|
||||
packed = [ x.safe_pack() for x in actual_events ]
|
||||
#packed = [ x.safe_pack() for x in actual_events ]
|
||||
|
||||
if __name__ == '__main__': unittest.main()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue