def test_get_single_rating(self):
        '''Test that users with the right permission can see details of a single rating vendor rating'''

        rating = VendorRatingFactory.create()
        rating_id = rating.id
        role = RoleFactory.create(name='Admin')
        permission = PermissionFactory.create(keyword='view_ratings',
                                              role_id=role.id)
        user_role = UserRoleFactory.create(user_id=rating.user_id,
                                           role_id=role.id)

        response = self.client().get(self.make_url(f'/ratings/{rating_id}'),
                                     headers=self.headers())
        response_json = self.decode_from_json_string(
            response.data.decode('utf-8'))
        payload = response_json['payload']

        self.assert200(response)
        self.assertJSONKeyPresent(payload, 'rating')
        self.assertJSONKeysPresent(payload['rating'], 'vendorId', 'userId',
                                   'id', 'comment', 'rating', 'channel')

        self.assertEqual(payload['rating']['id'], rating_id)
        self.assertEqual(payload['rating']['userId'], rating.user_id)
        self.assertEqual(payload['rating']['vendorId'], rating.vendor_id)
        self.assertEqual(payload['rating']['comment'], rating.comment)
        self.assertEqual(payload['rating']['rating'], rating.rating)
        '''Search for a non-existing rating returns 400 error'''
        response = self.client().get(self.make_url('/ratings/100'),
                                     headers=self.headers())
        self.assert400(response)
Exemple #2
0
    def test_get_single_rating_without_permission(self):
        """Test that users without the right permission cannot see details of a single rating vendor rating"""

        rating = VendorRatingFactory.create()
        rating_id = rating.id
        role = RoleFactory.create(name='Admin')
        permission = PermissionFactory.create(keyword='view_ratings', role_id=100)
        user_role = UserRoleFactory.create(user_id=rating.user_id, role_id=role.id)

        response = self.client().get(self.make_url(f'/ratings/{rating_id}'), headers=self.headers())

        self.assert401(response)
Exemple #3
0
    def test_list_rating_endpoint(self):
        vendor = VendorFactory.create()
        engagement = VendorEngagementFactory.create(vendor=vendor)
        rating = VendorRatingFactory.create(engagement=engagement, vendor=vendor)
        create_user_role('view_ratings')
        now = datetime.now()

        response = self.client().get(self.make_url(f'/ratings/{now.strftime("%Y-%m-%d")}'),
                                     headers=self.headers())

        response_json = self.decode_from_json_string(response.data.decode('utf-8'))
        self.assert404(response)
        self.assertEqual(response_json['msg'], 'No ratings for this date')
Exemple #4
0
    def test_update_vendor_rating_endpoint(self):

        rating = VendorRatingFactory.create()

        data = {'comment': 'New comments'}
        response = self.client().put(self.make_url(f'/ratings/{rating.id}'), data=self.encode_to_json_string(data), headers=self.headers())
        response_json = self.decode_from_json_string(response.data.decode('utf-8'))
        payload = response_json['payload']

        self.assert200(response)
        self.assertEqual(payload['rating']['id'], rating.id)
        self.assertEqual(payload['rating']['userId'], rating.user_id)
        self.assertEqual(payload['rating']['vendorId'], rating.vendor_id)
        self.assertEqual(payload['rating']['comment'], rating.comment)
        self.assertEqual(payload['rating']['rating'], rating.rating)

        """Updating a non-existent rating should return 400 error"""
        response = self.client().patch(self.make_url(f'/ratings/777777777'), data=self.encode_to_json_string(data), headers=self.headers())
        self.assert404(response)