Пример #1
0
class Test_add_and_remove_locations(object):
    @classmethod
    def setup_class(self):
        """
        Setup code run before any tests are run
        """
        self.alert = Alert({    'id': None,
                                'onsetDate': None,
                                'expireDate': None,
                                'isUpdate': False,
                                'isCancel': False,
                                'locations':[] 
                            })

    @classmethod
    def teardown_class(self):
        """
        Teardown code run after all tests are run
        """
        self.alert = None

    def setUp(self):
        """
        Run before each test method is run
        """
        del self.alert.locations[:]

    def test_add_location_happy_path(self):
        assert_equal(len(self.alert.locations), 0)
        self.alert.add_location((00.00, 00.00))
        assert_equal(len(self.alert.locations), 1)

    def test_add_location_max_vals(self):
        assert_equal(len(self.alert.locations), 0)
        self.alert.add_location((90, 180))
        assert_equal(len(self.alert.locations), 1)    

    def test_add_location_min_vals(self):
        assert_equal(len(self.alert.locations), 0)
        self.alert.add_location((-90, -180))
        assert_equal(len(self.alert.locations), 1)    

    def test_add_location_latitude_too_high(self):
        assert_equal(len(self.alert.locations), 0)
        self.alert.add_location((91, 180))
        assert_equal(len(self.alert.locations), 0)      

    def test_add_location_latitude_too_low(self):
        assert_equal(len(self.alert.locations), 0)
        self.alert.add_location((-91, 180))
        assert_equal(len(self.alert.locations), 0)       

    def test_add_location_longitude_too_high(self):
        assert_equal(len(self.alert.locations), 0)
        self.alert.add_location((90, 181))
        assert_equal(len(self.alert.locations), 0)            

    def test_add_location_longitude_too_low(self):
        assert_equal(len(self.alert.locations), 0)
        self.alert.add_location((90, -181))
        assert_equal(len(self.alert.locations), 0)        

    def test_add_location_latitude_string(self):
        assert_equal(len(self.alert.locations), 0)
        self.alert.add_location(('90', 180))
        assert_equal(len(self.alert.locations), 0)       

    def test_add_location_longitide_string(self):
        assert_equal(len(self.alert.locations), 0)
        self.alert.add_location((90, '180'))
        assert_equal(len(self.alert.locations), 0)     

    def test_add_location_both_string(self):
        assert_equal(len(self.alert.locations), 0)
        self.alert.add_location(('90', '180'))
        assert_equal(len(self.alert.locations), 0)     

    def test_add_location_both_non_numeric(self):
        assert_equal(len(self.alert.locations), 0)
        self.alert.add_location(('aaaa', 'bbbb'))
        assert_equal(len(self.alert.locations), 0)    

    def test_remove_location_happy_path(self):
        self.alert.add_location((00.00, 00.00))
        assert_equal(len(self.alert.locations), 1)
        self.alert.remove_location((00.00, 00.00))
        assert_equal(len(self.alert.locations), 0)

    def test_remove_location_not_present(self):
        self.alert.add_location((00.00, 00.00))
        assert_equal(len(self.alert.locations), 1)
        self.alert.remove_location((90.00, 90.00))
        assert_equal(len(self.alert.locations), 1)        

    def test_add_all_locations_happy_path(self):
        assert_equal(len(self.alert.locations), 0)
        self.alert.add_all_locations([(00.00, 00.00), (30.23, 40.89), (11.11,22.22)])
        assert_equal(len(self.alert.locations), 3)

    def test_add_all_locations_empty_list(self):
        assert_equal(len(self.alert.locations), 0)
        self.alert.add_all_locations([])
        assert_equal(len(self.alert.locations), 0)