Exemplo n.º 1
0
    def test_rental_get_all(self):
        rental = RentalModel(rental_schema.load(self.rental1))
        rental.save()
        rental = RentalModel(rental_schema.load(self.rental1))
        rental.save()
        res = RentalService.get_all()

        json_data = json.loads(res.data)
        self.assertEqual(res.status_code, 200)
        self.assertEqual(json_data.__len__(), 2)
Exemplo n.º 2
0
    def test_rental_delete_by_id(self):
        rental = RentalModel(rental_schema.load(self.rental1))
        rental.save()

        res = RentalService.delete_by_id(1234)
        self.assertEqual(res.status_code, 404)

        res = RentalService.delete_by_id(1)
        self.assertEqual(res.status_code, 204)
Exemplo n.º 3
0
    def create(req_data):

        req_data['user_id'] = RentalService.get_user()
        try:
            data = rental_schema.load(req_data)
        except ValidationError as e:
            return custom_response(e.messages, 400)
        rental = RentalModel(data)
        rental.save()
        data = rental_schema.dump(rental)
        return custom_response(data, 201)
Exemplo n.º 4
0
    def test_rental_get_by_id(self):
        rental = RentalModel(rental_schema.load(self.rental1))
        rental.save()

        res = RentalService.get_by_id(13)
        self.assertEqual(res.status_code, 404)

        res = RentalService.get_by_id(1)

        json_data = json.loads(res.data)
        self.assertEqual(res.status_code, 200)
        self.assertEqual(json_data.get('movie_id'), 1)
Exemplo n.º 5
0
 def create_rental(self):
     rental = RentalModel({'user_id': 1, 'movie_id': 1})
     db.session.add(rental)
     db.session.commit()
     return rental
Exemplo n.º 6
0
    def test_rental_update_without_permission(self):
        rental = RentalModel(rental_schema.load(self.rental1))
        rental.save()

        res = RentalService.update(1, rental_schema.load({}, partial=True))
        self.assertEqual(res.status_code, 400)
Exemplo n.º 7
0
    def test_rental_update_not_found(self):
        rental = RentalModel(rental_schema.load(self.rental1))
        rental.save()

        res = RentalService.update(33, rental_schema.load({}, partial=True))
        self.assertEqual(res.status_code, 404)
Exemplo n.º 8
0
    def test_rental_get_by_id_without_permission(self):
        rental = RentalModel(rental_schema.load(self.rental1))
        rental.save()

        res = RentalService.get_by_id(1)
        self.assertEqual(res.status_code, 400)