Пример #1
0
 def test_name_should_not_accept_non_unicode_string(self):
     sport = Sport()
     try:
         sport.name = "Juggling"
     except(TypeError):
         pass
     else:
         self.fail()
Пример #2
0
 def test_max_pace_should_not_accept_negative_value(self):
     sport = Sport()
     try:
         sport.max_pace = -1
     except (ValueError):
         pass
     else:
         self.fail()
Пример #3
0
 def test_name_should_not_accept_none(self):
     sport = Sport()
     try:
         sport.name = None
     except(TypeError):
         pass
     else:
         self.fail()
Пример #4
0
 def test_met_should_not_accept_non_float_string(self):
     sport = Sport()
     try:
         sport.met = "22.5kg"
     except(ValueError):
         pass
     else:
         self.fail()
Пример #5
0
 def test_max_pace_should_not_accept_non_integer_string(self):
     sport = Sport()
     try:
         sport.max_pace = "225s"
     except (ValueError):
         pass
     else:
         self.fail()
Пример #6
0
 def test_weight_should_not_accept_negative_value(self):
     sport = Sport()
     try:
         sport.weight = -1
     except (ValueError):
         pass
     else:
         self.fail()
Пример #7
0
 def test_color_should_not_accept_none(self):
     sport = Sport()
     try:
         sport.color = None
     except (ValueError):
         pass
     else:
         self.fail()
Пример #8
0
 def test_max_pace_should_not_accept_non_integer_string(self):
     sport = Sport()
     try:
         sport.max_pace = "225s"
     except(ValueError):
         pass
     else:
         self.fail()
Пример #9
0
 def test_met_should_not_accept_non_float_string(self):
     sport = Sport()
     try:
         sport.met = "22.5kg"
     except (ValueError):
         pass
     else:
         self.fail()
Пример #10
0
 def test_name_should_not_accept_non_unicode_string(self):
     sport = Sport()
     try:
         sport.name = "Juggling"
     except (TypeError):
         pass
     else:
         self.fail()
Пример #11
0
 def test_id_should_not_accept_non_integer_string(self):
     sport = Sport()
     try:
         sport.id = "1.1"
     except (ValueError):
         pass
     else:
         self.fail()
Пример #12
0
 def test_name_should_not_accept_none(self):
     sport = Sport()
     try:
         sport.name = None
     except (TypeError):
         pass
     else:
         self.fail()
Пример #13
0
 def test_weight_should_not_accept_negative_value(self):
     sport = Sport()
     try:
         sport.weight = -1
     except(ValueError):
         pass
     else:
         self.fail()
Пример #14
0
 def test_color_should_not_accept_none(self):
     sport = Sport()
     try:
         sport.color = None
     except(ValueError):
         pass
     else:
         self.fail()
Пример #15
0
 def test_id_should_not_accept_non_integer_string(self):
     sport = Sport()
     try:
         sport.id = "1.1"
     except(ValueError):
         pass
     else:
         self.fail()
Пример #16
0
 def test_max_pace_should_not_accept_negative_value(self):
     sport = Sport()
     try:
         sport.max_pace = -1
     except(ValueError):
         pass
     else:
         self.fail()
Пример #17
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()
Пример #18
0
 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])
Пример #19
0
 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()
Пример #20
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()
Пример #21
0
 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()
Пример #22
0
 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"])
Пример #23
0
    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])
Пример #24
0
 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")
Пример #25
0
    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"])
Пример #26
0
    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")
Пример #27
0
 def test_store_sport_should_error_when_existing_sport_has_duplicate_name(self):
     def mock_select(table, columns, where):
         if columns == pytrainer.sport._ID_COLUMN:
             return [[2]]
         else:
             return [(1, u"Test name", 0, 0.0, "0"), (2, u"New name", 0, 0.0, "0")]
     self.mock_ddbb.select = mock.Mock(wraps=mock_select)
     sport = Sport()
     sport.id = 1
     sport.name = u"New name"
     try:
         self.sport_service.store_sport(sport)
     except(SportServiceException):
         pass
     else:
         self.fail()
Пример #28
0
 def on_newsport_accept_clicked(self, widget):
     sport = Sport()
     sport.name = unicode(self.newsportentry.get_text())
     sport.met = self._trim_to_null(self.newmetentry.get_text())
     sport.weight = self.newweightentry.get_text()
     sport.max_pace = self._trim_to_null(self.newmaxpace.get_text())
     sport.color = self.stored_color
     if sport.name.lower() in [
             s.name.lower() for s in self._sport_service.get_all_sports()
     ]:
         msg = "Sport '%s' already exists" % sport.name
         logging.error(msg)
         md = gtk.MessageDialog(None, gtk.DIALOG_DESTROY_WITH_PARENT,
                                gtk.MESSAGE_ERROR, gtk.BUTTONS_CLOSE,
                                _(msg))
         md.set_title(_("Sport Creation Error"))
         md.run()
         md.destroy()
         return
     self._sport_service.store_sport(sport)
     self.parent.actualize_mainsportlist()
     self.on_switch_page(None, None, 2)
     self.hidesportsteps()
     self.buttonbox.set_sensitive(1)
     self.sportlist.show()
Пример #29
0
    def test_store_sport_should_error_when_existing_sport_has_duplicate_name(
            self):
        def mock_select(table, columns, where):
            if columns == pytrainer.sport._ID_COLUMN:
                return [[2]]
            else:
                return [(1, u"Test name", 0, 0.0, "0"),
                        (2, u"New name", 0, 0.0, "0")]

        self.mock_ddbb.select = mock.Mock(wraps=mock_select)
        sport = Sport()
        sport.id = 1
        sport.name = u"New name"
        try:
            self.sport_service.store_sport(sport)
        except (SportServiceException):
            pass
        else:
            self.fail()
Пример #30
0
 def test_remove_sport_should_error_when_sport_has_no_id(self):
     self.mock_ddbb.select.return_value = [(1, u"Test name", 150, 12.5, 200,
                                            "0")]
     sport = Sport()
     try:
         self.sport_service.remove_sport(sport)
     except (SportServiceException):
         pass
     else:
         self.fail()
Пример #31
0
    def getSportId(self, sport_name, add=None):
        """Deprecated: use sport_service.get_sport_by_name()
		
		Get the id of a sport by name, optionally adding a new sport if
		none exists with the given name.
		arguments:
			sport_name: sport's name to get id for
			add: whether the sport should be added if not found
		returns: id for sport with given name or None"""
        if sport_name is None:
            return None
        sport = self._get_sport(sport_name)
        if sport is None:
            logging.debug("No sport with name: '%s'", str(sport_name))
            if add is not None:
                logging.debug("Adding sport '%s'", str(sport_name))
                new_sport = Sport()
                new_sport.name = unicode(sport_name)
                sport = self._sport_service.store_sport(new_sport)
        return None if sport is None else sport.id
Пример #32
0
	def getSportId(self, sport_name, add=None):
		"""Deprecated: use sport_service.get_sport_by_name()
		
		Get the id of a sport by name, optionally adding a new sport if
		none exists with the given name.
		arguments:
			sport_name: sport's name to get id for
			add: whether the sport should be added if not found
		returns: id for sport with given name or None"""
		if sport_name is None:
			return None
		sport = self._get_sport(sport_name)
		if sport is None:
			logging.debug("No sport with name: '%s'", str(sport_name))
			if add is not None:
				logging.debug("Adding sport '%s'", str(sport_name))
				new_sport = Sport()
				new_sport.name = unicode(sport_name)
				sport = self._sport_service.store_sport(new_sport)
		return None if sport is None else sport.id
Пример #33
0
    def test_store_sport_should_return_stored_sport(self):
        sport_ids = []

        def update_sport_ids(*args):
            sport_ids.append([1])

        self.mock_ddbb.insert.side_effect = update_sport_ids

        def mock_select(table, columns, where):
            if columns == "id_sports":
                return sport_ids
            else:
                return [(2, u"", 0, 0, 0, "0")]

        self.mock_ddbb.select = mock.Mock(wraps=mock_select)
        sport = Sport()
        stored_sport = self.sport_service.store_sport(sport)
        self.assertEquals(2, stored_sport.id)
Пример #34
0
 def on_newsport_accept_clicked(self,widget):
     sport = Sport()
     sport.name = unicode(self.newsportentry.get_text())
     sport.met = self._trim_to_null(self.newmetentry.get_text())
     sport.weight = self.newweightentry.get_text()
     sport.max_pace = self._trim_to_null(self.newmaxpace.get_text())
     sport.color = self.stored_color
     if sport.name.lower() in [s.name.lower() for s in self._sport_service.get_all_sports()]:
         msg = "Sport '%s' already exists" % sport.name
         logging.error(msg)
         md = gtk.MessageDialog(None, gtk.DIALOG_DESTROY_WITH_PARENT, gtk.MESSAGE_ERROR, gtk.BUTTONS_CLOSE, _(msg))
         md.set_title(_("Sport Creation Error"))
         md.run()
         md.destroy()
         return
     self._sport_service.store_sport(sport)
     self.parent.actualize_mainsportlist()
     self.on_switch_page(None,None,2)
     self.hidesportsteps()
     self.buttonbox.set_sensitive(1)
     self.sportlist.show()
Пример #35
0
 def test_remove_sport_should_delete_sport_with_specified_id(self):
     self.mock_ddbb.select.return_value = [[1]]
     sport = Sport()
     sport.id = 1
     self.sport_service.remove_sport(sport)
     self.mock_ddbb.delete.assert_called_with("sports", "id_sports=1")
Пример #36
0
 def test_id_should_accept_integer(self):
     sport = Sport()
     sport.id = 1
     self.assertEquals(1, sport.id)
Пример #37
0
 def test_id_should_accept_integer_string(self):
     sport = Sport()
     sport.id = "1"
     self.assertEquals(1, sport.id)
Пример #38
0
 def test_met_should_accept_none(self):
     sport = Sport()
     sport.met = None
     self.assertEquals(None, sport.met)
Пример #39
0
 def test_met_should_accept_float_string(self):
     sport = Sport()
     sport.met = "22.5"
     self.assertEquals(22.5, sport.met)
Пример #40
0
 def test_name_should_accept_unicode_string(self):
     sport = Sport()
     sport.name = u"Unicycling"
     self.assertEquals(u"Unicycling", sport.name)
Пример #41
0
 def test_max_pace_should_accept_integer_string(self):
     sport = Sport()
     sport.max_pace = "220"
     self.assertEquals(220, sport.max_pace)
Пример #42
0
 def test_max_pace_should_accept_none(self):
     sport = Sport()
     sport.max_pace = None
     self.assertEquals(None, sport.max_pace)
Пример #43
0
 def test_met_should_default_to_None(self):
     sport = Sport()
     self.assertEquals(None, sport.met)
Пример #44
0
 def test_met_should_accept_float(self):
     sport = Sport()
     sport.met = 22.5
     self.assertEquals(22.5, sport.met)
Пример #45
0
 def test_max_pace_should_take_floor_of_float(self):
     sport = Sport()
     sport.max_pace = 220.6
     self.assertEquals(220, sport.max_pace)
Пример #46
0
 def test_met_should_accept_float_string(self):
     sport = Sport()
     sport.met = "22.5"
     self.assertEquals(22.5, sport.met)
Пример #47
0
 def test_id_should_default_to_none(self):
     sport = Sport()
     self.assertEquals(None, sport.id)
Пример #48
0
 def test_max_pace_should_accept_none(self):
     sport = Sport()
     sport.max_pace = None
     self.assertEquals(None, sport.max_pace)
Пример #49
0
 def test_name_should_accept_unicode_string(self):
     sport = Sport()
     sport.name = u"Unicycling"
     self.assertEquals(u"Unicycling", sport.name)
Пример #50
0
 def test_max_pace_should_accept_integer(self):
     sport = Sport()
     sport.max_pace = 220
     self.assertEquals(220, sport.max_pace)
Пример #51
0
 def test_color_should_default_to_blue(self):
     sport = Sport()
     self.assertEquals(0x0000ff, sport.color.rgb_val)
Пример #52
0
 def test_name_should_default_to_empty_string(self):
     sport = Sport()
     self.assertEquals(u"", sport.name)
Пример #53
0
 def test_met_should_accept_float(self):
     sport = Sport()
     sport.met = 22.5
     self.assertEquals(22.5, sport.met)
Пример #54
0
 def test_remove_sport_should_delete_sport_with_specified_id(self):
     self.mock_ddbb.select.return_value = [[1]]
     sport = Sport()
     sport.id = 1
     self.sport_service.remove_sport(sport)
     self.mock_ddbb.delete.assert_called_with("sports", "id_sports=1")
Пример #55
0
 def test_max_pace_should_take_floor_of_float(self):
     sport = Sport()
     sport.max_pace = 220.6
     self.assertEquals(220, sport.max_pace)
Пример #56
0
 def test_id_should_accept_integer_string(self):
     sport = Sport()
     sport.id = "1"
     self.assertEquals(1, sport.id)
Пример #57
0
 def test_id_should_accept_integer(self):
     sport = Sport()
     sport.id = 1
     self.assertEquals(1, sport.id)
Пример #58
0
 def test_weight_should_accept_float(self):
     sport = Sport()
     sport.weight = 22.5
     self.assertEquals(22.5, sport.weight)