class Test_updates(object): @classmethod def setup_class(self): """ Setup code run before any tests are run """ self.alert = Alert({ 'id': 'testAlert', 'onsetDate': datetime(1997, 7, 16, 19, 20, tzinfo=tzoffset(None, 3600)), 'expireDate': datetime(2000, 7, 16, 19, 20, tzinfo=tzoffset(None, 3600)), '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[:] self.alert.add_all_locations([(00.00, 00.00), (11.11, 11.11)]) self.alert.onsetDate = datetime(1997, 7, 16, 19, 20, tzinfo=tzoffset(None, 3600)) self.alert.expireDate = datetime(2000, 7, 16, 19, 20, tzinfo=tzoffset(None, 3600)) self.alert.isUpdate = False def test_update_onsetDate_happy_path(self): assert_equal(self.alert.onsetDate, parse("1997-07-16T19:20+01:00")) self.alert.update_onsetDate("1998-07-16T19:20+01:00") assert_equal(self.alert.onsetDate, parse("1998-07-16T19:20+01:00")) def test_update_expireDate_happy_path(self): assert_equal(self.alert.expireDate, parse("2000-07-16T19:20+01:00")) self.alert.update_expireDate("1997-08-16T19:20+01:00") assert_equal(self.alert.expireDate, parse("1997-08-16T19:20+01:00")) def test_update_locations_happy_path(self): assert_equal(len(self.alert.locations), 2) self.alert.update_locations([(90, 180)]) assert_equal(len(self.alert.locations), 1) assert_true((90, 180) in self.alert.locations) assert_false((11.11, 11.11) in self.alert.locations) def test_update_alert_happy_path(self): self.alert.update_alert({ 'id': 'testAlert', 'onsetDate': datetime(1998, 7, 16, 19, 20, tzinfo=tzoffset(None, 3600)), 'expireDate': datetime(1998, 7, 23, 19, 20, tzinfo=tzoffset(None, 3600)), 'isUpdate': True, 'locations': [(33.33, 33.33), (44.44, 44.44), (55.55, 55.55)] }) assert_equal(self.alert.onsetDate, parse("1998-07-16T19:20+01:00")) assert_equal(self.alert.expireDate, parse("1998-07-23T19:20+01:00")) assert_true(self.alert.isUpdate) assert_equal(len(self.alert.locations), 3) assert_false((11.11, 11.11) in self.alert.locations) assert_true((33.33, 33.33) in self.alert.locations) def test_update_alert_non_matching_id(self): self.alert.update_alert({ 'id': 'differentAlert', 'onsetDate': datetime(1998, 7, 16, 19, 20, tzinfo=tzoffset(None, 3600)), 'expireDate': datetime(1998, 7, 23, 19, 20, tzinfo=tzoffset(None, 3600)), 'isUpdate': True, 'locations': [(33.33, 33.33), (44.44, 44.44), (55.55, 55.55)] }) assert_not_equal(self.alert.onsetDate, parse("1998-07-16T19:20+01:00")) assert_not_equal(self.alert.expireDate, parse("1998-07-23T19:20+01:00")) assert_false(self.alert.isUpdate) assert_not_equal(len(self.alert.locations), 3) assert_true((11.11, 11.11) in self.alert.locations) assert_false((33.33, 33.33) in self.alert.locations)