Exemplo n.º 1
0
def product(id):
    helper = Helper()
    url = "http://redsky.target.com/v2/pdp/tcin/" + str(
        id
    ) + "?excludes=taxonomy,price,promotion,bulk_ship" + (
        ",rating_and_review_reviews,rating_and_review_statistics,question_answer_statistics"
    )
    response = urllib.urlopen(url)
    data = json.loads(response.read())

    if request.method == 'GET' and helper.product_exist(data):
        # Combine and format external API result and Redis pull if request method is GET and
        # product exist in the external API
        formatted_search = helper.format_data(id, data)
        return jsonify(formatted_search)

    elif request.method == 'PUT' and helper.product_exist(data):
        # Update price information in Redis if request method is PUT and product exist in the
        # external API

        req = request.get_json()
        helper.redis_update_pricing_info(
            'product', id,
            data['product']['item']['product_description']['title'],
            req['current_price'])
        return request.data

    else:
        # If we get into this logic branch, then id did not return anything from external API
        return 'Product not found.'
Exemplo n.º 2
0
 def test_redis_update_pricing_info_values_raise_exception(self, mock_hset):
     """Test exception is raised if hset fails"""
     fake_helper = Helper()
     with self.assertRaises(Exception):
         mock_hset.side_effect = Exception
         fake_helper.redis_update_pricing_info('value', 'value', 'value',
                                               FAKE_VALUES)
Exemplo n.º 3
0
 def test_redis_update_pricing_info_values_update_data(self, mock_hset):
     """Test happy path. No exceptions"""
     fake_helper = Helper()
     fake_helper.redis_update_pricing_info('value', 'value', 'value',
                                           FAKE_VALUES)
     mock_hset.assert_called()
Exemplo n.º 4
0
 def test_redis_update_pricing_info_values_is_not_dict(self):
     """Test that TypeError is raised if values is not a dictionary"""
     fake_helper = Helper()
     with self.assertRaises(TypeError):
         fake_helper.redis_update_pricing_info('value', 'value', 'value', 2)