Skip to content

Spring2025_Testing_Crypto_API_with_mock #518

@LeonFeng21

Description

@LeonFeng21

Difficulty: 2 (Medium)

Description:
This project introduces students to Python's unittest.mock module, a standard and powerful tool for creating mock objects and testing code that interacts with external systems. In this project, we will build a simple Bitcoin price alert system and test its behavior using mocked API responses.

Technology:
unittest.mock is part of Python's standard library. It allows developers to simulate external dependencies such as APIs or databases. This is useful for isolating test environments, simulating edge cases, and ensuring correctness without relying on real-time or real-world data.

Goal:
Create a Bitcoin price alert system that:

  1. Fetches Bitcoin price from CoinGecko (real or mocked)
  2. Compares price to a user-defined threshold
  3. Raises alert if threshold is crossed
  4. Tests all logic using unittest.mock

Steps:

  • Develop get_price, check_alert, and send_alert functions
  • Implement real API call logic (using requests)
  • Use unittest.mock.patch() to simulate different price scenarios
  • Write unit tests for each component
  • Package into Mock_utils.py, and show working examples via notebook + markdown

**Useful resources:
unittest.mock Documentation
Real Python: Understanding the Python Mock Object Library
CoinGecko API Documentation

**Is it free? Yes, unittest.mock is part of Python's standard library and is free to use. CoinGecko provides free access to its API with certain rate limits, suitable for educational purposes.​

**Python libraries / bindings:
unittest.mock: For creating mock objects and patching dependencies during testing.
requests: To make HTTP requests for fetching data from APIs.​
pandas: For data manipulation and analysis.​

This project offers students practical experience in developing applications that interact with external APIs and implementing unit tests using mock objects to ensure code reliability without depending on live data.​

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions