def setUp(self):
     """
     This method is called before each tests
     """
     self.call_handler = CallHandler()
     self.emp = Respondent(self.call_handler, 'respondent')
     self.call_instance = Call(self.call_handler)
     self.call_instance_two = Call(self.call_handler)
     self.call_instance_three = Call(self.call_handler)
     self.call_handler.call_queue = [
         self.call_instance, self.call_instance_two,
         self.call_instance_three
     ]
Exemplo n.º 2
0
def add_respondent():
    if not request.json:
        abort(400)
    print(request)
    respondent_type = request.json["respondent_type"]
    if respondent_type == 'respondent':
        Respondent(call_handler, 'respondent')
    elif respondent_type == 'manager':
        Respondent(call_handler, 'manager')
    else:
        Respondent(call_handler, 'director')
    return json.dumps({'success': True}), 200, {
        'ContentType': 'application/json'
    }
class CallHandlerTests(unittest.TestCase):
    def setUp(self):
        """
        This method is called before each tests
        """
        self.call_handler = CallHandler()
        self.respondent = Respondent(self.call_handler, 'respondent')
        self.respondent_b = Respondent(self.call_handler, 'respondent')
        self.manager = Respondent(self.call_handler, 'manager')
        self.director = Respondent(self.call_handler, 'director')

        self.call_instance = Call(self.call_handler)
        self.call_instance_two = Call(self.call_handler)
        self.call_instance_three = Call(self.call_handler)

    def tearDown(self):
        """
        This method is called after each tests
        """
        pass

    def test_locate_handler_rank_all_respondents_available(self):
        self.assertEqual(
            self.call_handler.locate_handler_for_call(0),
            self.respondent,
            msg='Not being directed towards available respondent rank 0')
        self.assertEqual(
            self.call_handler.locate_handler_for_call(1),
            self.manager,
            msg='Not being directed towards available respondent rank 1')
        self.assertEqual(
            self.call_handler.locate_handler_for_call(2),
            self.director,
            msg='Not being directed towards available respondent rank 2')
        return True

    def test_call_and_respondent_assignment(self):
        self.respondent.assign_new_call(self.call_instance)
        self.assertEqual(
            self.call_instance.respondent_handler,
            self.respondent,
            msg='Call is not being correctly associated with a user')
        return True

    def test_locate_handler_rank_respondents_busy(self):
        self.respondent.assign_new_call(self.call_instance)
        self.assertEqual(
            self.call_handler.locate_handler_for_call(0),
            self.respondent_b,
            msg='Not being directed towards available next respondent rank 0')
        self.respondent_b.assign_new_call(self.call_instance_two)
        self.assertFalse(self.call_instance_three.assign_to_free_respondent(),
                         msg='Should not have been passed an respondent')
        self.assertEqual(
            self.call_handler.request_call_from_queue(0),
            self.call_instance_three,
            msg='Not being passed the first available call from the queue')
        return True
    def setUp(self):
        """
        This method is called before each tests
        """
        self.call_handler = CallHandler()
        self.respondent = Respondent(self.call_handler, 'respondent')
        self.respondent_b = Respondent(self.call_handler, 'respondent')
        self.manager = Respondent(self.call_handler, 'manager')
        self.director = Respondent(self.call_handler, 'director')

        self.call_instance = Call(self.call_handler)
        self.call_instance_two = Call(self.call_handler)
        self.call_instance_three = Call(self.call_handler)
Exemplo n.º 5
0
class RespondentTests(unittest.TestCase):
    def setUp(self):
        self.mock_call_handler = mock.create_autospec(CallHandler)
        self.mock_call = mock.create_autospec(Call)
        self.respondent = Respondent(self.mock_call_handler, 'respondent')

    def tearDown(self):
        """
        This method is called after each tests
        """
        pass

    def test_set_respondent_type_verify_rank(self):
        self.respondent.set_respondent_type('respondent')
        self.assertEqual(self.respondent.rank, 0,
                         'Base Respondent should have rank 0')
        self.respondent.set_respondent_type('manager')
        self.assertEqual(self.respondent.rank, 1, 'Manager should have rank 1')
        self.respondent.set_respondent_type('director')
        self.assertEqual(self.respondent.rank, 2,
                         'Director should have rank 2')
        return True

    def test_set_respondent_type_verify_type_validity(self):
        """ If an invalid respondent type is passed to set_respondent_type should raise error """
        self.assertRaises(ValueError,
                          lambda: self.respondent.set_respondent_type('bogus'))
        return True

    def test_recieve_call_when_free(self):
        self.assertTrue(self.respondent.recieve_call(self.mock_call))
        return True

    def test_recieve_call_when_not_free(self):
        self.respondent.recieve_call(self.mock_call)
        self.assertRaises(Exception,
                          lambda: self.respondent.recieve_call(self.mock_call))
        return True

    def test_complete_call_when_not_free_side_effect(self):
        self.respondent.is_free = mock.Mock(return_value=True)
        with self.assertRaises(NameError) as cm:
            self.respondent.complete_call()
        return True

    def test_complete_call_when_not_free(self):
        self.respondent.recieve_call(self.mock_call)
        self.assertTrue(self.respondent.complete_call())
        return True

    def test_complete_call_when_free(self):
        self.assertRaises(NameError, lambda: self.respondent.complete_call())
        return True

    def test_escalate_and_reassign(self):
        self.respondent.recieve_call(self.mock_call)
        self.mock_call_handler.request_call_from_queue.return_value = self.mock_call
        self.assertTrue(self.respondent.escalate_and_reassign())
        self.assertEqual(self.respondent.call, self.mock_call)
        self.mock_call.increase_rank.assert_called_with()
        self.mock_call.assign_to_free_respondent.assert_called_with()
        return True

    def test_assign_new_call(self):
        self.mock_call_handler.request_call_from_queue.return_value = self.mock_call
        self.respondent.assign_new_call()
        self.mock_call_handler.request_call_from_queue.assert_called_with(
            self.respondent.rank)
        self.mock_call.set_respondent_handler.assert_called_with(
            self.respondent)
        return True

    def test_is_free(self):
        self.assertTrue(self.respondent.is_free())
        self.respondent.assign_new_call(self.mock_call)
        self.assertFalse(self.respondent.is_free())
        return True
Exemplo n.º 6
0
 def setUp(self):
     self.mock_call_handler = mock.create_autospec(CallHandler)
     self.mock_call = mock.create_autospec(Call)
     self.respondent = Respondent(self.mock_call_handler, 'respondent')
class RespondentTests(unittest.TestCase):
    """This is a first attempt at integration tests. Should be refactored,mocking is a better approach"""
    def setUp(self):
        """
        This method is called before each tests
        """
        self.call_handler = CallHandler()
        self.emp = Respondent(self.call_handler, 'respondent')
        self.call_instance = Call(self.call_handler)
        self.call_instance_two = Call(self.call_handler)
        self.call_instance_three = Call(self.call_handler)
        self.call_handler.call_queue = [
            self.call_instance, self.call_instance_two,
            self.call_instance_three
        ]

    def tearDown(self):
        """
        This method is called after each tests
        """
        pass

    def test_complete_call(self):
        self.assertTrue(self.emp.is_free(),
                        msg='respondent should be free before proceeding')
        self.emp.recieve_call(self.call_instance)
        self.emp.complete_call()
        self.assertTrue(self.emp.is_free(),
                        msg='respondent does not appear to be free')
        return True

    def test_complete_call_when_call_is_undefined(self):
        """ shouldnt be able to complete a call that doesnt exist """
        self.assertRaises(NameError, lambda: self.emp.complete_call())
        return True

    def test_escalate_and_reassign_when_call_is_not_undefined(self):
        """ verify escalate_and_reassign. existing call should be escalated to higher level, new call should be reassigned """
        self.emp.recieve_call(self.call_instance)
        self.call_instance_two.assign_to_free_respondent()
        self.assertTrue(self.emp.escalate_and_reassign())
        self.assertTrue(self.call_instance.in_queue_or_being_helped(),
                        msg='existing call not in queue or being helped')
        self.assertEqual(self.call_instance.rank,
                         1,
                         msg='existing call not being escalated')
        self.assertFalse(self.emp.is_free(),
                         msg='respondent should be assigned to new call')
        return True

    def test_escalate_and_reassign_when_call_is_undefined(self):
        """ shouldnt be able to escalate_and_reassign when not in call """
        self.assertRaises(NameError, lambda: self.emp.escalate_and_reassign())
        return True

    def test_assign_new_call_when_call_is_not_undefined(self):
        """ shouldnt be able to assign new call when in current call """
        self.emp.recieve_call(self.call_instance)
        self.assertRaises(NameError,
                          lambda: self.emp.assign_new_call(self.call_instance))
        return True