示例#1
0
    def test_rate_value(self,mock_json):
        mock_rate = 555
        example_api_response = {'bpi':{'USD':{'rate_float':mock_rate}}}
        mock_json.side_effect = [example_api_response]
        converted = bitcoin.convert(10)

        self.assertEqual(5550 , converted)
示例#2
0
 def test_get_price_in_us_dollar(self, mock_rates):
     mock_rate = 12345.67
     api_response = {'rate': mock_rate}
     mock_rates.side_effect = [api_response]
     bitcoins = 10
     formatting = bitcoins * mock_rate
     conversion = bitcoin.convert(mock_rate, bitcoins)
     self.assertEqual(formatting, conversion)
示例#3
0
def coins_tag(context, satoshis):
    user = context.request.user
    if user.is_authenticated():
        unit = user.profile.preferred_unit()
    else:
        unit = bitcoin.BTC
    if satoshis is None:
        return unit.symbol_html()
    return bitcoin.format_coins_for_html(bitcoin.convert(satoshis, bitcoin.SATOSHI, unit), unit)
示例#4
0
    def test_get_usd_price(self, mock_rates):
        mock_rate = 8594.25
        example_api_response = {'rate': mock_rate}
        mock_rates.side_effect = [example_api_response]
        bitcoins = float(bitcoin.getCoins())
        expected = bitcoins * mock_rate
        converted = bitcoin.convert(mock_rate, bitcoins)
        self.assertEqual(expected, converted)


##Tests my convert function in bitcoin.py
##I have a mock rate and an example api response
##calls get coins to get user input of coins, calculates
##expected conversion, compares it with what my function does
## and asserts they are the same
示例#5
0
 def test_conversion_based_off_api(self, mock_rates):
     mock_rate = 121212.00
     example_api_response = {
         'time': {
             'updated': 'Feb 26, 2020 22:12:00 UTC',
             'updatedISO': '2020-02-26T22:12:00+00:00',
             'updateduk': 'Feb 26, 2020 at 22:12 GMT'
         },
         'disclaimer':
         'This data was produced from the CoinDesk Bitcoin Price Index (USD). Non-USD currency data converted using hourly conversion rate from openexchangerates.org',
         'chartName': 'Bitcoin',
         'bpi': {
             'USD': {
                 'code': 'USD',
                 'symbol': '$',
                 'rate': '8,788.4483',
                 'description': 'United States Dollar',
                 'rate_float': mock_rate
             },
             'GBP': {
                 'code': 'GBP',
                 'symbol': '£',
                 'rate': '6,812.1548',
                 'description': 'British Pound Sterling',
                 'rate_float': 6812.1548
             },
             'EUR': {
                 'code': 'EUR',
                 'symbol': '€',
                 'rate': '8,077.0586',
                 'description': 'Euro',
                 'rate_float': 8077.0586
             }
         }
     }
     mock_rates.side_effect = [example_api_response]
     converted = bitcoin.convert(100)
     self.assertEqual(12121200.00, converted)
示例#6
0
 def testConvert(self, mockRate):
     mockRateFloat = 1111.11
     exampleApiResponse = {'bpi': 'USD', 'rateFloat': mockRateFloat}
     mockRateSideEffect = [exampleApiResponse]
     converted = bitcoin.convert(100, mockRateFloat)
     self.assertEqual(111111, converted)