Exemplo n.º 1
0
 def test_name_should_not_accept_non_unicode_string(self):
     sport = Sport()
     try:
         sport.name = "Juggling"
     except(TypeError):
         pass
     else:
         self.fail()
Exemplo n.º 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()
Exemplo n.º 3
0
 def test_name_should_not_accept_none(self):
     sport = Sport()
     try:
         sport.name = None
     except(TypeError):
         pass
     else:
         self.fail()
Exemplo n.º 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()
Exemplo n.º 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()
Exemplo n.º 6
0
 def test_weight_should_not_accept_negative_value(self):
     sport = Sport()
     try:
         sport.weight = -1
     except (ValueError):
         pass
     else:
         self.fail()
Exemplo n.º 7
0
 def test_color_should_not_accept_none(self):
     sport = Sport()
     try:
         sport.color = None
     except (ValueError):
         pass
     else:
         self.fail()
Exemplo n.º 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()
Exemplo n.º 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()
Exemplo n.º 10
0
 def test_name_should_not_accept_non_unicode_string(self):
     sport = Sport()
     try:
         sport.name = "Juggling"
     except (TypeError):
         pass
     else:
         self.fail()
Exemplo n.º 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()
Exemplo n.º 12
0
 def test_name_should_not_accept_none(self):
     sport = Sport()
     try:
         sport.name = None
     except (TypeError):
         pass
     else:
         self.fail()
Exemplo n.º 13
0
 def test_weight_should_not_accept_negative_value(self):
     sport = Sport()
     try:
         sport.weight = -1
     except(ValueError):
         pass
     else:
         self.fail()
Exemplo n.º 14
0
 def test_color_should_not_accept_none(self):
     sport = Sport()
     try:
         sport.color = None
     except(ValueError):
         pass
     else:
         self.fail()
Exemplo n.º 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()
Exemplo n.º 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()
Exemplo n.º 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()
Exemplo n.º 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])
Exemplo n.º 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()
Exemplo n.º 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()
Exemplo n.º 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()
Exemplo n.º 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"])
Exemplo n.º 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])
Exemplo n.º 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")
Exemplo n.º 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"])
Exemplo n.º 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")
Exemplo n.º 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()
Exemplo n.º 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()
Exemplo n.º 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()
Exemplo n.º 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()
Exemplo n.º 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
Exemplo n.º 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
Exemplo n.º 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)
Exemplo n.º 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()
Exemplo n.º 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")
Exemplo n.º 36
0
 def test_id_should_accept_integer(self):
     sport = Sport()
     sport.id = 1
     self.assertEquals(1, sport.id)
Exemplo n.º 37
0
 def test_id_should_accept_integer_string(self):
     sport = Sport()
     sport.id = "1"
     self.assertEquals(1, sport.id)
Exemplo n.º 38
0
 def test_met_should_accept_none(self):
     sport = Sport()
     sport.met = None
     self.assertEquals(None, sport.met)
Exemplo n.º 39
0
 def test_met_should_accept_float_string(self):
     sport = Sport()
     sport.met = "22.5"
     self.assertEquals(22.5, sport.met)
Exemplo n.º 40
0
 def test_name_should_accept_unicode_string(self):
     sport = Sport()
     sport.name = u"Unicycling"
     self.assertEquals(u"Unicycling", sport.name)
Exemplo n.º 41
0
 def test_max_pace_should_accept_integer_string(self):
     sport = Sport()
     sport.max_pace = "220"
     self.assertEquals(220, sport.max_pace)
Exemplo n.º 42
0
 def test_max_pace_should_accept_none(self):
     sport = Sport()
     sport.max_pace = None
     self.assertEquals(None, sport.max_pace)
Exemplo n.º 43
0
 def test_met_should_default_to_None(self):
     sport = Sport()
     self.assertEquals(None, sport.met)
Exemplo n.º 44
0
 def test_met_should_accept_float(self):
     sport = Sport()
     sport.met = 22.5
     self.assertEquals(22.5, sport.met)
Exemplo n.º 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)
Exemplo n.º 46
0
 def test_met_should_accept_float_string(self):
     sport = Sport()
     sport.met = "22.5"
     self.assertEquals(22.5, sport.met)
Exemplo n.º 47
0
 def test_id_should_default_to_none(self):
     sport = Sport()
     self.assertEquals(None, sport.id)
Exemplo n.º 48
0
 def test_max_pace_should_accept_none(self):
     sport = Sport()
     sport.max_pace = None
     self.assertEquals(None, sport.max_pace)
Exemplo n.º 49
0
 def test_name_should_accept_unicode_string(self):
     sport = Sport()
     sport.name = u"Unicycling"
     self.assertEquals(u"Unicycling", sport.name)
Exemplo n.º 50
0
 def test_max_pace_should_accept_integer(self):
     sport = Sport()
     sport.max_pace = 220
     self.assertEquals(220, sport.max_pace)
Exemplo n.º 51
0
 def test_color_should_default_to_blue(self):
     sport = Sport()
     self.assertEquals(0x0000ff, sport.color.rgb_val)
Exemplo n.º 52
0
 def test_name_should_default_to_empty_string(self):
     sport = Sport()
     self.assertEquals(u"", sport.name)
Exemplo n.º 53
0
 def test_met_should_accept_float(self):
     sport = Sport()
     sport.met = 22.5
     self.assertEquals(22.5, sport.met)
Exemplo n.º 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")
Exemplo n.º 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)
Exemplo n.º 56
0
 def test_id_should_accept_integer_string(self):
     sport = Sport()
     sport.id = "1"
     self.assertEquals(1, sport.id)
Exemplo n.º 57
0
 def test_id_should_accept_integer(self):
     sport = Sport()
     sport.id = 1
     self.assertEquals(1, sport.id)
Exemplo n.º 58
0
 def test_weight_should_accept_float(self):
     sport = Sport()
     sport.weight = 22.5
     self.assertEquals(22.5, sport.weight)