Esempio n. 1
0
 def test_add_new_tag(self, session):
     tag = 'Movie night candidate'
     database.add_tag(tag)
 
     count = (session.query(database.Tag)
              .filter(database.Tag.tag == 'Movie night candidate')
              .count())
     assert count == 1
Esempio n. 2
0
def add_tag_callback(tag: str):
    """Add a new user supplied tag to the database.
    
    Args:
        tag:

    """
    database.add_tag(tag)
Esempio n. 3
0
    def test_add_links_to_movies(self, session):
        expected = {'Solaris', "Akira Kurosawa's Dreams"}
        test_tag = 'Foreign'
        database.add_tag(test_tag)
        movie = database.MovieKeyTypedDict(title='Solaris', year=1972)
        database.add_movie_tag_link(test_tag, movie)
        movie = database.MovieKeyTypedDict(title="Akira Kurosawa's Dreams", year=1972)
        database.add_movie_tag_link(test_tag, movie)

        movies = (session.query(database.Movie.title)
                  .filter(database.Movie.tags.any(tag=test_tag)))
        result = {movie.title for movie in movies}
        assert result == expected
Esempio n. 4
0
    def test_edit_tag(self, session):
        old_tag = 'old test tag'
        database.add_tag(old_tag)
        movie = database.MovieKeyTypedDict(title='Solaris', year=1972)
        database.add_movie_tag_link(old_tag, movie)
        old_tag_id, tag = (session.query(database.Tag.id, database.Tag.tag)
                           .filter(database.Tag.tag == 'old test tag')
                           .one())

        new_tag = 'new test tag'
        database.edit_tag(old_tag, new_tag)
        new_tag_id, tag = (session.query(database.Tag.id, database.Tag.tag)
                           .filter(database.Tag.tag == 'new test tag')
                           .one())

        assert old_tag_id == new_tag_id
Esempio n. 5
0
 def test_del_tag(self, session):
     # Add a tag and links
     test_tag = 'Going soon'
     database.add_tag(test_tag)
     movie = database.MovieKeyTypedDict(title='Solaris', year=1972)
     database.add_movie_tag_link(test_tag, movie)
     movie = database.MovieKeyTypedDict(title='Hamlet', year=1996)
     database.add_movie_tag_link(test_tag, movie)
     
     # Delete the tag
     database.del_tag(test_tag)
     
     # Is the tag still there?
     with pytest.raises(sqlalchemy.orm.exc.NoResultFound):
         session.query(database.Tag).filter(database.Tag.tag == test_tag).one()
     
     # Do any movies still have the tag?
     assert (session.query(database.Movie)
             .filter(database.Movie.tags.any(tag=test_tag))
             .all()) == []
Esempio n. 6
0
    def test_add_tag(self):
        c = db.conn.cursor()
        c.execute('''
            SELECT * FROM tags
            WHERE pid = 4
            AND tag = 'bob'
        ''')
        row = c.fetchone()

        self.assertEqual(row, None)

        self.assertTrue(db.add_tag("4", "Bob"))

        c.execute('''
            SELECT * FROM tags
            WHERE pid = 4
            AND tag = 'bob'
        ''')
        row = c.fetchone()

        self.assertEqual(row, ("4", "bob"))

        self.assertFalse(db.add_tag("4", "BOB"))
Esempio n. 7
0
def loaded_database(hamlet, solaris, dreams, revanche):
    """Provide a loaded database."""
    database.connect_to_database(filename=':memory:')
    # noinspection PyProtectedMember
    movies = [database.Movie(**movie) for movie in (hamlet, solaris, dreams, revanche)]
    # noinspection PyProtectedMember
    with database._session_scope() as session:
        session.add_all(movies)
    database.add_tag('blue')
    database.add_movie_tag_link('blue', database.MovieKeyTypedDict(title='Hamlet', year=1996))
    database.add_tag('yellow')
    database.add_movie_tag_link('yellow', database.MovieKeyTypedDict(title='Revanche', year=2008))
    database.add_tag('green')
    database.add_movie_tag_link('green', database.MovieKeyTypedDict(title='Revanche', year=2008))
    database.add_movie_tag_link('green', database.MovieKeyTypedDict(title='Solaris', year=1972))
Esempio n. 8
0
def add_tag(pid):
    """Allows user to add a tag to the selected post

    Args:
        pid (str): The pid of the post of which the new tag will be added
    Returns:
        (bool): True if the user chooses to logout, False otherwise
    """
    print('Add tag')
    while (True):
        tag = input('Enter a tag: ')
        to_return, return_val = keyword_input_validate(tag)
        if to_return:
            return return_val
        if tag.strip() == "":
            print("\nTag cannot be empty, please try again.")
            continue
        break

    add_tag_success = db.add_tag(pid, tag)
    if add_tag_success:
        print("Tag successfully added")
    else:
        print("Failed to add a tag")
Esempio n. 9
0
 def test_find_tags_gets_many(self, session):
     tag = 'seen'
     database.add_tag(tag)
     found_tags = database.find_tags('ee')
     assert found_tags == ['green', 'seen']
Esempio n. 10
0
 def test_case_insensitive_tag(self):
     self.assertFalse(db.check_has_case_insensitive_entry("tags", ["pid", "tag"], ["1", "BANANA"]))
     self.assertTrue(db.add_tag("1", "banana"))
     self.assertTrue(db.check_has_case_insensitive_entry("tags", ["pid", "tag"], ["1", "BaNaNa"]))