예제 #1
0
    def test_delete_list(self):
        """
        Invoke the delete list stub

        :return:
        """
        # Data
        test_list_id = TodoListDBHandler.new_todo_list_entry('TestList')

        # When
        delete_list(test_list_id, self.grpc_secured_channel)

        # Then
        db_entries = TodoListDBHandler.get_lists_paginated()
        self.assertEqual(len(db_entries), 0)
예제 #2
0
    def test_get_list(self):
        """
        Invoke the get list stub

        :return:
        """
        # Data
        test_list_id = TodoListDBHandler.new_todo_list_entry('TestList')

        # When
        response = get_list(test_list_id, self.grpc_secured_channel)

        # Then
        db_entries = TodoListDBHandler.get_lists_paginated()
        self.assertEqual(response.id, db_entries[0].id)
        self.assertEqual(response.name, db_entries[0].name)
예제 #3
0
    def test_get_lists_paginated_2(self):
        """
        Invoke the get lists paginated stub

        :return:
        """
        # Data
        [TodoListDBHandler.new_todo_list_entry(str(i)) for i in range(5)]  # pylint: disable=expression-not-assigned

        # When
        response = get_lists_paginated(3, 2, self.grpc_secured_channel)

        # Then
        db_entries = TodoListDBHandler.get_lists_paginated()
        self.assertEqual(response.next_page_number, '')
        self.assertEqual(len(response.todo_lists), 1)
        self.assertEqual(response.todo_lists[0].id, db_entries[4].id)
        self.assertEqual(response.todo_lists[0].id, db_entries[4].id)
예제 #4
0
    def test_create_list_fail_unique_name(self, print_mock: MagicMock):
        """
        Invoke create list stub should fail when list with that name already exist in the database

        :param print_mock: Mock to inspect print calls
        :return:
        """
        # Data
        test_list_name = 'TestList'
        TodoListDBHandler.new_todo_list_entry(test_list_name)

        # When
        create_list(test_list_name, self.grpc_secured_channel)

        # Then
        db_entries = TodoListDBHandler.get_lists_paginated()
        self.assertEqual(len(db_entries), 1,
                         'Error DB should have only 1 entry')
        self.assertIn('List name must be unique', print_mock.getvalue())
예제 #5
0
    def test_stub_delete_list_script(self, input_mock: MagicMock,
                                     print_mock: MagicMock):
        """
        Invoke the delete lists stub script

        :param input_mock: Mock to input function
        :param print_mock: Mock to inspect print calls
        :return:
        """
        # Data
        test_list_id = TodoListDBHandler.new_todo_list_entry('TestList')
        input_mock.return_value = str(test_list_id)

        # When
        main_stub_delete_list()

        # Then
        db_entries = TodoListDBHandler.get_lists_paginated()
        self.assertIn('id "{}" deleted'.format(test_list_id),
                      print_mock.getvalue())
        self.assertEqual(len(db_entries), 0)
예제 #6
0
    def test_stub_get_lists_paginated_script(self, input_mock: MagicMock,
                                             print_mock: MagicMock):
        """
        Invoke the get lists paginated stub script

        :param input_mock: Mock to input function
        :param print_mock: Mock to inspect print calls
        :return:
        """
        # Data
        input_mock.return_value = '2'
        [TodoListDBHandler.new_todo_list_entry(str(i)) for i in range(5)]  # pylint: disable=expression-not-assigned

        # When
        main_stub_get_lists_paginated()

        # Then
        db_entries = TodoListDBHandler.get_lists_paginated()
        self.assertIn('next_page_number=3', print_mock.getvalue())
        self.assertIn('count=5', print_mock.getvalue())
        self.assertIn('id: {}'.format(db_entries[2].id), print_mock.getvalue())
        self.assertIn('id: {}'.format(db_entries[3].id), print_mock.getvalue())
예제 #7
0
    def test_create_list_fail_server_unavailable(self, print_mock: MagicMock):
        """
        Invoke stub should fail when the server is UNAVAILABLE.

        :param print_mock: Mock to inspect print calls
        :return:
        """
        # Data
        test_list_name = 'TestList'
        self.grpc_server.stop(None)

        # When
        create_list(test_list_name, self.grpc_secured_channel)

        # Then
        db_entries = TodoListDBHandler.get_lists_paginated()
        self.assertEqual(len(db_entries), 0, 'Error DB should have 0 entries')
        self.assertIn('failed to connect to all addresses',
                      print_mock.getvalue())
예제 #8
0
    def test_create_lists(self):
        """
        Invoke the create list stub and validate that the list is stored in the database

        :return:
        """
        # Data
        new_list_name = 'TestList'

        # When
        response = create_list(new_list_name, self.grpc_secured_channel)

        # Then
        db_entries = TodoListDBHandler.get_lists_paginated()
        self.assertEqual(len(db_entries), 1,
                         'Error DB should have only 1 entry')
        self.assertEqual(response.id, db_entries[0].id)
        self.assertEqual(response.name, new_list_name)
        self.assertEqual(response.name, db_entries[0].name)
예제 #9
0
    def test_stub_create_list_script(self, input_mock: MagicMock,
                                     print_mock: MagicMock):
        """
        Invoke the create lists stub script

        :param input_mock: Mock to input function
        :param print_mock: Mock to inspect print calls
        :return:
        """
        # Data
        new_list_name = 'TestList'
        input_mock.return_value = new_list_name

        # When
        main_stub_create_list()

        # Then
        db_entries = TodoListDBHandler.get_lists_paginated()
        self.assertIn(
            'id "{}" and name "{}"'.format(db_entries[0].id,
                                           db_entries[0].name),
            print_mock.getvalue())