-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
47 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |