def __testRepo(self):
     assert len(self.__repo) == 0
     self.__repo.add(self.__movie)
     assert len(self.__repo) == 1
     try:
         self.__repo.add(self.__movie)
         assert False
     except RepoError as re:
         assert str(re) == "existing elem!"
     keyMovie = Movie(self.__id, None, None)
     assert self.__repo.search(keyMovie) == self.__movie
     try:
         self.__repo.search(self.__badMovie)
         assert False
     except RepoError as re:
         assert str(re) == "inexisting elem!"
     newMovie = Movie(self.__id, "TheNun", "horror")
     self.__repo.update(newMovie)
     all = self.__repo.getAll()
     assert all == [newMovie]
     assert self.__repo.search(keyMovie) == newMovie
     try:
         self.__repo.update(self.__badMovie)
         assert False
     except RepoError as re:
         assert str(re) == "inexisting elem!"
     removeElem = Movie(self.__id, None, None)
     self.__repo.removeee(removeElem)
     try:
         self.__repo.removeee(removeElem)
         assert False
     except RepoError as re:
         assert str(re) == "inexisting elem!"
 def __init__(self):
     self.__id = 23
     self.__titlu = "Ronin"
     self.__gen = "action"
     self.__movie = Movie(self.__id, self.__titlu, self.__gen)
     self.__validator = MovieValidator()
     self.__badId = -23
     self.__badTitlu = ""
     self.__badGen = ""
     self.__badMovie = Movie(self.__badId, self.__badTitlu, self.__badGen)
     self.__repo = Repository()
     self.__service = MovieService(self.__repo, self.__validator)
Exemple #3
0
def createMovie(fullyqualifiedname, moviepath):
    matched = False
    m = re.search(r'(.*)\[(\d{4})](.*)\[(.*)]-(.*)', fullyqualifiedname)
    if m is not None:
        moviename = re.sub(r'\.', ' ', m.group(1))
        year = m.group(2)
        quality = m.group(3)
        language = m.group(4)
        ripper = m.group(5)
        matched = True
    m = re.search(r'(.*)\[(\d{4})](.*)-(.*)', fullyqualifiedname)
    if not matched and m is not None:
        moviename = re.sub(r'\.', ' ', m.group(1))
        year = m.group(2)
        quality = m.group(3)
        ripper = m.group(4)
        language = ''
        matched = True
    m = re.search(r'(.*).(\d{4}).(.*)-(.*)', fullyqualifiedname)
    if not matched and m is not None:
        moviename = re.sub(r'\.', ' ', m.group(1))
        year = m.group(2)
        quality = m.group(3)
        ripper = m.group(4)
        language = ''
        matched = True
    if matched is not True:
        moviename = fullyqualifiedname
        year = ''
        quality = ''
        language = ''
        ripper = ''
    return Movie(fullyqualifiedname, moviename, moviepath, year, quality,
                 ripper, language)
Exemple #4
0
    def extract(self):
        print("extracting attributes from url:" + self.url_movie)
        page_movie = requests.get(self.url_movie).content
        soup = BeautifulSoup(page_movie, 'html.parser')
        title_wrapper = soup.find('div', {'class': 'title_wrapper'})
        ratting_wrapper = soup.find('span', {'itemprop': 'ratingValue'})

        if title_wrapper is None:
            return None

        title_movie = title_wrapper.h1.text.strip()

        tag_duration = title_wrapper.find('div', {'class': 'subtext'}).time
        if tag_duration is None:
            duration_minutes = None
        else:
            duration_minutes = int(regex.sub("[^0-9]", "", tag_duration.get('datetime')))

        if ratting_wrapper is None:
            ratting = None
        else:
            ratting = float(ratting_wrapper.text)

        genres = []
        for genre in title_wrapper.find('div', {'class': 'subtext'}).find('a', attrs={'href': regex.compile(r'genres*')}):
            genres.append(genre)

        director_name, director_country, position_director = self.extract_director_properties(page_movie)
        director = Director(director_name, director_country, position_director, 'F')
        movie = Movie(title_movie, duration_minutes, ratting, genres, director)

        return movie
    def __testBusiness(self):
        assert self.__service.getAllMovies() == []
        self.__service.addMovie(self.__id, self.__titlu, self.__gen)
        movies = self.__service.getAllMovies()
        assert movies == [self.__movie]
        movie0 = Movie(67, "Red", "action")
        #movie1 = Movie(3,"LOTR","fantasy")

        self.__service.addMovie(67, "Red", "action")
        #         self.__service.addMovie(34,"AStarIsBorn","romance")
        #         self.__service.addMovie(14,"AmericanPie","comedy")
        #         self.__service.addMovie(3,"LOTR","fantasy")
        goodMovies = self.__service.getMovieById(67)
        assert goodMovies == movie0
Exemple #6
0
# for i in range(10):
#     ok=0
#     while ok==0:
#         try:
#             id=random.randint(9, 99999)
#             nume=randomString()
#             cnp=random.randint(1000, 100000)
#
#             client=Client(id, nume, cnp)
#             repoClients.add(client)
#             ok=1
#         except RepoError as re:
#             ok=0

movie1 = Movie(101, 'Ronin', 'action')
movie2 = Movie(1, "TheNun", "horror")
movie3 = Movie(34, "Venom", "fantasy")

client1 = Client(10, "Andrei", 1961210)
client2 = Client(42, "Sonia", 2990703)
client3 = Client(19, "Mara", 20209)
client6 = Client(199, "Maria", 199)
client4 = Client(78, "Mihaela", 99)
client5 = Client(20, "Marian", 123)

repoClients.add(client1)
repoClients.add(client2)
repoClients.add(client3)

repoMovies.add(movie1)
Exemple #7
0
def retrieveAndSaveMovieData(url):
    try:
        movie = Movie(ROOT_URL + url)
        repository.saveMovie(movie)
    except:
        print " [ERROR] : ", url
class TestMovie(object):
    def __init__(self):
        self.__id = 23
        self.__titlu = "Ronin"
        self.__gen = "action"
        self.__movie = Movie(self.__id, self.__titlu, self.__gen)
        self.__validator = MovieValidator()
        self.__badId = -23
        self.__badTitlu = ""
        self.__badGen = ""
        self.__badMovie = Movie(self.__badId, self.__badTitlu, self.__badGen)
        self.__repo = Repository()
        self.__service = MovieService(self.__repo, self.__validator)

    def __testModel(self):
        assert self.__movie.get_id() == self.__id
        assert self.__movie.get_titlu() == self.__titlu
        assert self.__movie.get_gen() == self.__gen

    def __testValid(self):
        try:
            self.__validator.valideazaMovie(self.__movie)
            assert True
        except ValidError:
            assert False

        try:
            self.__validator.valideazaMovie(self.__badMovie)
            assert False
        except ValidError as ve:
            assert str(ve) == "bad id!\nbad titlu!\nbad gen!\n"

    def __testRepo(self):
        assert len(self.__repo) == 0
        self.__repo.add(self.__movie)
        assert len(self.__repo) == 1
        try:
            self.__repo.add(self.__movie)
            assert False
        except RepoError as re:
            assert str(re) == "existing elem!"
        keyMovie = Movie(self.__id, None, None)
        assert self.__repo.search(keyMovie) == self.__movie
        try:
            self.__repo.search(self.__badMovie)
            assert False
        except RepoError as re:
            assert str(re) == "inexisting elem!"
        newMovie = Movie(self.__id, "TheNun", "horror")
        self.__repo.update(newMovie)
        all = self.__repo.getAll()
        assert all == [newMovie]
        assert self.__repo.search(keyMovie) == newMovie
        try:
            self.__repo.update(self.__badMovie)
            assert False
        except RepoError as re:
            assert str(re) == "inexisting elem!"
        removeElem = Movie(self.__id, None, None)
        self.__repo.removeee(removeElem)
        try:
            self.__repo.removeee(removeElem)
            assert False
        except RepoError as re:
            assert str(re) == "inexisting elem!"

    def __testBusiness(self):
        assert self.__service.getAllMovies() == []
        self.__service.addMovie(self.__id, self.__titlu, self.__gen)
        movies = self.__service.getAllMovies()
        assert movies == [self.__movie]
        movie0 = Movie(67, "Red", "action")
        #movie1 = Movie(3,"LOTR","fantasy")

        self.__service.addMovie(67, "Red", "action")
        #         self.__service.addMovie(34,"AStarIsBorn","romance")
        #         self.__service.addMovie(14,"AmericanPie","comedy")
        #         self.__service.addMovie(3,"LOTR","fantasy")
        goodMovies = self.__service.getMovieById(67)
        assert goodMovies == movie0

    def runTests(self):
        self.__testModel()
        self.__testValid()
        self.__testRepo()
        self.__testBusiness()