def test_id_should_accept_integer_string(self): sport = Sport() sport.id = "1" self.ddbb.session.add(sport) self.ddbb.session.commit() sport = self.ddbb.session.query(Sport).filter(Sport.id == 1).one() self.assertEquals(1, sport.id)
def test_max_pace_should_take_floor_of_float(self): sport = Sport() sport.max_pace = 220.6 self.ddbb.session.add(sport) self.ddbb.session.commit() sport = self.ddbb.session.query(Sport).filter(Sport.id == 1).one() self.assertEquals(220, sport.max_pace)
def test_remove_sport_should_remove_associated_entries(self): sport = Sport() sport.name = u"Test name" sport = self.sport_service.store_sport(sport) self.sport_service.remove_sport(sport) result = self.sport_service.get_sport(1) self.assertEqual(result, None)
def test_max_pace_should_take_floor_of_float(self): sport = Sport() sport.max_pace = 220.6 self.ddbb.session.add(sport) self.ddbb.session.commit() sport = self.ddbb.session.query(Sport).filter(Sport.id == 1).one() self.assertEqual(220, sport.max_pace)
def test_id_should_accept_integer_string(self): sport = Sport() sport.id = "1" self.ddbb.session.add(sport) self.ddbb.session.commit() sport = self.ddbb.session.query(Sport).filter(Sport.id == 1).one() self.assertEqual(1, sport.id)
def test_remove_sport_should_remove_associated_entries(self): sport = Sport() sport.name = u"Test name" sport = self.sport_service.store_sport(sport) self.sport_service.remove_sport(sport) result = self.sport_service.get_sport(1) self.assertEquals(result, None)
def test_met_should_accept_float_string(self): sport = Sport() sport.name = "test1" sport.met = "22.5" self.ddbb.session.add(sport) self.ddbb.session.commit() sport = self.ddbb.session.query(Sport).filter(Sport.id == 1).one() self.assertEquals(22.5, sport.met)
def test_name_should_not_accept_non_unicode_string(self): sport = Sport() try: sport.name = "Juggling" except(TypeError): pass else: self.fail()
def test_met_should_accept_float_string(self): sport = Sport() sport.name = "test1" sport.met = "22.5" self.ddbb.session.add(sport) self.ddbb.session.commit() sport = self.ddbb.session.query(Sport).filter(Sport.id == 1).one() self.assertEqual(22.5, sport.met)
def test_weight_should_not_accept_negative_value(self): sport = Sport() try: sport.weight = -1 except(ValueError): pass else: self.fail()
def test_id_should_not_accept_non_integer_string(self): sport = Sport() try: sport.id = "1.1" except(ValueError): pass else: self.fail()
def test_met_should_not_accept_non_float_string(self): sport = Sport() try: sport.met = "22.5kg" except(ValueError): pass else: self.fail()
def test_color_should_not_accept_none(self): sport = Sport() try: sport.color = None except(ValueError): pass else: self.fail()
def test_store_sport_should_update_row_when_sport_has_id(self): sport = Sport() sport.name = u"Test name" sport = self.sport_service.store_sport(sport) sport.name = u"New name" self.sport_service.store_sport(sport) sport = self.sport_service.get_sport(1) self.assertEqual(sport.name, u"New name")
def test_max_pace_should_not_accept_negative_value(self): sport = Sport() try: sport.max_pace = -1 except(ValueError): pass else: self.fail()
def test_name_should_not_accept_none(self): sport = Sport() try: sport.name = None except(TypeError): pass else: self.fail()
def test_max_pace_should_not_accept_non_integer_string(self): sport = Sport() try: sport.max_pace = "225s" except(ValueError): pass else: self.fail()
def test_store_sport_should_update_row_when_sport_has_id(self): sport = Sport() sport.name = u"Test name" sport = self.sport_service.store_sport(sport) sport.name = u"New name" self.sport_service.store_sport(sport) sport = self.sport_service.get_sport(1) self.assertEquals(sport.name, u"New name")
def test_remove_sport_should_error_when_sport_has_unknown_id(self): sport = Sport() sport.id = 100 try: self.sport_service.remove_sport(sport) except (SportServiceException): pass else: self.fail()
def test_remove_sport_should_error_when_sport_has_unknown_id(self): sport = Sport() sport.id = 100 try: self.sport_service.remove_sport(sport) except(SportServiceException): pass else: self.fail()
def test_name_should_not_accept_non_unicode_string(self): sport = Sport() sport.name = "Juggling" + chr(255) try: self.ddbb.session.add(sport) self.ddbb.session.flush() except (ProgrammingError, DataError, OperationalError): pass else: self.fail()
def test_id_should_not_accept_non_integer_string(self): sport = Sport() try: sport.id = "test" self.ddbb.session.add(sport) self.ddbb.session.flush() except (IntegrityError, DataError, OperationalError): pass else: self.fail()
def test_met_should_not_accept_non_float_string(self): sport = Sport() sport.met = "22.5kg" try: self.ddbb.session.add(sport) self.ddbb.session.flush() except (ValueError, StatementError): pass else: self.fail()
def test_weight_should_not_accept_non_float_string(self): sport = Sport() sport.weight = "22.5kg" try: self.ddbb.session.add(sport) self.ddbb.session.flush() except StatementError: pass else: self.fail()
def test_max_pace_should_not_accept_non_integer_string(self): sport = Sport() sport.max_pace = "225s" try: self.ddbb.session.add(sport) self.ddbb.session.flush() except (ValueError, StatementError): pass else: self.fail()
def test_name_should_not_accept_non_unicode_string(self): sport = Sport() sport.name = "Juggling" + chr(255) try: self.ddbb.session.add(sport) self.ddbb.session.flush() except (ProgrammingError, DataError): pass else: self.fail()
def test_id_should_not_accept_non_integer_string(self): sport = Sport() try: sport.id = "test" self.ddbb.session.add(sport) self.ddbb.session.flush() except (IntegrityError, DataError): pass else: self.fail()
def test_name_should_not_accept_none(self): sport = Sport() sport.name = None try: self.ddbb.session.add(sport) self.ddbb.session.commit() except (IntegrityError, OperationalError): pass else: self.fail()
def test_color_should_not_accept_none(self): sport = Sport() sport.color = None try: self.ddbb.session.add(sport) self.ddbb.session.commit() except StatementError: pass else: self.fail()
def test_max_pace_should_not_accept_negative_value(self): sport = Sport() sport.max_pace = -1 try: self.ddbb.session.add(sport) self.ddbb.session.flush() except (IntegrityError, InterfaceError): pass else: self.fail()
def test_weight_should_not_accept_none(self): sport = Sport() sport.weight = None try: self.ddbb.session.add(sport) self.ddbb.session.flush() except (IntegrityError, OperationalError): pass else: self.fail()
def test_met_should_not_accept_non_float_string(self): sport = Sport() sport.met = "22.5kg" try: self.ddbb.session.add(sport) self.ddbb.session.flush() except(ValueError, StatementError): pass else: self.fail()
def test_remove_sport_should_remove_associated_entries(self): self.mock_ddbb.select.return_value = [[1]] sport = Sport() sport.id = 1 delete_arguments = [] def mock_delete(*args): delete_arguments.append(args) self.mock_ddbb.delete = mock.Mock(wraps=mock_delete) self.sport_service.remove_sport(sport) self.assertEquals(("records", "sport=1"), delete_arguments[0])
def test_remove_sport_should_error_when_sport_has_unknown_id(self): self.mock_ddbb.select.return_value = [] sport = Sport() sport.id = 100 try: self.sport_service.remove_sport(sport) except(SportServiceException): pass else: self.fail()
def test_max_pace_should_not_accept_non_integer_string(self): sport = Sport() sport.max_pace = "225s" try: self.ddbb.session.add(sport) self.ddbb.session.flush() except(ValueError, StatementError): pass else: self.fail()
def test_store_sport_should_error_when_new_sport_has_duplicate_name(self): self.mock_ddbb.select.return_value = [(1, u"Test name", 150, 12.5, 200, "0")] sport = Sport() sport.name = u"Test name" try: self.sport_service.store_sport(sport) except(SportServiceException): pass else: self.fail()
def test_max_pace_should_not_accept_negative_value(self): if self.ddbb.engine.name == 'mysql': self.skipTest('Check constraints not available on Mysql') sport = Sport() sport.max_pace = -1 try: self.ddbb.session.add(sport) self.ddbb.session.flush() except (IntegrityError, InterfaceError): pass else: self.fail()
def test_store_sport_should_insert_row_when_sport_has_no_id(self): def mock_select(table, columns, where): call_count = self.mock_ddbb.select.call_count if call_count == 2: return [[1]] return [] self.mock_ddbb.select = mock.Mock(wraps=mock_select) sport = Sport() sport.name = u"Test name" self.sport_service.store_sport(sport) self.mock_ddbb.insert.assert_called_with("sports", "name,weight,met,max_pace,color", [u"Test name", 0.0, None, None, "0000ff"])
def test_name_should_not_accept_non_unicode_string(self): if self.ddbb.engine.name == 'mysql': self.skipTest('Not supported on Mysql 5.6') sport = Sport() sport.name = "Juggling" + chr(255) try: self.ddbb.session.add(sport) self.ddbb.session.flush() except (ProgrammingError, DataError, OperationalError): pass else: self.fail()
def test_store_sport_should_error_when_new_sport_has_duplicate_name(self): sport1 = Sport() sport1.name = u"Test name" self.sport_service.store_sport(sport1) sport2 = Sport() sport2.name = u"Test name" try: self.sport_service.store_sport(sport2) except(SportServiceException): pass else: self.fail()
def test_id_should_not_accept_non_integer_string(self): if self.ddbb.engine.name == 'mysql': self.skipTest('Not supported on Mysql 5.6') sport = Sport() try: sport.id = "test" self.ddbb.session.add(sport) self.ddbb.session.flush() except (IntegrityError, DataError, OperationalError): pass else: self.fail()
def test_get_all_sports_should_return_all_sports_in_query_result(self): sport1 = Sport() sport1.name = u"Test name" self.sport_service.store_sport(sport1) sport2 = Sport() sport2.name = u"Test name 2" self.sport_service.store_sport(sport2) sports = self.sport_service.get_all_sports() self.assertEqual(2, len(sports)) sport1 = sports[0] self.assertEqual(1, sport1.id) sport2 = sports[1] self.assertEqual(2, sport2.id)
def test_store_sport_should_update_row_when_sport_has_id(self): def mock_select(table, columns, where): if columns == "id_sports": return [[1]] else: return [(1, u"", 0, 0, 0, "0")] self.mock_ddbb.select = mock.Mock(wraps=mock_select) sport = Sport() sport.id = 1 sport.name = u"New name" self.sport_service.store_sport(sport) self.mock_ddbb.update.assert_called_with("sports", "name,weight,met,max_pace,color", [u"New name", 0.0, None, None, "0000ff"], "id_sports=1")