import unittest
import json

from src.models import Weather


class TestWeather(unittest.TestCase):
    """Testing the Weather model of the project"""

    def setUp(self):
        self.json_api_response = open("./fixtures/weather.json").read()
        self.dict_api_response = json.loads(self.json_api_response)

    def test_json_constructor(self):
        """Weather objects can be correctly created from OWM api response in JSON format"""
        test_weather = Weather(api_response=self.json_api_response)

        self.assertEqual(test_weather.id, 300)
        self.assertEqual(test_weather.main, 'Drizzle')
        self.assertEqual(test_weather.description, 'light intensity drizzle')
        self.assertEqual(test_weather.icon, '09d')

    def test_dict_constructor(self):
        """Weather objects can be correctly created from a dict containing OWM's API response"""
        test_weather = Weather(weather_info=self.dict_api_response)

        self.assertEqual(test_weather.id, 300)
        self.assertEqual(test_weather.main, 'Drizzle')
        self.assertEqual(test_weather.description, 'light intensity drizzle')
        self.assertEqual(test_weather.icon, '09d')

    def test_weather_is_bad_returns_false_when_weather_is_good(self):
        """Testing that the method Weather.is_bad() returns True when the weather condition is a good one"""
        test_weather = Weather(weather_info=self.dict_api_response)

        test_weather.id = 800
        self.assertFalse(test_weather.is_bad())
        test_weather.id = 801
        self.assertFalse(test_weather.is_bad())
        test_weather.id = 802
        self.assertFalse(test_weather.is_bad())
        test_weather.id = 803
        self.assertFalse(test_weather.is_bad())
        test_weather.id = 804
        self.assertFalse(test_weather.is_bad())
        test_weather.id = 951
        self.assertFalse(test_weather.is_bad())

    def test_weather_is_bad_returns_true_when_weather_is_bad(self):
        """Testing that the method Weather.is_bad() returns True when the weather condition is a good one"""
        test_weather = Weather(weather_info=self.dict_api_response)

        test_weather.id = 300
        self.assertTrue(test_weather.is_bad())
        test_weather.id = 473
        self.assertTrue(test_weather.is_bad())
        test_weather.id = 2432
        self.assertTrue(test_weather.is_bad())


if __name__ == '__main__':
    unittest.__main__()

@@ -513,33 +513,23 @@
         
-self.
 assert
-Equal(
+ 
 test_wea
@@ -527,38 +527,39 @@
  test_weather.id
-,
+ ==
  300
-)
 %0A        self.as
@@ -551,33 +551,23 @@
         
-self.
 assert
-Equal(
+ 
 test_wea
@@ -567,33 +567,35 @@
 est_weather.main
-,
+ ==
  'Drizzle')%0A    
@@ -580,33 +580,32 @@
 ain == 'Drizzle'
-)
 %0A        self.as
@@ -597,33 +597,23 @@
         
-self.
 assert
-Equal(
+ 
 test_wea
@@ -620,33 +620,35 @@
 ther.description
-,
+ ==
  'light intensit
@@ -649,33 +649,32 @@
 tensity drizzle'
-)
 %0A        self.as
@@ -666,33 +666,23 @@
         
-self.
 assert
-Equal(
+ 
 test_wea
@@ -686,32 +686,33 @@
 weather.icon
-,
+ ==
  '09d'
-)
 %0A%0A    def te
@@ -912,33 +912,23 @@
         
-self.
 assert
-Equal(
+ 
 test_wea
@@ -938,14 +938,15 @@
 r.id
-,
+ ==
  300
-)
 %0A   
@@ -950,33 +950,23 @@
         
-self.
 assert
-Equal(
+ 
 test_wea
@@ -974,17 +974,19 @@
 her.main
-,
+ ==
  'Drizzl
@@ -983,25 +983,24 @@
 == 'Drizzle'
-)
 %0A        sel
@@ -996,33 +996,23 @@
         
-self.
 assert
-Equal(
+ 
 test_wea
@@ -1027,17 +1027,19 @@
 cription
-,
+ ==
  'light 
@@ -1056,17 +1056,16 @@
 drizzle'
-)
 %0A       
@@ -1069,25 +1069,15 @@
     
-self.
 assert
-Equal(
+ 
 test
@@ -1093,16 +1093,17 @@
 icon
-,
+ ==
  '09d'
-)
 %0A%0A  

Revert "Refactoring previous tests"