Exemple #1
0
    def test_update(self):
        FilmRepository.create(**self.film_dict)

        film_update = {
            "vals": {
                'year': 1995,
            }
        }
        response = self.client.put(
            "/api/film/1",
            content_type="application/json",
            data=json.dumps(film_update),
        )

        self.assertEqual(response.status_code, 200)
        response_json = json.loads(response.data.decode("utf-8"))
        check_dict = self.film_dict.copy()
        check_dict['id'] = 1
        check_dict['year'] = 1995

        self.assertEqual(
            response_json,
            {"film": check_dict},
        )
        film = FilmRepository.get(id=1)
        self.assertEqual(film.year, 1995)
Exemple #2
0
    def test_get(self):
        FilmRepository.create(**self.film_dict)
        response = self.client.get("/api/film/1")

        self.assertEqual(response.status_code, 200)
        response_json = json.loads(response.data.decode("utf-8"))
        check_dict = self.film_dict.copy()
        check_dict['id'] = 1
        self.assertEqual(
            response_json,
            {"film": check_dict},
        )
Exemple #3
0
    def get():
        films = FilmRepository.getAll()
        _str = "["
        for i in range(len(films)):
            _str += json.dumps(films[i].json) + ","
        _str = _str[:len(_str) - 1] + "]"

        return _str
Exemple #4
0
 def post(name, year, pos, rating, url, image):
     film = FilmRepository.create(
         name=name,
         year=year,
         pos=pos,
         rating=rating,
         url=url,
         image=image,
     )
     return jsonify({"film": film.json})
Exemple #5
0
 def post(title, author, date, type, image, synopsis, country):
     """ Create a film based on the sent information """
     film = FilmRepository.create(title=title,
                                  author=author,
                                  date=date,
                                  type=type,
                                  image=image,
                                  synopsis=synopsis,
                                  country=country)
     return jsonify({"film": film.json})
Exemple #6
0
    def test_get(self):
        FilmRepository.create(**self.film_dict_1)
        FilmRepository.create(**self.film_dict_2)
        FilmRepository.create(**self.film_dict_3)

        response = self.client.get("/api/top/")

        self.assertEqual(response.status_code, 200)
        response_json = json.loads(response.data.decode("utf-8"))
        self.assertEqual(
            len(response_json.get("films")),
            3,
        )
Exemple #7
0
 def delete(id):
     fr = FilmRepository()
     fr.delete(id)
     return jsonify({"message": "Deleted succesfully"})
Exemple #8
0
 def put(id, vals):
     fr = FilmRepository()
     film = fr.update(id, vals)
     return jsonify({"film": film.json})
Exemple #9
0
 def get(id):
     film = FilmRepository.get(id=id)
     return jsonify({"film": film.json})
Exemple #10
0
 def get():
     films = FilmRepository.get_all()
     films_json = [film.json for film in films]
     return jsonify({"films": films_json})
Exemple #11
0
 def put(title, author, date):
     """ Update a film based on the sent information """
     repository = FilmRepository()
     film = repository.update(title=title, author=author, date=date)
     return jsonify({"film": film.json})
Exemple #12
0
 def get(title, author):
     film = FilmRepository.get(title=title, author=author)
     return jsonify({"film": film.json})
Exemple #13
0
 def post(title, date):
     """ Create a film based on the sent information """
     film = FilmRepository.create(title=title, date=date)
     return jsonify({"film": film.json})
Exemple #14
0
 def get(title):
     """ Return a film key information based on its title """
     film = FilmRepository.get(title=title)
     return jsonify({"film": film.json})