Answered step by step
Verified Expert Solution
Link Copied!
Question
1 Approved Answer

Write a test for your Bitcoin program (from the API topic) that converts a number of Bitcoin to their value in US Dollars. Structure your

Write a test for your Bitcoin program (from the API topic) that converts a number of Bitcoin to their value in US Dollars.

Structure your program so you don't need to mock user input. 

Structure your program so it's possible to isolate and then mock the API call. 

Mock the API call by providing a mock JSON response. Assert that your program calculates the correct value in dollars.

import requests url = 'https://api.coindesk.com/v1/bpi/currentprice.json  

import requests url = https://api.coindesk.com/v1/bpi/currentprice.json" def main(): bitcoin get_bitcoin_amount() dollars convert_bitcoin_to_dollars (bitcoin) display_results (bitcoin, dollars) def get_bitcoin_amount(): while True: try: if bitcoin - float(input('Enter the number of bitcoin: ')) if bitcoin > 0: return bitcoin else: print(" Please enter a number greater than e') except ValueError: def convert_bitcoin_to_dollars (bitcoin): rate_json = get_bitcoin_data() exchange_rate= extract_rate(rate_json) print('Enter a positive number.') bitcoin = exchange rate * bitcoin return bitcoin # this function will be mocked i def get bitcoin_data(): name main() return requests.get(url).json() def extract_rate(rate_json): return rate_json["bpi']['USD']['rate_float'] def display_results (bitcoin, dollars): print (f {bitcoin) bitcoin is equal to ${dollars}') main

Step by Step Solution

3.46 Rating (153 Votes )

There are 3 Steps involved in it

Step: 1

To write a test for your Bitcoin program you can use the unittest library in Python to create a test ... blur-text-image
Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Financial Reporting Financial Statement Analysis And Valuation A Strategic Perspective

Authors: James M. Wahlen, Stephen P. Baginski, Mark Bradshaw

9th Edition

1337614689, 1337614688, 9781337668262, 978-1337614689

More Books

Students explore these related Programming questions

Question

1.25-(7500/150000*1)+(7500/150000*0.8)

Answered: 3 weeks ago