def test_create_vendor_rating_endpoint(self):
        rating = VendorRatingFactory.build()
        vendor_id = VendorFactory.create().id
        engagement_id = VendorEngagementFactory.create().id
        data = {
            'vendorId': vendor_id,
            'engagementId': engagement_id,
            'user_id': rating.user_id,
            'rating': rating.rating,
            'comment': rating.comment,
            'channel': rating.channel
        }
        response = self.client().post(self.make_url('/ratings/'),
                                      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.assertEqual(response.status_code, 201)
        self.assertJSONKeyPresent(response_json, 'payload')
        self.assertEqual(payload['rating']['vendorId'], vendor_id)
        self.assertEqual(payload['rating']['userId'], rating.user_id)
        self.assertEqual(payload['rating']['rating'], rating.rating)
        self.assertEqual(payload['rating']['comment'], rating.comment)
        self.assertEqual(payload['rating']['channel'], rating.channel)
Esempio n. 2
0
    def test_create_vendor_rating_endpoint_invalid_token(self):
        rating = VendorRatingFactory.build()
        order_id = OrderFactory.create().id
        vendor_id = VendorFactory.create().id
        engagement_id = VendorEngagementFactory.create().id
        main_meal_id = MealItemFactory.create().id
        data = {
            'mainMealId': main_meal_id,
            'vendorId': vendor_id,
            'engagementId': engagement_id,
            'serviceDate': datetime.strftime(rating.service_date, '%Y-%m-%d'),
            'ratingType': rating.rating_type,
            'orderId': order_id,
            'user_id': rating.user_id,
            'rating': rating.rating,
            'comment': rating.comment,
            'channel': rating.channel
        }
        response = self.client().post(
            self.make_url('/ratings/order/'),
            data=self.encode_to_json_string(data),
            headers={
                'Content-Type': 'application/json',
                'X-Location': '1',
                'Authorization': 'Bearer vnvhnv.hhbhjvjvcbcgff.cggnncbnnf'
            })

        response_json = self.decode_from_json_string(
            response.data.decode('utf-8'))

        self.assertEqual(response.status_code, 400)
        self.assertEqual(response_json['msg'], 'Error Decoding')
Esempio n. 3
0
    def test_create_order_rating_endpoint(self):
        rating = VendorRatingFactory.build()
        order_id = OrderFactory.create().id
        vendor_id = VendorFactory.create().id
        engagement_id = VendorEngagementFactory.create().id
        main_meal_id = MealItemFactory.create().id
        data = {
            'mainMealId': main_meal_id,
            'vendorId': vendor_id,
            'engagementId': engagement_id,
            'serviceDate': datetime.strftime(rating.service_date, '%Y-%m-%d'),
            'ratingType': rating.rating_type,
            'orderId': order_id,
            'user_id': rating.user_id,
            'rating': rating.rating,
            'comment': rating.comment,
            'channel': rating.channel
        }
        response = self.client().post(self.make_url('/ratings/order/'),
                                      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.assertEqual(response.status_code, 201)
        self.assertJSONKeyPresent(response_json, 'payload')
        self.assertEqual(payload['rating']['userId'], rating.user_id)
        self.assertEqual(payload['rating']['rating'], rating.rating)
        self.assertEqual(payload['rating']['comment'], rating.comment)
        self.assertEqual(payload['rating']['channel'], rating.channel)
Esempio n. 4
0
    def test_create_vendor_rating_endpoint_no_token(self):
        rating = VendorRatingFactory.build()
        order_id = OrderFactory.create().id
        vendor_id = VendorFactory.create().id
        engagement_id = VendorEngagementFactory.create().id
        main_meal_id = MealItemFactory.create().id
        data = {
            'mainMealId': main_meal_id,
            'vendorId': vendor_id,
            'engagementId': engagement_id,
            'serviceDate': datetime.strftime(rating.service_date, '%Y-%m-%d'),
            'ratingType': rating.rating_type,
            'orderId': order_id,
            'user_id': rating.user_id,
            'rating': rating.rating,
            'comment': rating.comment,
            'channel': rating.channel
        }
        response = self.client().post(self.make_url('/ratings/order/'),
                                      data=self.encode_to_json_string(data),
                                      headers=self.headers_without_token())

        response_json = self.decode_from_json_string(
            response.data.decode('utf-8'))

        self.assertEqual(response.status_code, 400)
        self.assertEqual(response_json['msg'],
                         'Authorization Header is Expected')
Esempio n. 5
0
    def test_rating_today_meal_fails(self):
        vendor = VendorFactory.create()

        engagement = VendorEngagementFactory.create(vendor=vendor)
        engagement_rating = VendorRatingFactory.build(engagement_id=engagement.id)

        rating_data = {'rating': engagement_rating.rating, 'engagementId': engagement_rating.engagement_id,
                       'serviceDate': datetime.strftime(datetime.now().date(), '%Y-%m-%d'), 'mainMealId': MealItemFactory.create().id}

        response = self.client().post(self.make_url(f'/ratings/order/'), data=self.encode_to_json_string(rating_data),
                                      headers=self.headers())

        self.assertEqual(response.status_code, 400)
    def test_update_vendor_rating(self):
        vendor = VendorFactory.build(location_id=self.location.id)
        new_vendor = self.repo.new_vendor(vendor.name, vendor.address,
                                          vendor.tel, vendor.is_active,
                                          vendor.contact_person,
                                          vendor.location_id)

        engagement = VendorEngagementFactory(location_id=self.location.id,
                                             vendor_id=vendor.id,
                                             vendor=vendor)

        vendor_rating = VendorRatingFactory.build()
        main_meal_id = MealItemFactory.create().id
        vendor_rating = VendorRatingFactory.build(vendor_id=vendor.id,
                                                  engagement_id=engagement.id)
        self.rating_repo.new_rating(
            new_vendor.id, vendor_rating.user_id, 4,
            vendor_rating.service_date, vendor_rating.rating_type,
            vendor_rating.type_id, vendor_rating.engagement_id, main_meal_id,
            vendor_rating.channel, vendor_rating.comment)

        self.repo.update_vendor_average_rating(new_vendor.id)

        self.assertEqual(new_vendor.average_rating, 4)
Esempio n. 7
0
    def test_create_vendor_rating_endpoint(self):
        vendor = VendorFactory.create()

        engagement = VendorEngagementFactory.create(vendor=vendor)
        engagement_rating = VendorRatingFactory.build(engagement_id=engagement.id)

        rating_data = {'rating': engagement_rating.rating, 'engagementId': engagement_rating.engagement_id,
                       'serviceDate': engagement_rating.service_date.strftime('%Y-%m-%d')}

        response = self.client().post(self.make_url(f'/ratings/'), data=self.encode_to_json_string(rating_data),
                                      headers=self.headers())
        response_json = self.decode_from_json_string(response.data.decode('utf-8'))

        self.assertEqual(response.status_code, 201)
        self.assertEqual(response_json['msg'], 'Rating created')
        self.assertEqual(response_json['payload']['rating']['id'], 1)
Esempio n. 8
0
    def test_update_vendor_rating(self):
        vendor = VendorFactory.build()
        new_vendor = self.repo.new_vendor(vendor.name, vendor.address,
                                          vendor.tel, vendor.is_active,
                                          vendor.contact_person,
                                          vendor.location_id)

        vendor_rating = VendorRatingFactory.build()
        self.rating_repo.new_rating(
            new_vendor.id, vendor_rating.user_id, 4,
            vendor_rating.service_date, vendor_rating.rating_type,
            vendor_rating.type_id, vendor_rating.engagement_id,
            vendor_rating.channel, vendor_rating.comment)

        self.repo.update_vendor_average_rating(new_vendor.id)

        self.assertEqual(new_vendor.average_rating, 4)