help@rskworld.in +91 93305 39277
RSK World
  • Home
  • Development
    • Web Development
    • Mobile Apps
    • Software
    • Games
    • Project
  • Technologies
    • Data Science
    • AI Development
    • Cloud Development
    • Blockchain
    • Cyber Security
    • Dev Tools
    • Testing Tools
  • Blog
  • About
  • Contact

Theme Settings

Color Scheme
Display Options
Font Size
100%
Back to Project
RSK World
weather-chatbot
/
tests
RSK World
weather-chatbot
Weather Chatbot - Python + Flask + OpenWeatherMap + OpenAI + Weather Forecast + Weather Alerts + Natural Language Processing
tests
  • __init__.py110 B
  • conftest.py1.3 KB
  • test_app.py3.3 KB
  • test_utils.py1.8 KB
  • test_weather_api.py1.6 KB
test_weather_api.py
tests/test_weather_api.py
Raw Download
Find: Go to:
#!/usr/bin/env python3
"""
Weather API Tests
=================

Author: RSK World (https://rskworld.in)
Year: 2026

Description: Unit tests for weather API functionality
"""

import pytest
import os
import sys
from unittest.mock import patch, MagicMock

sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), '..')))

from weather_api import get_weather

def test_get_weather_success():
    """Test successful weather API call."""
    mock_response = MagicMock()
    mock_response.json.return_value = {
        'name': 'London',
        'main': {'temp': 15, 'humidity': 60},
        'weather': [{'description': 'clear sky'}]
    }
    mock_response.raise_for_status = MagicMock()
    
    with patch('weather_api.requests.get', return_value=mock_response):
        with patch.dict(os.environ, {'OPENWEATHER_API_KEY': 'test_key'}):
            result = get_weather('London')
            assert 'name' in result
            assert result['name'] == 'London'

def test_get_weather_error():
    """Test weather API error handling."""
    with patch('weather_api.requests.get', side_effect=Exception('Network error')):
        with patch.dict(os.environ, {'OPENWEATHER_API_KEY': 'test_key'}):
            result = get_weather('London')
            assert 'error' in result

def test_get_weather_missing_key():
    """Test weather API with missing API key."""
    with patch.dict(os.environ, {}, clear=True):
        result = get_weather('London')
        # Should handle missing key gracefully
        assert result is not None
50 lines•1.6 KB
python

About RSK World

Founded by Molla Samser, with Designer & Tester Rima Khatun, RSK World is your one-stop destination for free programming resources, source code, and development tools.

Founder: Molla Samser
Designer & Tester: Rima Khatun

Development

  • Game Development
  • Web Development
  • Mobile Development
  • AI Development
  • Development Tools

Legal

  • Terms & Conditions
  • Privacy Policy
  • Disclaimer

Contact Info

Nutanhat, Mongolkote
Purba Burdwan, West Bengal
India, 713147

+91 93305 39277

hello@rskworld.in
support@rskworld.in

© 2026 RSK World. All rights reserved.

Content used for educational purposes only. View Disclaimer