def test_playVideo_should_call_getVideoObject(self):
        player = BlipTVPlayer()
        player.getVideoObject = Mock()
        player.getVideoObject.return_value = []

        player.playVideo({"apierror": "some error"})

        assert(player.getVideoObject.call_count == 1)
    def test_playVideo_should_log_and_fail_gracefully_on_apierror(self):
        player = BlipTVPlayer()
        player.getVideoObject = Mock()
        player.getVideoObject.return_value = []

        result = player.playVideo({"apierror": "some error"})

        assert(result == False)
        sys.modules["__main__"].common.log.assert_called_with("construct video url failed contents of video item []")
    def test_playVideo_should_update_locally_stored_watched_status(self):
        sys.modules["__main__"].common.makeAscii.return_value = "ascii"
        sys.modules["__main__"].settings.getSetting.return_value = "0"
        sys.modules["__main__"].common.log = Mock()
        sys.argv = ["test1", "1", "test2"]
        player = BlipTVPlayer()
        player.getVideoObject = Mock()
        player.getVideoObject.return_value = {"Title": "someTitle", "videoid": "some_id", "thumbnail": "someThumbnail", "video_url": "someUrl"}
        player.addSubtitles = Mock()

        player.playVideo({"videoid": "some_id"})

        sys.modules["__main__"].settings.setSetting.assert_called_with("vidstatus-some_id", "7" )
    def test_playVideo_should_call_xbmc_setResolvedUrl(self):
        sys.modules["__main__"].settings.getSetting.return_value = "0"
        sys.modules["__main__"].common.makeAscii.return_value = "ascii"
        sys.modules["__main__"].xbmcgui.ListItem = Mock()
        player = BlipTVPlayer()
        player.addSubtitles = Mock()
        player.getVideoObject = Mock()
        player.getVideoObject.return_value = {"Title": "someTitle", "videoid": "some_id", "thumbnail": "someThumbnail", "video_url": "someUrl"}
        sys.argv = ["test1", "1", "test2"]

        player.playVideo({"videoid": "some_id"})

        assert(sys.modules["__main__"].xbmcplugin.setResolvedUrl.call_count > 0)
    def test_getVideoObject_should_test_local_file(self):
        sys.modules["__main__"].xbmcvfs.exists.return_value = True
        sys.modules["__main__"].xbmcvfs.exists.return_value
        sys.modules["__main__"].settings.getSetting.return_value = "mock_path/"
        player = BlipTVPlayer()
        player.selectVideoQuality = Mock()
        player.selectVideoQuality.return_value = "video-url"
        player._getVideoLinks = Mock()
        player.getInfo = Mock()
        player.getInfo.return_value = {"Title": "mock"}
        
        (video, status) = player.getVideoObject({"action": "check-local", "videoid": "mockid"})

        sys.modules["__main__"].xbmcvfs.exists.assert_called_with('mock_path/mock-[mockid].mp4')
    def test_getVideoObject_should_fail(self):
        sys.modules["__main__"].xbmcvfs.exists.return_value = True
        sys.modules["__main__"].settings.getSetting.return_value = "mock_path/"
        sys.modules["__main__"].language.return_value = "mock error"
        player = BlipTVPlayer()
        player.selectVideoQuality = Mock()
        player.selectVideoQuality.return_value = "video-url"
        player._getVideoLinks = Mock()
        player._getVideoLinks.return_value = False
        player.getInfo = Mock()
        player.getInfo.return_value = {}

        params = {"action": "play", "videoid": "mockid"}
        video = player.getVideoObject(params)
        print "A : " + repr(video)
        print "B : " + repr(params)
        assert(params["apierror"] == "mock error")
    def test_getVideoObject_should_return_correctly(self):
        patcher = patch("urllib2.urlopen")
        patcher.start()
        import urllib2
        urllib2.urlopen().geturl = Mock(return_value="real-video-url")
        player = BlipTVPlayer()
        player.selectVideoQuality = Mock()
        player.selectVideoQuality.return_value = "video-url"
        player._getVideoLinks = Mock()
        player.getInfo = Mock()
        player.getInfo.return_value = {"Title": "mock"}

        video = player.getVideoObject({"action": "download"})
        patcher.stop()

        print "A : " + repr(video)
        assert(video["Title"] == "mock")
        assert(video["video_url"] == "real-video-url")