def test_commit(self): #Arrange op = Operator() op.first_name = "monty" op.family_name = "python" op.date_of_birth = date(1990, 9, 30) op.drone_license = 2 op.rescue_endorsement = True op.operations = 5 opStore = OperatorStore() action = opStore.add(op) #Act if action.is_valid(): action.commit() else: for i in action.messages: print(i) #Assert listy = [] for i in opStore.list_all(): listy.append(opStore.get(i)) self.assertIn(op, listy)
def add_operator(self): """ Starts a new operator and displays it in the list. """ # Start a new operator instance print('FINISH: Start a new operator') operator = Operator() operator.first_name = "" operator.family_name = "" operator.drone_license = 1 operator.rescue_endorsement = 1 operator.operations = 0 # Display the operator self.view_operator(operator, self._save_new_operator)
def test_operatorStore_added_successfully(self): #Arrange op = Operator() op.first_name = "Afzal" op.family_name = "Rahim" dob = date(1974, 9, 12) op.date_of_birth = dob op.drone_license = 2 op.rescue_endorsement = True op.operations = 6 store = OperatorStore() #Act act = store.add(op) if act.is_valid(): act.commit() #Assert #self.assertTrue(store.get(op.id), True, "Operator has not been added successfully") self.assertTrue(store.get(op.id))
def test_operator_validation(self): #Arrange op = Operator() op.first_name = "Afzal" op.family_name = "Rahim" dob = date(1974, 9, 12) op.date_of_birth = dob op.drone_license = 2 op.rescue_endorsement = True op.operations = 6 store = OperatorStore() #Act act = store.add(op) #Assert if act.is_valid(): act.commit() #print(act.messages) #print(store._operators) self.assertTrue(act.is_valid())
def test_dobError(self): #Arrange op = Operator() op.first_name = "Afzal" op.family_name = "Rahim" #dob = date(1974, 9, 12) #op.date_of_birth = dob op.drone_license = 2 op.rescue_endorsement = True op.operations = 6 store = OperatorStore() #action = OperatorAction(op, store._add(op)) #Act act = store.add(op) #Assert if act.is_valid(): act.commit() else: #self.assertIn('Date of birth is required', act.messages) self.assertEqual('Date of birth is required' in act.messages, False, 'Date of birth is required.')
def test_rescueEndorsement_validity(self): #Arrange op = Operator() op.first_name = "Afzal" op.family_name = "Rahim" dob = date(1974, 9, 12) op.date_of_birth = dob op.drone_license = 2 op.rescue_endorsement = True op.operations = 2 store = OperatorStore() #action = OperatorAction(op, store._add(op)) #Act act = store.add(op) #Assert if act.is_valid(): act.commit() else: #self.assertIn('The operator must have been involved in five prior rescue operations.', act.messages) self.assertEqual('The operator must have been involved in five prior rescue operations' in act.messages, False, 'The operator must have been involved in five prior rescue operations.')
def test_droneLicence_validity(self): #Arrange op = Operator() op.first_name = "Afzal" op.family_name = "Rahim" dob = date(2017, 9, 12) op.date_of_birth = dob op.drone_license = 2 op.rescue_endorsement = True op.operations = 6 store = OperatorStore() #action = OperatorAction(op, store._add(op)) #Act act = store.add(op) #Assert if act.is_valid(): act.commit() else: #self.assertIn('Operator should be at least twenty to hold a class 2 license', act.messages) self.assertEqual('Operator should be at least twenty to hold a class 2 license' in act.messages, False, 'Operator should be at least twenty to hold a class 2 license')