Example #1
0
 def test_enterText_Should_DoNothing_When_UserCancelsOperation(self):
     # Setup
     xbmc.Keyboard.stubConfirmed = False
     control = Mock()
     validator = Mock()
     updater = Mock()
     
     # Test
     enterText(control=control, validator=validator.validate, updater=updater.update)
     
     # Verify
     verifyZeroInteractions(validator)
     verifyZeroInteractions(updater)
Example #2
0
 def test_enterText_Should_NotUpdateControlAndModel_When_UserEnteredTextFailsValidation(self):
     # Setup
     xbmc.Keyboard.stubConfirmed = True
     xbmc.Keyboard.stubText = 'Bubba'
     control = Mock()
     updater = Mock()
     validator = Mock()
     when(validator).validate(any()).thenRaise(Exception('Invalid name'))        
     
     # Test
     enterText(control=control, validator=validator.validate, updater=updater.update)
     
     # Verify
     verifyZeroInteractions(updater)
     verify(control, 0).setLabel(any(str), any(str))
Example #3
0
    def test_enterText_Should_DoNothing_When_UserCancelsOperation(self):
        # Setup
        xbmc.Keyboard.stubConfirmed = False
        control = Mock()
        validator = Mock()
        updater = Mock()

        # Test
        enterText(control=control,
                  validator=validator.validate,
                  updater=updater.update)

        # Verify
        verifyZeroInteractions(validator)
        verifyZeroInteractions(updater)
Example #4
0
    def readInput(self):
        ok = False
        if self.type == str:
            ok, value = enterText(control=self.widget,
                                  validator=self.validator)
        elif self.type in (
                int,
                Seconds,
        ):
            ok, value = enterNumeric(control=self.widget,
                                     validator=self.validator,
                                     current=self.store.get(self.key))
        elif self.type == NegativeSeconds:
            ok, value = enterNumeric(control=self.widget,
                                     validator=self.validator,
                                     current=str(
                                         int(self.store.get(self.key)) * -1))
            if value != '0':
                value = '-' + value
        elif self.type == bool and type(
                self.widget) == xbmcgui.ControlRadioButton:
            ok, value = True, ['False', 'True'][self.widget.isSelected()]
        else:
            log.warn('readinput() not activated for type %s and widget %s' %
                     (self.type, type(self.widget)))

        if ok:
            self.store.put(self.key, value)
            self.render(
            )  # re-render since enterNumeric(...) doesn't handle special cases like Seconds
Example #5
0
 def test_enterText_Should_UpdateModelAndControl_When_UserInputIsValid(self):
     # Setup
     xbmc.Keyboard.stubConfirmed = True
     xbmc.Keyboard.stubText = "Bubba"
     
     control = Mock()
     when(control).getLabel().thenReturn('Name')
     validator = Mock()
     updater = Mock()
     
     # Test
     enterText(control=control, validator=validator.validate, updater=updater.update)
     
     # Verify
     verify(validator, 1).validate('Bubba')
     # TODO: type(xbmc.ControlButton) fails for Mock
     #verify(control, 1).setLabel(any(str), any(str)) 
     verify(updater, 1).update('Bubba')
Example #6
0
    def test_enterText_Should_NotUpdateControlAndModel_When_UserEnteredTextFailsValidation(
            self):
        # Setup
        xbmc.Keyboard.stubConfirmed = True
        xbmc.Keyboard.stubText = 'Bubba'
        control = Mock()
        updater = Mock()
        validator = Mock()
        when(validator).validate(any()).thenRaise(Exception('Invalid name'))

        # Test
        enterText(control=control,
                  validator=validator.validate,
                  updater=updater.update)

        # Verify
        verifyZeroInteractions(updater)
        verify(control, 0).setLabel(any(str), any(str))
Example #7
0
    def test_enterText_Should_UpdateModelAndControl_When_UserInputIsValid(
            self):
        # Setup
        xbmc.Keyboard.stubConfirmed = True
        xbmc.Keyboard.stubText = "Bubba"

        control = Mock()
        when(control).getLabel().thenReturn('Name')
        validator = Mock()
        updater = Mock()

        # Test
        enterText(control=control,
                  validator=validator.validate,
                  updater=updater.update)

        # Verify
        verify(validator, 1).validate('Bubba')
        # TODO: type(xbmc.ControlButton) fails for Mock
        #verify(control, 1).setLabel(any(str), any(str))
        verify(updater, 1).update('Bubba')
Example #8
0
    def readInput(self):
        ok = False
        if self.type == str:
            ok, value = enterText(control=self.widget, validator=self.validator)
        elif self.type in (int, Seconds,):
            ok, value = enterNumeric(control=self.widget, validator=self.validator, current=self.store.get(self.key))
        elif self.type == NegativeSeconds:
            ok, value = enterNumeric(control=self.widget, validator=self.validator, current= str(int(self.store.get(self.key)) * -1))
            if value != '0':
                value = '-' + value
        elif self.type == bool and type(self.widget) == xbmcgui.ControlRadioButton:
            ok, value = True, ['False', 'True'][self.widget.isSelected()]
        else:
            log.warn('readinput() not activated for type %s and widget %s' % (self.type, type(self.widget)))

        if ok:
            self.store.put(self.key, value)
            self.render() # re-render since enterNumeric(...) doesn't handle special cases like Seconds