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)
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}, )
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
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})
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})
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, )
def delete(id): fr = FilmRepository() fr.delete(id) return jsonify({"message": "Deleted succesfully"})
def put(id, vals): fr = FilmRepository() film = fr.update(id, vals) return jsonify({"film": film.json})
def get(id): film = FilmRepository.get(id=id) return jsonify({"film": film.json})
def get(): films = FilmRepository.get_all() films_json = [film.json for film in films] return jsonify({"films": films_json})
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})
def get(title, author): film = FilmRepository.get(title=title, author=author) return jsonify({"film": film.json})
def post(title, date): """ Create a film based on the sent information """ film = FilmRepository.create(title=title, date=date) return jsonify({"film": film.json})
def get(title): """ Return a film key information based on its title """ film = FilmRepository.get(title=title) return jsonify({"film": film.json})