Esempio n. 1
0
 def test_get_item_id(self):
     equipment = Equipment()
     equipment.id = 1
     self.mock_equipment_service.get_all_equipment.return_value = [equipment]
     equipment_store = EquipmentStore(self.mock_equipment_service)
     iter = equipment_store.get_iter_first()
     self.assertEquals(1, equipment_store.get_value(iter, 0))
Esempio n. 2
0
 def test_get_item_description(self):
     equipment = Equipment()
     equipment.id = 1
     equipment.description = u"item description"
     self.mock_equipment_service.get_all_equipment.return_value = [equipment]
     equipment_store = EquipmentStore(self.mock_equipment_service)
     iter = equipment_store.get_iter_first()
     self.assertEquals("item description", equipment_store.get_value(iter, 1))
Esempio n. 3
0
 def test_active_set_to_non_boolean(self):
     equipment = Equipment()
     try:
         equipment.active = "test"
     except (TypeError):
         pass
     else:
         self.fail("Should not be able to set active to non-boolean value.")
Esempio n. 4
0
 def test_get_item_active(self):
     equipment = Equipment()
     equipment.id = 1
     equipment.active = False
     self.mock_equipment_service.get_all_equipment.return_value = [equipment]
     equipment_store = EquipmentStore(self.mock_equipment_service)
     iter = equipment_store.get_iter_first()
     self.assertFalse(equipment_store.get_value(iter, 4))
Esempio n. 5
0
 def test_notes_set_to_non_string(self):
     equipment = Equipment()
     try:
         equipment.notes = 42
     except(TypeError):
         pass
     else:
         self.fail("Should not be able to set notes to non-string value.")
Esempio n. 6
0
 def test_prior_usage_set_to_non_numeric_string(self):
     equipment = Equipment()
     try:
         equipment.prior_usage = "test"
     except(ValueError):
         pass
     else:
         self.fail("Should not be able to set life expectancy to non numeric value.")
Esempio n. 7
0
 def test_notes_set_to_non_string(self):
     equipment = Equipment()
     try:
         equipment.notes = 42
     except (TypeError):
         pass
     else:
         self.fail("Should not be able to set notes to non-string value.")
Esempio n. 8
0
 def test_description_set_to_non_string(self):
     equipment = Equipment()
     try:
         equipment.description = 42
     except(TypeError):
         pass
     else:
         self.fail("Should not be able to set description to non string value.")
Esempio n. 9
0
 def test_active_set_to_non_boolean(self):
     equipment = Equipment()
     try:
         equipment.active = "test"
     except(TypeError):
         pass
     else:
         self.fail("Should not be able to set active to non-boolean value.")
Esempio n. 10
0
 def test_id_set_to_non_numeric_string(self):
     equipment = Equipment()
     try:
         equipment.id = "test"
     except(ValueError):
         pass
     else:
         self.fail("Should not be able to set equipment id to non numeric value.")
Esempio n. 11
0
 def test_get_item_usage_text(self):
     equipment = Equipment()
     equipment.id = 1
     equipment.life_expectancy = 200
     self.mock_equipment_service.get_all_equipment.return_value = [equipment]
     self.mock_equipment_service.get_equipment_usage.return_value = 100
     equipment_store = EquipmentStore(self.mock_equipment_service)
     iter = equipment_store.get_iter_first()
     self.assertEquals("100 / 200", equipment_store.get_value(iter, 3))
Esempio n. 12
0
 def test_store_equipment_duplicate_description(self):
     self.mock_ddbb.select.return_value = [(1,)]
     equipment = Equipment()
     equipment.description = u"test item"
     try:
         self.equipment_service.store_equipment(equipment)
         self.fail("Should not be able to store new item with non-unique description.")
     except(EquipmentServiceException):
         pass
Esempio n. 13
0
 def test_description_set_to_non_string(self):
     equipment = Equipment()
     try:
         equipment.description = 42
     except (TypeError):
         pass
     else:
         self.fail(
             "Should not be able to set description to non string value.")
Esempio n. 14
0
 def test_update_equipment_non_existant(self):
     self.mock_ddbb.select.return_value = []
     equipment = Equipment()
     equipment.id = 1
     try:
         self.equipment_service.store_equipment(equipment)
         self.fail("Should not be able to update an item which did not previously exist.")
     except(EquipmentServiceException):
         pass
Esempio n. 15
0
 def test_id_set_to_non_numeric_string(self):
     equipment = Equipment()
     try:
         equipment.id = "test"
     except (ValueError):
         pass
     else:
         self.fail(
             "Should not be able to set equipment id to non numeric value.")
Esempio n. 16
0
 def test_get_item_usage_percent_zero_usage(self):
     equipment = Equipment()
     equipment.id = 1
     equipment.life_expectancy = 200
     self.mock_equipment_service.get_all_equipment.return_value = [equipment]
     self.mock_equipment_service.get_equipment_usage.return_value = 0
     equipment_store = EquipmentStore(self.mock_equipment_service)
     iter = equipment_store.get_iter_first()
     self.assertEquals(0, equipment_store.get_value(iter, 2))
Esempio n. 17
0
 def test_get_item_usage_percent_usage_exceeds_life_expectancy(self):
     equipment = Equipment()
     equipment.id = 1
     equipment.life_expectancy = 200
     self.mock_equipment_service.get_all_equipment.return_value = [equipment]
     self.mock_equipment_service.get_equipment_usage.return_value = 300
     equipment_store = EquipmentStore(self.mock_equipment_service)
     iter = equipment_store.get_iter_first()
     self.assertEquals(100, equipment_store.get_value(iter, 2), "Progress bar cannot exceed 100%.")
Esempio n. 18
0
 def test_update_equipment_duplicate_description(self):
     self.mock_ddbb.select.return_value = [(1, u"test item", True, 500, 200, u"Test notes.")]
     equipment = Equipment()
     equipment.id = 2
     equipment.description = u"test item"
     try:
         self.equipment_service.store_equipment(equipment)
         self.fail("Should not be able to change item description to non-unique value.")
     except(EquipmentServiceException):
         pass
Esempio n. 19
0
 def test_prior_usage_set_to_non_numeric_string(self):
     equipment = Equipment()
     try:
         equipment.prior_usage = "test"
     except (ValueError):
         pass
     else:
         self.fail(
             "Should not be able to set life expectancy to non numeric value."
         )
Esempio n. 20
0
 def test_update_equipment(self):
     equipment = Equipment()
     equipment.id = 1
     equipment.description = u"new description"
     self.mock_ddbb.select.return_value =  [(1, u"old description", 1, 0, 0,u"")]
     self.equipment_service.store_equipment(equipment)
     self.mock_ddbb.update.assert_called_with("equipment", 
                                              "description,active,life_expectancy,prior_usage,notes", 
                                              ["new description", 1, 0, 0,"" ], 
                                              "id = 1")
Esempio n. 21
0
 def test_update_equipment_non_existant(self):
     self.mock_ddbb.select.return_value = []
     equipment = Equipment()
     equipment.id = 1
     try:
         self.equipment_service.store_equipment(equipment)
         self.fail(
             "Should not be able to update an item which did not previously exist."
         )
     except (EquipmentServiceException):
         pass
Esempio n. 22
0
 def test_store_equipment_duplicate_description(self):
     self.mock_ddbb.select.return_value = [(1, )]
     equipment = Equipment()
     equipment.description = u"test item"
     try:
         self.equipment_service.store_equipment(equipment)
         self.fail(
             "Should not be able to store new item with non-unique description."
         )
     except (EquipmentServiceException):
         pass
Esempio n. 23
0
 def test_update_equipment(self):
     equipment = Equipment()
     equipment.id = 1
     equipment.description = u"new description"
     self.mock_ddbb.select.return_value = [(1, u"old description", 1, 0, 0,
                                            u"")]
     self.equipment_service.store_equipment(equipment)
     self.mock_ddbb.update.assert_called_with(
         "equipment",
         "description,active,life_expectancy,prior_usage,notes",
         ["new description", 1, 0, 0, ""], "id = 1")
Esempio n. 24
0
 def test_update_equipment_duplicate_description(self):
     self.mock_ddbb.select.return_value = [(1, u"test item", True, 500, 200,
                                            u"Test notes.")]
     equipment = Equipment()
     equipment.id = 2
     equipment.description = u"test item"
     try:
         self.equipment_service.store_equipment(equipment)
         self.fail(
             "Should not be able to change item description to non-unique value."
         )
     except (EquipmentServiceException):
         pass
Esempio n. 25
0
 def test_store_equipment(self):
     equipment = Equipment()
     equipment.description = u"test description"
     equipment_ids = []
     def mock_select(table, columns, where):
         if columns == "id":
             return equipment_ids
         else:
             return [(2, u"", 1, 0, 0,u"")]
     def update_equipment_ids(*args):
         equipment_ids.append([1])
     self.mock_ddbb.select = mock.Mock(wraps=mock_select)
     self.mock_ddbb.insert.side_effect = update_equipment_ids
     stored_equipment = self.equipment_service.store_equipment(equipment)
     self.mock_ddbb.insert.assert_called_with("equipment", 
                                              "description,active,life_expectancy,prior_usage,notes", 
                                              ["test description", 1, 0, 0,"" ])
     self.assertEquals(2, stored_equipment.id)
Esempio n. 26
0
 def test_equals_instances_with_same_id(self):
     equipment1 = Equipment()
     equipment1.id = 1
     equipment2 = Equipment()
     equipment2.id = 1
     self.assertEqual(equipment1, equipment2,
                      "Equipment instances with same id should be equal.")
Esempio n. 27
0
    def test_store_equipment(self):
        equipment = Equipment()
        equipment.description = u"test description"
        equipment_ids = []

        def mock_select(table, columns, where):
            if columns == "id":
                return equipment_ids
            else:
                return [(2, u"", 1, 0, 0, u"")]

        def update_equipment_ids(*args):
            equipment_ids.append([1])

        self.mock_ddbb.select = mock.Mock(wraps=mock_select)
        self.mock_ddbb.insert.side_effect = update_equipment_ids
        stored_equipment = self.equipment_service.store_equipment(equipment)
        self.mock_ddbb.insert.assert_called_with(
            "equipment",
            "description,active,life_expectancy,prior_usage,notes",
            ["test description", 1, 0, 0, ""])
        self.assertEquals(2, stored_equipment.id)
Esempio n. 28
0
 def test_equals_instances_with_different_ids(self):
     equipment1 = Equipment()
     equipment1.id = 1
     equipment2 = Equipment()
     equipment2.id = 2
     self.assertNotEqual(
         equipment1, equipment2,
         "Equipment instances with different ids should not be equal.")
Esempio n. 29
0
 def test_multiple_equipment_items(self):
     equipment1 = Equipment()
     equipment1.id = 1
     equipment2 = Equipment()
     equipment2.id = 2
     self.mock_equipment_service.get_all_equipment.return_value = [equipment1, equipment2]
     equipment_store = EquipmentStore(self.mock_equipment_service)
     iter = equipment_store.get_iter_first()
     iter = equipment_store.iter_next(iter)
     self.assertEquals(2, equipment_store.get_value(iter, 0))
Esempio n. 30
0
 def _confirm_add_equipment_clicked(self, widget):
     #FIXME input validation for numeric fields
     description = self._builder.get_object("entryEquipmentAddDescription").get_text()
     life_expectancy = self._builder.get_object("entryEquipmentAddLifeExpectancy").get_text()
     prior_usage = self._builder.get_object("entryEquipmentAddPriorUsage").get_text()
     active = self._builder.get_object("checkbuttonEquipmentAddActive").get_active()
     notes_buffer = self._builder.get_object("textviewEquipmentAddNotes").get_buffer()
     notes = notes_buffer.get_text(notes_buffer.get_start_iter(), notes_buffer.get_end_iter())
     new_equipment = Equipment()
     new_equipment.description = unicode(description)
     new_equipment.active = active
     new_equipment.life_expectancy = life_expectancy
     new_equipment.prior_usage = prior_usage
     new_equipment.notes = unicode(notes)
     self._equipment_store.add_equipment(new_equipment)
     self.show_page_equipment_list()
Esempio n. 31
0
 def test_id_set_to_numeric_string(self):
     equipment = Equipment()
     equipment.id = "3"
     self.assertEquals(3, equipment.id)
Esempio n. 32
0
 def test_get_equipment_usage_none(self):
     self.mock_ddbb.select.return_value = [(None,)]
     equipment = Equipment()
     equipment.id = 1
     usage = self.equipment_service.get_equipment_usage(equipment)
     self.assertEquals(0, usage)
Esempio n. 33
0
 def test_id_set_to_integer(self):
     equipment = Equipment()
     equipment.id = 2
     self.assertEquals(2, equipment.id)
Esempio n. 34
0
 def test_prior_usage_set_to_integer(self):
     equipment = Equipment()
     equipment.prior_usage = 2
     self.assertEquals(2, equipment.prior_usage)
Esempio n. 35
0
 def test_id_set_to_integer(self):
     equipment = Equipment()
     equipment.id = 2
     self.assertEquals(2, equipment.id)
Esempio n. 36
0
 def test_equals_new_instances(self):
     equipment1 = Equipment()
     equipment2 = Equipment()
     self.assertNotEqual(equipment1, equipment2, "")
Esempio n. 37
0
 def test_notes_set_to_unicode_string(self):
     equipment = Equipment()
     equipment.notes = u"Zapatos de €100."
     self.assertEquals(u"Zapatos de €100.", equipment.notes)
Esempio n. 38
0
 def test_equals_instances_with_different_ids(self):
     equipment1 = Equipment()
     equipment1.id = 1
     equipment2 = Equipment()
     equipment2.id = 2
     self.assertNotEqual(equipment1, equipment2, "Equipment instances with different ids should not be equal.")
Esempio n. 39
0
 def test_description_set_to_unicode_string(self):
     equipment = Equipment()
     equipment.description = u"Zapatos de €100"
     self.assertEquals(u"Zapatos de €100", equipment.description)
Esempio n. 40
0
 def test_active_set_to_boolean(self):
     equipment = Equipment()
     equipment.active = False
     self.assertFalse(equipment.active)
Esempio n. 41
0
 def test_equals_instances_with_same_id(self):
     equipment1 = Equipment()
     equipment1.id = 1
     equipment2 = Equipment()
     equipment2.id = 1
     self.assertEqual(equipment1, equipment2, "Equipment instances with same id should be equal.")
Esempio n. 42
0
 def test_notes_set_to_unicode_string(self):
     equipment = Equipment()
     equipment.notes = u"Zapatos de €100."
     self.assertEquals(u"Zapatos de €100.", equipment.notes)
Esempio n. 43
0
 def test_life_expectancy_set_to_integer(self):
     equipment = Equipment()
     equipment.life_expectancy = 2
     self.assertEquals(2, equipment.life_expectancy)
Esempio n. 44
0
 def test_prior_usage_set_to_numeric_string(self):
     equipment = Equipment()
     equipment.prior_usage = "3"
     self.assertEquals(3, equipment.prior_usage)
Esempio n. 45
0
 def test_id_defaults_to_none(self):
     equipment = Equipment()
     self.assertEqual(None, equipment.id)
Esempio n. 46
0
 def test_description_defaults_to_empty_string(self):
     equipment = Equipment()
     self.assertEquals(u"", equipment.description)
Esempio n. 47
0
 def test_description_set_to_unicode_string(self):
     equipment = Equipment()
     equipment.description = u"Zapatos de €100"
     self.assertEquals(u"Zapatos de €100", equipment.description)
Esempio n. 48
0
 def test_id_set_to_numeric_string(self):
     equipment = Equipment()
     equipment.id = "3"
     self.assertEquals(3, equipment.id)
Esempio n. 49
0
 def test_active_set_to_boolean(self):
     equipment = Equipment()
     equipment.active = False
     self.assertFalse(equipment.active)
Esempio n. 50
0
 def test_get_equipment_usage_none(self):
     self.mock_ddbb.select.return_value = [(None, )]
     equipment = Equipment()
     equipment.id = 1
     usage = self.equipment_service.get_equipment_usage(equipment)
     self.assertEquals(0, usage)
Esempio n. 51
0
 def test_active_defaults_to_true(self):
     equipment = Equipment()
     self.assertTrue(equipment.active)
Esempio n. 52
0
 def test_life_expectancy_set_to_numeric_string(self):
     equipment = Equipment()
     equipment.life_expectancy = "3"
     self.assertEquals(3, equipment.life_expectancy)