Skip to content

Commit

Permalink
test cases for converted prices
Browse files Browse the repository at this point in the history
  • Loading branch information
la3679 committed Apr 11, 2024
1 parent fcb7e75 commit 992e088
Showing 1 changed file with 47 additions and 0 deletions.
47 changes: 47 additions & 0 deletions PCP/server/tests/1_api/test_10_conerted_prices.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import unittest
from unittest.mock import patch
from flask import Flask
from flask_restful import Api
from src.api.converted_prices_api import IndianConvertedPricesAPI, CanadianPricesAPI, AllPricesAPI

class ConvertedPricesAPITestCase(unittest.TestCase):
@classmethod
def setUpClass(cls):
cls.app = Flask(__name__)
api = Api(cls.app)
api.add_resource(IndianConvertedPricesAPI, '/indian_prices')
api.add_resource(CanadianPricesAPI, '/canadian_prices')
api.add_resource(AllPricesAPI, '/all_prices')
cls.client = cls.app.test_client()

@patch('src.db.converted_price.get_indian_converted_prices')
def test_indian_converted_prices(self, mock_get_prices):
mock_get_prices.return_value = [[1, 1, '95713.67', 'INR']] # Mock data just needs to be non-empty

response = self.client.get('/indian_prices')
self.assertEqual(response.status_code, 200)
self.assertIsNotNone(response.json) # Check that the response is not null
self.assertTrue(len(response.json) > 0) # Check that there is some data

@patch('src.db.converted_price.get_canadian_prices')
def test_canadian_prices(self, mock_get_prices):
mock_get_prices.return_value = [[41, 41, '1563.99', 'CAD']] # Mock data just needs to be non-empty

response = self.client.get('/canadian_prices')
self.assertEqual(response.status_code, 200)
self.assertIsNotNone(response.json) # Check that the response is not null
self.assertTrue(len(response.json) > 0) # Check that there is some data

@patch('src.db.converted_price.get_all_prices')
def test_all_prices(self, mock_get_prices):
mock_get_prices.return_value = [
[1, 1, '95713.67', 'INR'], [41, 41, '1563.99', 'CAD']
] # Mock data just needs to be non-empty

response = self.client.get('/all_prices')
self.assertEqual(response.status_code, 200)
self.assertIsNotNone(response.json) # Check that the response is not null
self.assertTrue(len(response.json) > 0) # Check that there is some data

if __name__ == '__main__':
unittest.main()

0 comments on commit 992e088

Please sign in to comment.