Example #1
0
 def test_should_enable_pagination_with_no_args(self):
     input_tokens = ['foo', 'bar']
     self.parsed_globals.paginate = True
     # Corresponds to not specifying --foo nor --bar
     self.parsed_args.foo = None
     self.parsed_args.bar = None
     paginate.check_should_enable_pagination(
         input_tokens, self.parsed_args, self.parsed_globals)
     # We should have turned paginate off because the
     # user specified --bar 10
     self.assertTrue(self.parsed_globals.paginate)
Example #2
0
 def test_should_enable_pagination_with_no_args(self):
     input_tokens = ['foo', 'bar']
     self.parsed_globals.paginate = True
     # Corresponds to not specifying --foo nor --bar
     self.parsed_args.foo = None
     self.parsed_args.bar = None
     paginate.check_should_enable_pagination(input_tokens, self.parsed_args,
                                             self.parsed_globals)
     # We should have turned paginate off because the
     # user specified --bar 10
     self.assertTrue(self.parsed_globals.paginate)
Example #3
0
 def test_should_not_enable_pagination(self):
     # Here the user has specified a manual pagination argument,
     # so we should turn pagination off.
     # From setUp(), the limit_key is 'Bar'
     input_tokens = ['foo', 'bar']
     self.parsed_globals.paginate = True
     # Corresponds to --bar 10
     self.parsed_args.foo = None
     self.parsed_args.bar = 10
     paginate.check_should_enable_pagination(
         input_tokens, self.parsed_args, self.parsed_globals)
     # We should have turned paginate off because the
     # user specified --bar 10
     self.assertFalse(self.parsed_globals.paginate)
Example #4
0
 def test_should_not_enable_pagination(self):
     # Here the user has specified a manual pagination argument,
     # so we should turn pagination off.
     # From setUp(), the limit_key is 'Bar'
     input_tokens = ['foo', 'bar']
     self.parsed_globals.paginate = True
     # Corresponds to --bar 10
     self.parsed_args.foo = None
     self.parsed_args.bar = 10
     paginate.check_should_enable_pagination(input_tokens, self.parsed_args,
                                             self.parsed_globals)
     # We should have turned paginate off because the
     # user specified --bar 10
     self.assertFalse(self.parsed_globals.paginate)
Example #5
0
    def test_fall_back_to_original_max_items_when_pagination_turned_off(self):
        input_tokens = ['max-items']
        # User specifies --no-paginate.
        self.parsed_globals.paginate = False
        # But also specifies --max-items 10, which is normally a pagination arg
        # we replace.  However, because they've explicitly turned off
        # pagination, we should put back the original arg.
        self.parsed_args.max_items = 10
        shadowed_args = {'max-items': mock.sentinel.ORIGINAL_ARG}
        arg_table = {'max-items': mock.sentinel.PAGINATION_ARG}

        paginate.check_should_enable_pagination(input_tokens, shadowed_args,
                                                arg_table, self.parsed_args,
                                                self.parsed_globals)
Example #6
0
    def test_fall_back_to_original_max_items_when_pagination_turned_off(self):
        input_tokens = ['max-items']
        # User specifies --no-paginate.
        self.parsed_globals.paginate = False
        # But also specifies --max-items 10, which is normally a pagination arg
        # we replace.  However, because they've explicitly turned off
        # pagination, we should put back the original arg.
        self.parsed_args.max_items = 10
        shadowed_args = {'max-items': mock.sentinel.ORIGINAL_ARG}
        arg_table = {'max-items': mock.sentinel.PAGINATION_ARG}

        paginate.check_should_enable_pagination(
            input_tokens, shadowed_args, arg_table,
            self.parsed_args, self.parsed_globals)
Example #7
0
 def test_shadowed_args_are_replaced_when_pagination_set_off(self):
     input_tokens = ['foo', 'bar']
     self.parsed_globals.paginate = False
     # Corresponds to --bar 10
     self.parsed_args.foo = None
     self.parsed_args.bar = 10
     shadowed_args = {'foo': mock.sentinel.ORIGINAL_ARG}
     arg_table = {'foo': mock.sentinel.PAGINATION_ARG}
     paginate.check_should_enable_pagination(input_tokens, shadowed_args,
                                             arg_table, self.parsed_args,
                                             self.parsed_globals)
     # We should have turned paginate off because the
     # user specified --bar 10
     self.assertFalse(self.parsed_globals.paginate)
     self.assertEqual(arg_table['foo'], mock.sentinel.ORIGINAL_ARG)
Example #8
0
 def test_default_to_pagination_on_when_ambiguous(self):
     input_tokens = ['foo', 'max-items']
     self.parsed_globals.paginate = True
     # Here the user specifies --max-items 10 This is ambiguous because the
     # input_token also contains 'max-items'.  Should we assume they want
     # pagination turned off or should we assume that this is the normalized
     # --max-items?
     # Will we default to assuming they meant the normalized
     # --max-items.
     self.parsed_args.foo = None
     self.parsed_args.max_items = 10
     paginate.check_should_enable_pagination(
         input_tokens, self.parsed_args, self.parsed_globals)
     self.assertTrue(self.parsed_globals.paginate,
                     "Pagination was not enabled.")
Example #9
0
 def test_shadowed_args_are_replaced_when_pagination_set_off(self):
     input_tokens = ['foo', 'bar']
     self.parsed_globals.paginate = False
     # Corresponds to --bar 10
     self.parsed_args.foo = None
     self.parsed_args.bar = 10
     shadowed_args = {'foo': mock.sentinel.ORIGINAL_ARG}
     arg_table = {'foo': mock.sentinel.PAGINATION_ARG}
     paginate.check_should_enable_pagination(
         input_tokens, shadowed_args, arg_table,
         self.parsed_args, self.parsed_globals)
     # We should have turned paginate off because the
     # user specified --bar 10
     self.assertFalse(self.parsed_globals.paginate)
     self.assertEqual(arg_table['foo'], mock.sentinel.ORIGINAL_ARG)
Example #10
0
 def test_default_to_pagination_on_when_ambiguous(self):
     input_tokens = ['foo', 'max-items']
     self.parsed_globals.paginate = True
     # Here the user specifies --max-items 10 This is ambiguous because the
     # input_token also contains 'max-items'.  Should we assume they want
     # pagination turned off or should we assume that this is the normalized
     # --max-items?
     # Will we default to assuming they meant the normalized
     # --max-items.
     self.parsed_args.foo = None
     self.parsed_args.max_items = 10
     paginate.check_should_enable_pagination(input_tokens, self.parsed_args,
                                             self.parsed_globals)
     self.assertTrue(self.parsed_globals.paginate,
                     "Pagination was not enabled.")