def test_greater_or_equals(self): self.assertTrue(EventTypeIdentifier(1, 2) >= EventTypeIdentifier(1, 2)) self.assertTrue(EventTypeIdentifier(2, 2) >= EventTypeIdentifier(1, 7)) self.assertTrue(EventTypeIdentifier(1, 1) >= EventTypeIdentifier(1, 1)) self.assertFalse( EventTypeIdentifier(1, 1) >= EventTypeIdentifier(1, 2)) self.assertFalse( EventTypeIdentifier(1, 1) >= EventTypeIdentifier(2, 1))
def test_less_or_equals(self): self.assertTrue(EventTypeIdentifier(1, 2) <= EventTypeIdentifier(1, 2)) self.assertTrue(EventTypeIdentifier(1, 6) <= EventTypeIdentifier(1, 7)) self.assertTrue(EventTypeIdentifier(1, 7) <= EventTypeIdentifier(2, 1)) self.assertFalse( EventTypeIdentifier(1, 1) <= EventTypeIdentifier(1, 0)) self.assertFalse( EventTypeIdentifier(3, 1) <= EventTypeIdentifier(2, 7))
def test_remove_event_type(self): event = Event(1940000001) event_type = EventType(EventTypeIdentifier(1, 5), "Test") self.event_service.remove_event_type(event, event_type) self.event_type_dao.unlink_event_type_from_event_id.assert_called_once_with( 1940000001, event_type)
def test_add_event_type(self): event = Event(1940000001) event_type = EventType(EventTypeIdentifier(1, 5), "Test") self.event_service.add_event_type(event, event_type) self.event_type_dao.join_event_type_to_event_id.assert_called_once_with( 1940000001, event_type)
def test_add_event_type(self, event, number_of_references): message = Message(CONF_EVENT_CHANGED, event=event) self.message_broker.send_message(message) self.view.new_event_type = self.event_type_dao.get_by_id( EventTypeIdentifier(3, 2)) self.presenter.add_event_type_reference() self.assertEqual(number_of_references, len(self.event_service.get_event_types(event)))
def test_get_event_types(self): event = Event(1940000001) event_type = EventType(EventTypeIdentifier(5, 1), "Test") self.event_type_dao.get_event_types_for_event_id.return_value = [ event_type ] result = self.event_service.get_event_types(event) self.assertEqual(1, len(result)) self.assertEqual(event_type, result[0]) self.event_type_dao.get_event_types_for_event_id.assert_called_once_with( 1940000001)
def test_remove_event_type(self): event = self.event_service.get_by_id(1940000001) event_type = self.event_type_dao.get_by_id(EventTypeIdentifier(5, 2)) message = Message(CONF_EVENT_CHANGED, event=event) self.message_broker.send_message(message) self.view.selected_item = event_type self.assertEqual(2, len(self.event_service.get_event_types(event))) self.presenter.remove_event_type_reference() self.assertEqual(1, len(self.event_service.get_event_types(event)))
def get_event_type_tree(self): event_types = ( EventType(EventTypeIdentifier(0, 0), "root"), EventType(EventTypeIdentifier(1, 0), "parent1"), EventType(EventTypeIdentifier(1, 1), "child11"), EventType(EventTypeIdentifier(1, 2), "child12"), EventType(EventTypeIdentifier(2, 0), "parent2"), EventType(EventTypeIdentifier(2, 1), "child21"), EventType(EventTypeIdentifier(2, 2), "child22"), ) return Tree(event_types)
def test_get_event_type_tree(self): self.event_type_dao.find_all.return_value = [ EventType(EventTypeIdentifier(1, 0), "one_zero"), EventType(EventTypeIdentifier(1, 1), "one_one"), EventType(EventTypeIdentifier(2, 0), "two_zero"), EventType(EventTypeIdentifier(2, 1), "two_one") ] tree = self.event_service.get_event_type_tree() self.assertFalse(tree is None) self.assertFalse(tree.root_node is None) self.assertEqual(2, len(tree.root_node.children)) self.assertEqual("one_zero", tree.root_node.children[0].entity.description) self.assertEqual("two_zero", tree.root_node.children[1].entity.description) self.assertEqual(1, len(tree.root_node.children[0].children)) self.assertEqual(1, len(tree.root_node.children[1].children)) self.assertEqual( "one_one", tree.root_node.children[0].children[0].entity.description) self.assertEqual( "two_one", tree.root_node.children[1].children[0].entity.description)
def test_add_event_type_2(self): ''' Trying to readd already added type ''' event = self.event_service.get_by_id(1940000001) event_type = self.event_type_dao.get_by_id(EventTypeIdentifier(5, 2)) message = Message(CONF_EVENT_CHANGED, event=event) self.message_broker.send_message(message) self.view.new_event_type = event_type self.assertEqual(2, len(self.event_service.get_event_types(event))) self.presenter.add_event_type_reference() self.assertEqual(2, len(self.event_service.get_event_types(event)))
def check_event_type_reference_new(self): print("Checking create new event type reference...", end='') reference = self.event_window.references[1] dialog = reference.event_type_selection_dialog self.event_window_presenter.goto_first() self.assertEquals(len(reference.items), 2) self.start_dialog(reference._get_new_event_type) dialog.presenter.set_tree() dialog.tree_widget.set(EventTypeIdentifier(3, 2)) dialog.presenter.ok_action() self.wait() self.assertEquals(len(reference.items), 3) print("OK")
def check_event_type_reference_delete(self): print("Checking deleting event type reference...", end='') reference = self.event_window.references[1] dialog = reference.deletion_dialog self.event_window_presenter.goto_first() self.assertEquals(len(reference.items), 3) items = reference.listbox.get_items() identifier = EventTypeIdentifier(3, 2) for item in items: if item.id == identifier: reference.listbox.set(item) self.start_dialog(reference._remove_event_type_reference) dialog.presenter.yes_action() self.assertEquals(len(reference.items), 2) print("OK")
def test_join_event_type_to_event_id_again(self): event_type = self.dao.get_by_id(EventTypeIdentifier(1, 2)) self.dao.join_event_type_to_event_id(1940000001, event_type) liste = self.dao.get_event_types_for_event_id(1940000001) self.assertEqual(2, len(liste))
def test_not_equals(self): event_type1 = EventType(EventTypeIdentifier(1, 2), "Test") event_type2 = EventType(EventTypeIdentifier(1, 3), "Test") self.assertNotEqual(event_type1, event_type2)
def test_fetching_tree(self): tree = self.dao.get_event_type_tree() self.assertEqual(tree.root_node.id, EventTypeIdentifier(0, 0)) self.assertEqual(14, len(tree.root_node.children)) self.assertEqual(8, len(tree.root_node.children[0].children))
def test_unlink_event_type_from_event_id(self): event_type = self.dao.get_by_id(EventTypeIdentifier(1, 2)) self.dao.unlink_event_type_from_event_id(1940000001, event_type) liste = self.dao.get_event_types_for_event_id(1940000001) self.assertEqual(1, len(liste))
def test_string_representation(self): event_type = EventType(EventTypeIdentifier(1, 2), "My event type") self.assertEqual("My event type", "%s" % event_type)
def test_equals_with_none(self): self.assertFalse(EventTypeIdentifier(1, 2) == None)
def test_greater_or_equal_than_2(self): event_type1 = EventType(EventTypeIdentifier(1, 7), "Test") event_type2 = EventType(EventTypeIdentifier(1, 7), "Test2") self.assertTrue(event_type2 >= event_type1)
def test_less_or_equal_than_1(self): event_type1 = EventType(EventTypeIdentifier(1, 7), "Test") event_type2 = EventType(EventTypeIdentifier(2, 1), "Test2") self.assertTrue(event_type1 <= event_type2)
def test_greater_than_1(self): event_type1 = EventType(EventTypeIdentifier(1, 2), "Test") event_type2 = EventType(EventTypeIdentifier(1, 3), "Test2") self.assertTrue(event_type2 > event_type1)
def test_less_than_1(self): event_type1 = EventType(EventTypeIdentifier(1, 2), "Test") event_type2 = EventType(EventTypeIdentifier(1, 3), "Test2") self.assertTrue(event_type1 < event_type2)
def test_compare_to_none(self): event_type1 = EventType(EventTypeIdentifier(1, 2), "Test") self.assertNotEqual(event_type1, None)