예제 #1
0
    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)
예제 #2
0
 def test_add_operator_age_wrong(self):
     #arrange
     operatorstore = OperatorStore()
     operator = Operator()
     operator.date_of_birth = date(1998, 2, 3)
     operator.drone_license = 2
     operator.operations = 6
     #act
     actual = operatorstore.add(operator)
     #assert
     self.assertIn("First name is required", actual.messages)
예제 #3
0
 def test_add_operator_drone_license(self):
     #arrange
     operatorstore = OperatorStore()
     operator = Operator()
     operator.first_name = "Cindy"
     operator.date_of_birth = date(1998, 2, 3)
     operator.operations = 6
     #act
     actual = operatorstore.add(operator)
     #assert
     self.assertIn("Drone license is required", actual.messages)
예제 #4
0
 def test_add_operator_pass_all_rules(self):
     #arrange
     operatorstore = OperatorStore()
     operator = Operator()
     operator.first_name = "Cindy"
     operator.date_of_birth = date(1998, 2, 3)
     operator.drone_license = 2
     operator.operations = 6
     #act
     actual = operatorstore.add(operator)
     #assert
     self.assertTrue(len(actual.messages) == 0)
예제 #5
0
    def test_fail_license(self):
        # Arrange
        op = Operator()
        op.first_name = "Matthew"
        op.date_of_birth = date(1995, 12, 25)
        store = OperatorStore()

        # Act
        act = store.add(op)

        # Assert
        self.assertFalse(act.is_valid())
예제 #6
0
 def test_add_operator_rescue_5(self):
     #arrange
     operatorstore = OperatorStore()
     operator = Operator()
     operator.first_name = "Cindy"
     operator.date_of_birth = date(1998, 2, 3)
     operator.drone_license = 2
     operator.operations = 2
     #act
     actual = operatorstore.add(operator)
     #assert
     self.assertIn("More than 5 rescue operations is required",
                   actual.messages)
예제 #7
0
 def test_add_operator_successfully(self):
     #arrange
     operatorstore = OperatorStore()
     operator = Operator()
     operator.first_name = "Cindy"
     operator.date_of_birth = date(1998, 2, 3)
     operator.drone_license = 2
     operator.operations = 6
     #act
     actual = operatorstore.add(operator)
     #assert
     if actual.is_valid():
         actual.commit()
     self.assertIn(operator.id, operatorstore._operators)
예제 #8
0
 def test_add_operator_age_more_than_20(self):
     #arrange
     operatorstore = OperatorStore()
     operator = Operator()
     operator.first_name = "Cindy"
     operator.date_of_birth = date(2000, 2, 3)
     operator.drone_license = 2
     operator.operations = 6
     #act
     actual = operatorstore.add(operator)
     #assert
     self.assertIn(
         "Operator should be at least twenty to hold a class 2 license",
         actual.messages)
예제 #9
0
    def test_fail_endorsement(self):
        # Arrange
        op = Operator()
        op.first_name = "Matthew"
        op.date_of_birth = date(1995, 12, 25)
        op.drone_license = 1
        op.rescue_endorsement = True
        store = OperatorStore()

        # Act
        act = store.add(op)

        # Assert
        self.assertFalse(act.is_valid())
예제 #10
0
    def test_pass_all(self):
        # Arrange
        op = Operator()
        op.first_name = "Matthew"
        op.date_of_birth = date(1995, 12, 25)
        op.drone_license = 2
        op.rescue_endorsement = True
        op.operations = 5
        store = OperatorStore()

        # Act
        act = store.add(op)

        # Assert
        self.assertTrue(act.is_valid())
예제 #11
0
 def test_add_operator_exception(self):
     #arrange
     operatorstore = OperatorStore()
     operator = Operator()
     operator.first_name = "Cindy"
     operator.date_of_birth = date(1998, 2, 3)
     operator.drone_license = 2
     operator.operations = 6
     #act
     actual = operatorstore.add(operator)
     #assert
     if actual.is_valid():
         actual.commit()
     with self.assertRaises(Exception):
         actual.commit()
예제 #12
0
    def test_add(self):
        # Arrange
        op = Operator()
        op.first_name = "Matthew"
        op.date_of_birth = date(1995, 12, 25)
        op.drone_license = 2
        op.rescue_endorsement = True
        op.operations = 5
        store = OperatorStore()

        # Act
        act = store.add(op)
        act.commit()

        # Assert
        self.assertEqual(store.get(1), op)
예제 #13
0
    def test_operatorInvalidDroneLicense(self):
        #Arrange
        op = Operator()
        op.first_name = "monty"
        op.date_of_birth = date(1990, 9, 30)
        op.rescue_endorsement = True
        op.operations = 5
        opStore = OperatorStore()

        #Act
        action = opStore.add(op)

        #Assert
        self.assertIsNone(op.drone_license)
        self.assertFalse(action.is_valid())
        self.assertIn("Drone license is required", action.messages)
예제 #14
0
 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))
예제 #15
0
    def test_operatorInvalidEndorsement(self):
        #Arrange
        op = Operator()
        op.first_name = "monty"
        op.date_of_birth = date(1990, 9, 30)
        op.drone_license = 2
        op.rescue_endorsement = True
        op.operations = 4
        opStore = OperatorStore()

        #Act
        action = opStore.add(op)

        #Assert
        if (op.rescue_endorsement):
            self.assertFalse(op.operations >= 5)
        self.assertFalse(action.is_valid())
        self.assertIn(
            "Operator should have been involved in five prior rescue operations to hold a rescue drone endorsement",
            action.messages)
예제 #16
0
 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())
예제 #17
0
    def test_operatorInvalidDL2(self):
        #Arrange
        op = Operator()
        op.first_name = "monty"
        op.rescue_endorsement = True
        op.operations = 5
        op.date_of_birth = date(2015, 9, 30)
        op.drone_license = 2
        opStore = OperatorStore()

        #Act
        action = opStore.add(op)

        #Assert
        if (op.drone_license == 2):
            self.assertFalse(
                date.today() - op.date_of_birth >= timedelta(7300))
        self.assertFalse(action.is_valid())
        self.assertIn(
            "Operator should be at least twenty to hold a class 2 license",
            action.messages)
예제 #18
0
 def test_nameError(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.assertEqual(self.assertIn('First name is required', act.messages), False, 'First name is required')
         self.assertEqual('First name is required' in act.messages, False, 'First name is required.')
예제 #19
0
 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.')
예제 #20
0
 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')
예제 #21
0
    def test_operatorValidity(self):
        #Arrange
        op = Operator()
        op.first_name = "monty"
        op.date_of_birth = date(1990, 9, 30)
        op.drone_license = 2
        op.rescue_endorsement = True
        op.operations = 5
        opStore = OperatorStore()

        #Act
        action = opStore.add(op)

        #Assert
        self.assertIsNotNone(op.first_name)
        self.assertIsNotNone(op.date_of_birth)
        self.assertIsNotNone(op.drone_license)
        if (op.drone_license == 2):
            self.assertTrue(date.today() - op.date_of_birth >= timedelta(7300))
        if (op.rescue_endorsement):
            self.assertTrue(op.operations >= 5)

        self.assertTrue(action.is_valid())