Example #1
0
    def test_should_detect_too_many_actual_invocations(self):
        self.tester.clear()
        self.tester.clear()

        verify(self.tester, times(2)).had_called_with(call.clear())
        with raises(TooManyActualInvocations):
            verify(self.tester, times(1)).had_called_with(call.clear())
Example #2
0
    def test_inherited_fillable_elements(self):
        class Section2(Element, Filling):
            s2_el1 = Input(XPath('s2_el1'))
            s2_el2 = Input(XPath('s2_el2'))

        class Section1(Element, Filling):
            locator = XPath('section1')
            section2 = Section2(XPath('section2'))
            s1_el1 = Input(XPath('s1_el1'))

        class Page(object):
            section1 = Section1()

        # basic test
        section1 = Page().section1()
        assert isinstance(section1, Section1)
        assert section1.web_element is self.web_element

        dict_to_fill = {
            's1_el1': 's1_el1_value',
            'section2': {
                's2_el1': 's2_el1_value',
                's2_el2': 's2_el2_value',
            }
        }
        section1.fill(dict_to_fill)

        # section1 must be found with driver
        self.driver.find_element.assert_has_calls([call('xpath', 'section1')])

        # section2 and items of section1 must be found with web element of section1
        self.web_element.find_element.assert_has_calls([
            call('xpath', 's1_el1'),
            call('xpath', 'section2')
        ], any_order=True)

        self.web_element_inh.assert_has_calls([
            call.clear(),
            call.send_keys('s1_el1_value'),
        ])

        # items of section2 must be found with web element of section2
        self.web_element_inh.find_element.assert_has_calls([
            call('xpath', 's2_el1'),
            call('xpath', 's2_el2'),
        ], any_order=True)

        self.web_element_inh_2.assert_has_calls([
            call.clear(),
            call.send_keys('s2_el1_value'),
            call.clear(),
            call.send_keys('s2_el2_value')
        ], any_order=True)
Example #3
0
    def test_should_detect_when_invoked_more_than_once(self):
        self.tester.add("foo")
        self.tester.clear()
        self.tester.clear()

        verify(self.tester).had_called_with(call.add("foo"))
        with raises(TooManyActualInvocations):
            verify(self.tester).had_called_with(call.clear())
Example #4
0
    def test_should_fail_verification_on_method_argument(self):
        self.tester.clear()
        self.tester.add("foo")

        verify(self.tester).had_called_with(call.clear())

        with raises(WantedButNotInvoked):
            verify(self.tester).had_called_with(call.add("bar"))
Example #5
0
    def test_should_verify(self):
        self.tester.clear()
        verify(self.tester).had_called_with(call.clear())

        self.tester.add("test")
        verify(self.tester).had_called_with(call.add("test"))

        verify_no_more_interactions(self.tester)
Example #6
0
    def test_should_allow_verifying_interaction_never_happened(self):
        self.tester.add('one')

        verify(self.tester, never()).had_called_with(call.add('two'))
        verify(self.tester, never()).had_called_with(call.clear())

        with raises(NeverWantedButInvoked):
            verify(self.tester, never()).had_called_with(call.add('one'))
 def test_wait(self):
     """
     Does the decorator call the right methods?
     """
     self.cow.return_value = 'boy'
     output = self.dummy('pie')
     self.cow.assert_called_with('pie')
     self.assertEqual('boy', output)
     calls = [call.wait(self.sleep), call.clear(), call.start()]
     self.assertEqual(calls, self.timer.mock_calls)
     return
 def test_start(self):
     """
     Does it clear the event then start the timer?
     """
     self.timer.start()
     # first call - create the event and set
     # second call - clear the call so users will block
     # third call - start the timer
     calls = [call.set(), call.clear(), call.start()]
     self.assertEqual(calls, self.timer.event.mock_calls + self.timer.timer.mock_calls)
     return
Example #9
0
    def test_stop_propagation(self):
        class Section2(Element, Filling):
            locator = XPath('section2')
            s2_el1 = Input(XPath('s2_el1'))
            s2_el2 = Input(XPath('s2_el2'))

        class Section1(Element, Filling):
            locator = XPath('section1')
            stop_propagation = True
            section2 = Section2()
            s1_el1 = Input(XPath('s1_el1'))

        class Page:
            section1 = Section1()

        section1 = Page().section1()
        assert isinstance(section1, Section1)

        dict_to_fill = {
            's1_el1': 's1_el1_value',
            'section2': {
                's2_el1': 's2_el1_value',
                's2_el2': 's2_el2_value',
            }
        }

        section1.fill(dict_to_fill)

        self.driver.find_element.assert_has_calls([call('xpath', 'section1')])

        self.web_element.find_element.assert_has_calls([
            call('xpath', 's1_el1'),
        ])

        self.web_element_inh.assert_has_calls([
            call.clear(),
            call.send_keys('s1_el1_value')
        ])

        self.web_element_inh.find_element.assert_not_called()

        self.web_element_inh.get_attribute.return_value = 's1_el1_value'
        self.web_element_inh_2.get_attribute.side_effect = ['s2_el1_value', 's2_el2_value']

        state = section1.get_state()

        result_dict = {'s1_el1': 's1_el1_value'}
        eq_(result_dict, state)
Example #10
0
 def test_should_detect_actual_invocations_count_is_more_than_zero(self):
     verify(self.tester, times(0)).had_called_with(call.clear())
     with raises(WantedButNotInvoked):
         verify(self.tester, times(15)).had_called_with(call.clear())
Example #11
0
 def test_should_fail_verification(self):
     with raises(WantedButNotInvoked):
         verify(self.tester).had_called_with(call.clear())
Example #12
0
 def test_should_pass_when_methods_actually_not_called(self):
     verify(self.tester, times(0)).had_called_with(call.clear())
     verify(self.tester, times(0)).had_called_with(call.add("yes, I wasn't called"))
Example #13
0
 def test_should_detect_actually_called_once(self):
     self.tester.clear()
     with raises(NeverWantedButInvoked):
         verify(self.tester, times(0)).had_called_with(call.clear())