def test_deleteStoredSearch_should_call_executebuiltin(self):
     storage = BlipTVStorage()
     storage.retrieveValue = Mock()
     storage.retrieveValue.return_value = repr(["some_search"])
     storage.store = Mock()
     
     storage.deleteStoredSearch({"delete": "some_search2"})
     
     sys.modules["__main__"].xbmc.executebuiltin.assert_called_with('Container.Refresh')
 def test_retrieve_should_call_retrieveValue_if_type_is_set(self):
     sys.modules["__main__"].settings.getSetting.return_value = "0"
     storage = BlipTVStorage()
     storage.getStorageKey = Mock()
     storage.getStorageKey.return_value = "some_key"
     storage.retrieveValue = Mock()
     
     storage.retrieve("some_key", "thumbnail")
     
     storage.retrieveValue.assert_called_with("some_key")
    def test_getStoredSearches_should_call_retrieve_to_get_searches(self):
        storage = BlipTVStorage()
        storage.retrieveValue = Mock()
        storage.retrieveValue.return_value = repr(["some_search"])
        storage.retrieve = Mock()
        storage.retrieve.return_value = ["some_search"]
        storage.store = Mock()

        storage.getStoredSearches({"path": "some_path"})

        assert(storage.retrieve.call_count > 0)
    def test_getStoredSearches_should_return_proper_list_structure(self):
        storage = BlipTVStorage()
        storage.retrieveValue = Mock()
        storage.retrieveValue.return_value = ["some_search"]
        storage.retrieve = Mock()
        storage.retrieve.return_value = ["some_search"]
        storage.store = Mock()

        result = storage.getStoredSearches({"path": "some_path"})

        print repr(result)
        assert(result == [{'path': 'some_path', 'search': 'some_search', 'thumbnail': ['some_search'], 'Title': 'some_search'}])
    def test_getStoredSearches_should_call_retrieve_to_get_thumbnail_collection(self):
        storage = BlipTVStorage()
        storage.retrieveValue = Mock()
        storage.retrieveValue.return_value = ["some_search"]
        storage.retrieve = Mock()
        storage.retrieve.return_value = ["some_search"]
        storage.store = Mock()

        storage.getStoredSearches({"path": "some_path"})
        assert(storage.retrieve.call_args[0][0] == {"path": "some_path"})
        assert(storage.retrieve.call_args[0][1] == "thumbnail")
        print repr(storage.retrieve.call_args[0][2])
        assert(storage.retrieve.call_args[0][2] == {'path': 'some_path', 'search': 'some_search', 'thumbnail': ['some_search'], 'Title': 'some_search'})
        assert(storage.retrieve.call_count == 2)
 def test_deleteStoredSearch_should_call_unquote_on_delete_param(self):
     patcher = patch("urllib.unquote_plus")
     patcher.start()
     import urllib
     urllib.unquote_plus.return_value = "some_unquoted_search"
     storage = BlipTVStorage()
     storage.retrieveValue = Mock()
     storage.retrieveValue.return_value = repr(["some_search"])
     storage.retrieve = Mock()
     storage.retrieve.return_value = ["some_search1"]
     storage.store = Mock()
     
     storage.deleteStoredSearch({"delete": "some_search2"})
     args = urllib.unquote_plus.call_args
     patcher.stop()
     
     assert(args[0][0] == "some_search2")
    def test_getStoredSearches_should_fill_item_for_store_search(self):
        patcher = patch("urllib.quote_plus")
        patcher.start()
        import urllib
        urllib.quote_plus.return_value = "some_quoted_search"
        storage = BlipTVStorage()
        storage.retrieveValue = Mock()
        storage.retrieveValue.return_value = ["some_search"]
        storage.retrieve = Mock()
        storage.retrieve.return_value = ["some_search"]
        storage.store = Mock()

        result = storage.getStoredSearches({"path": "some_path", "store": "searches"})

        args = urllib.quote_plus.call_args
        patcher.stop()
        print repr(result)
        assert(args[0][0] == "some_search")
        assert(result == [{'feed': 'search', 'search': 'some_quoted_search', 'Title': 'some_search', 'scraper': 'search', 'path': 'some_path', 'thumbnail': ['some_search'], 'icon': 'search'}])
    def test_getStoredSearches_should_call_quote_plus_on_search_items(self):
        patcher = patch("urllib.quote_plus")
        patcher.start()
        import urllib
        urllib.quote_plus.return_value = "some_quoted_search"
        storage = BlipTVStorage()
        storage.retrieveValue = Mock()
        storage.retrieveValue.return_value = ["some_search"]
        storage.retrieve = Mock()
        storage.retrieve.return_value = ["some_search"]
        storage.store = Mock()
        
        result = storage.getStoredSearches({"path": "some_path"})

        args = urllib.quote_plus.call_args
        patcher.stop()

        assert(args[0][0] == "some_search")
        assert(result == [{'path': 'some_path', 'search': 'some_quoted_search', 'thumbnail': ['some_search'], 'Title': 'some_search'}])
 def test_retrieveValue_should_call_getsetting_with_correct_params(self):
     storage = BlipTVStorage()
     
     storage.retrieveValue("some_key")
     
     sys.modules["__main__"].settings.getSetting.assert_called_with("some_key")