Esempio n. 1
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)
Esempio n. 2
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)
Esempio 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)
Esempio 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)
Esempio n. 5
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)
Esempio n. 6
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)
Esempio n. 7
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)