Beispiel #1
0
def test_database_episode_id(prevent_modification):
    copyfile(my_dir + "/datafiles/database_example1.db", Database.PATH)
    mydatabase = Database()

    episode = mydatabase.episode(1)
    assert episode.ep_id == 1
    assert episode.title == "episode title"
Beispiel #2
0
def test_database_from_json(prevent_modification):
    copyfile(my_dir + "/datafiles/feeds_working", Database.OLD_PATH)
    mydatabase = Database()

    feeds = mydatabase.feeds()
    assert len(feeds) == 2
    assert feeds[0].key == "feed key"
    assert feeds[0].title == "feed title"
    assert feeds[0].description == "feed description"
    assert feeds[0].link == "feed link"
    assert feeds[0].last_build_date == "feed last_build_date"
    assert feeds[0].copyright == "feed copyright"
    episodes0 = mydatabase.episodes(feeds[0])
    assert episodes0[0].title == "episode title"
    assert episodes0[0].description == "episode description"
    assert episodes0[0].link == "episode link"
    assert episodes0[0].pubdate == "episode pubdate"
    assert episodes0[0].copyright == "episode copyright"
    assert episodes0[0].enclosure == "episode enclosure"

    assert feeds[1].key == "http://feed2_url"
    assert feeds[1].title == "feed2 title"
    assert feeds[1].description == "feed2 description"
    assert feeds[1].link == "feed2 link"
    assert feeds[1].last_build_date == "feed2 last_build_date"
    assert feeds[1].copyright == "feed2 copyright"
    episodes1 = mydatabase.episodes(feeds[1])
    assert episodes1[0].title == "episode title"
    assert episodes1[0].description == "episode description"
    assert episodes1[0].link == "episode link"
    assert episodes1[0].pubdate == "episode pubdate"
    assert episodes1[0].copyright == "episode copyright"
    assert episodes1[0].enclosure == "episode enclosure"
Beispiel #3
0
def test_database_feed_episodes(prevent_modification):
    copyfile(my_dir + "/datafiles/database_example1.db", Database.PATH)
    mydatabase = Database()

    feed = mydatabase.feeds()[0]
    episodes = mydatabase.episodes(feed)
    for episode in episodes:
        assert isinstance(episode, Episode)
Beispiel #4
0
def test_database_episodes_length(prevent_modification):
    copyfile(my_dir + "/datafiles/database_example1.db", Database.PATH)
    mydatabase = Database()

    feed1 = mydatabase.feeds()[0]
    feed2 = mydatabase.feeds()[1]
    assert len(mydatabase.episodes(feed1)) == 1
    assert len(mydatabase.episodes(feed2)) == 1
Beispiel #5
0
def test_database_feed(prevent_modification):
    copyfile(my_dir + "/datafiles/database_example1.db", Database.PATH)
    mydatabase = Database()

    feed = mydatabase.feeds()[0]
    assert isinstance(feed, Feed)
    assert feed.key == "feed key"
    assert feed.title == "feed title"
Beispiel #6
0
def test_database_replace_episode(prevent_modification):
    copyfile(my_dir + "/datafiles/database_example1.db", Database.PATH)
    mydatabase = Database()

    myfeed_path = my_dir + "/feeds/valid_basic.xml"
    myfeed = Feed(file=myfeed_path)
    episodes = myfeed.parse_episodes()

    mydatabase.replace_feed(myfeed)
    mydatabase.replace_episode(myfeed, episodes[0])
    assert len(mydatabase.episodes(myfeed)) == 1
    mydatabase.replace_episode(myfeed, episodes[0])
    assert len(mydatabase.episodes(myfeed)) == 1
Beispiel #7
0
def import_subscriptions(path: str, database: Database) -> None:
    subscriptions = Subscriptions()

    # Load may raise an error, but they are user-friendly enough that we don't
    # need to catch them here. It's also okay to crash at this point.
    subscriptions.load(path)

    print("Importing %d feeds..." % len(subscriptions.feeds))

    for feed in subscriptions.feeds:
        database.replace_feed(feed)
        episodes = feed.parse_episodes()
        database.replace_episodes(feed, episodes)
        print("Imported '%s' with %d episodes" % (str(feed), len(episodes)))
Beispiel #8
0
def test_database_delete_queue(display):
    copyfile(my_dir + "/datafiles/database_example1.db", Database.PATH)
    mydatabase = Database()

    myqueue = Queue(display)
    player1 = mock.MagicMock(spec=Player)
    feed = mydatabase.feeds()[0]
    episode = mydatabase.episodes(feed)[0]
    player1.episode = episode
    myqueue.add(player1)

    mydatabase.replace_queue(myqueue)
    assert len(mydatabase.queue()) == 1
    mydatabase.delete_queue()
    assert len(mydatabase.queue()) == 0
Beispiel #9
0
def test_database_delete_episode_progress(prevent_modification):
    copyfile(my_dir + "/datafiles/database_example1.db", Database.PATH)
    mydatabase = Database()
    ep = mydatabase.episode(1)
    mydatabase.replace_progress(ep, 1000)
    p = mydatabase.episode(1)
    assert ep.progress == 1000
    assert p.progress == 1000
    mydatabase.delete_progress(ep)
    p = mydatabase.episode(1)
    assert ep.progress == 0
    assert p.progress == 0
Beispiel #10
0
def test_database_delete_feed(prevent_modification):
    copyfile(my_dir + "/datafiles/database_example1.db", Database.PATH)
    mydatabase = Database()
    assert len(mydatabase.feeds()) == 2

    feed = mydatabase.feeds()[0]
    mydatabase.delete_feed(feed)
    assert len(mydatabase.feeds()) == 1
Beispiel #11
0
def test_database_replace_feed(prevent_modification):
    copyfile(my_dir + "/datafiles/database_example1.db", Database.PATH)
    mydatabase = Database()

    myfeed_path = my_dir + "/feeds/valid_basic.xml"
    myfeed1 = Feed(file=myfeed_path)
    myfeed2 = Feed(file=myfeed_path)

    mydatabase.replace_feed(myfeed1)
    assert len(mydatabase.feeds()) == 3
    mydatabase.replace_feed(myfeed2)
    assert len(mydatabase.feeds()) == 3
Beispiel #12
0
def export_subscriptions(path: str, database: Database) -> None:
    subscriptions = Subscriptions()

    feeds = database.feeds()
    subscriptions.generate(feeds)
    # Save may raise an error, but they are user-friendly enough that we don't
    # need to catch them here. It's also okay to crash at this point.
    subscriptions.save(path)

    print("Exported %d feeds" % len(feeds))
Beispiel #13
0
def import_subscriptions(path: str, database: Database) -> None:
    subscriptions = Subscriptions()

    # Load may raise an error, but they are user-friendly enough that we don't
    # need to catch them here. It's also okay to crash at this point.
    subscriptions.load(path)

    for generated in subscriptions.parse():
        if isinstance(generated, Feed):
            feed = generated
            database.replace_feed(feed)
            episodes = feed.parse_episodes()
            database.replace_episodes(feed, episodes)
            print("Added \"%s\" with %d episodes" % (str(feed), len(episodes)))
        else:
            print("ERROR: Failed to load %s -- %s" %
                  (str(generated[0]), str(generated[1])))

    print("Imported %d feeds" % len(subscriptions.feeds))
Beispiel #14
0
def test_database_delete_feed_and_episode(prevent_modification):
    copyfile(my_dir + "/datafiles/database_example1.db", Database.PATH)
    mydatabase = Database()

    feed = mydatabase.feeds()[0]
    feed_episode = mydatabase.episodes(feed)[0]

    mydatabase.delete_feed(feed)
    feed_episode = mydatabase.episodes(feed)
    assert len(feed_episode) == 0
Beispiel #15
0
def test_database_from_json(prevent_modification):
    copyfile(my_dir + "/datafiles/feeds_working", Database.OLD_PATH)
    mydatabase = Database()

    feeds = mydatabase.feeds()
    assert len(feeds) == 2

    # we don't technically make any assumptions about the order of the feeds
    if feeds[0].key != "feed key":
        feeds.reverse()

    assert feeds[0].key == "feed key"
    assert feeds[0].title == "feed title"
    assert feeds[0].description == "feed description"
    assert feeds[0].link == "feed link"
    assert feeds[0].last_build_date == "feed last_build_date"
    assert feeds[0].copyright == "feed copyright"
    episodes0 = mydatabase.episodes(feeds[0])
    assert episodes0[0].title == "episode title"
    assert episodes0[0].description == "episode description"
    assert episodes0[0].link == "episode link"
    assert episodes0[0].pubdate == "episode pubdate"
    assert episodes0[0].copyright == "episode copyright"
    assert episodes0[0].enclosure == "episode enclosure"
    assert not episodes0[0].played

    assert feeds[1].key == "http://feed2_url"
    assert feeds[1].title == "feed2 title"
    assert feeds[1].description == "feed2 description"
    assert feeds[1].link == "feed2 link"
    assert feeds[1].last_build_date == "feed2 last_build_date"
    assert feeds[1].copyright == "feed2 copyright"
    episodes1 = mydatabase.episodes(feeds[1])
    assert episodes1[0].title == "episode title"
    assert episodes1[0].description == "episode description"
    assert episodes1[0].link == "episode link"
    assert episodes1[0].pubdate == "episode pubdate"
    assert episodes1[0].copyright == "episode copyright"
    assert episodes1[0].enclosure == "episode enclosure"
    assert not episodes1[0].played
Beispiel #16
0
def test_database_reload(prevent_modification, display):
    mydatabase = Database()

    myfeed_path = my_dir + "/feeds/valid_basic.xml"
    myfeed = Feed(file=myfeed_path)
    real_title = myfeed.title
    myfeed._title = "fake title"

    mydatabase.replace_feed(myfeed)

    display.change_status = mock.MagicMock(name="change_status")
    mydatabase.reload(display)
    assert display.change_status.call_count == 2
    assert mydatabase.feeds()[0].title == real_title
Beispiel #17
0
def test_database_delete_feed_episode_and_progress(prevent_modification):
    copyfile(my_dir + "/datafiles/database_example1.db", Database.PATH)
    mydatabase = Database()

    feed = mydatabase.feeds()[0]
    feed_episode = mydatabase.episodes(feed)[0]
    mydatabase.replace_progress(feed_episode, 1000)

    feed_episode = mydatabase.episodes(feed)[0]
    assert feed_episode.progress == 1000
    mydatabase.replace_progress(feed_episode, 1000)
    mydatabase.delete_feed(feed)
    # returns None since nothing was deleted
    assert mydatabase.delete_progress(feed_episode) is None
Beispiel #18
0
def test_database_default(prevent_modification):
    mydatabase = Database()
    assert isinstance(mydatabase, Database)
Beispiel #19
0
def display(prevent_modification, stdscr):
    database = Database()
    yield Display(stdscr, database)
Beispiel #20
0
def main():
    database = Database()

    # parse command line arguments
    parser = argparse.ArgumentParser(prog=castero.__title__,
                                     description=castero.__description__)
    parser.add_argument('-V',
                        '--version',
                        action='version',
                        version='%(prog)s {}'.format(castero.__version__))
    parser.add_argument('--import', help='path to OPML file of feeds to add')
    parser.add_argument('--export', help='path to save feeds as OPML file')
    args = parser.parse_args()

    if vars(args)['import'] is not None:
        import_subscriptions(vars(args)['import'], database)
        sys.exit(0)
    elif vars(args)['export'] is not None:
        export_subscriptions(vars(args)['export'], database)
        sys.exit(0)

    # update fields in help menu text
    for field in Config:
        if "{%s}" % field in castero.__help__:
            castero.__help__ = \
                castero.__help__.replace(
                    "{%s}" % field,
                    Config[field].ljust(11)
                )
        elif "{%s|" % field in castero.__help__:
            field2 = castero.__help__.split("{%s|" % field)[1].split("}")[0]
            castero.__help__ = \
                castero.__help__.replace(
                    "{%s|%s}" % (field, field2),
                    ("%s or %s" % (Config[field], Config[field2])).ljust(11)
                )
        elif "{%s/" % field in castero.__help__:
            field2 = castero.__help__.split("{%s/" % field)[1].split("}")[0]
            castero.__help__ = \
                castero.__help__.replace(
                    "{%s/%s}" % (field, field2),
                    ("%s/%s" % (Config[field], Config[field2])).ljust(11)
                )
    remaining_brace_fields = re.compile('\\{.*?\\}').findall(castero.__help__)
    for field in remaining_brace_fields:
        adjusted = field.replace("{", "").replace("}", "").ljust(11)
        castero.__help__ = \
            castero.__help__.replace(field, adjusted)

    # instantiate display
    redirect_stderr()
    stdscr = curses.initscr()
    display = Display(stdscr, database)
    display.clear()
    display.update_parent_dimensions()

    # check if we need to start reloading
    if helpers.is_true(Config['reload_on_start']):
        reload_thread = threading.Thread(target=database.reload,
                                         args=[display])
        reload_thread.start()

    # run initial display operations
    display.display_all()
    display._menus_valid = False
    display._update_timer = 0

    # core loop for the client
    running = True
    while running:
        display.display()
        char = display.getch()
        if char != -1:
            running = display.handle_input(char)

    sys.exit(0)
Beispiel #21
0
def test_database_feeds_length(prevent_modification):
    copyfile(my_dir + "/datafiles/database_example1.db", Database.PATH)
    mydatabase = Database()

    assert len(mydatabase.feeds()) == 2
Beispiel #22
0
def main():
    database = Database()

    # update fields in help menu text
    for field in Config:
        if "{%s}" % field in castero.__help__:
            castero.__help__ = \
                castero.__help__.replace(
                    "{%s}" % field,
                    Config[field].ljust(9)
                )
        elif "{%s|" % field in castero.__help__:
            field2 = castero.__help__.split("{%s|" % field)[1].split("}")[0]
            castero.__help__ = \
                castero.__help__.replace(
                    "{%s|%s}" % (field, field2),
                    ("%s or %s" % (Config[field], Config[field2])).ljust(9)
                )
    remaining_brace_fields = re.compile('\{.*?\}').findall(castero.__help__)
    for field in remaining_brace_fields:
        adjusted = field.replace("{", "").replace("}", "").ljust(9)
        castero.__help__ = \
            castero.__help__.replace(field, adjusted)

    # check if user is running the client with an info flag
    info_flags = {
        'help': ['-h', '--help'],
        'version': ['-v', '--version']
    }
    if sys.argv[len(sys.argv) - 1] in info_flags['help']:
        print(castero.__help__)
        sys.exit(0)
    elif sys.argv[len(sys.argv) - 1] in info_flags['version']:
        print(castero.__version__)
        sys.exit(0)

    # instantiate the display object
    stdscr = curses.initscr()
    display = Display(stdscr, database)
    display.clear()
    display.update_parent_dimensions()

    # check if we need to start reloading
    if helpers.is_true(Config['reload_on_start']):
        reload_thread = threading.Thread(target=feeds.reload, args=[display])
        reload_thread.start()

    # run initial display operations
    display.display()
    display.update()
    display.refresh()

    # core loop for the client
    running = True
    while running:
        display.display()
        display.update()
        display.refresh()
        char = display.getch()
        if char != -1:
            running = display.handle_input(char)

    sys.exit(0)