Пример #1
0
class TestForms(unittest.TestCase):

    @mock_forms
    def setUp(self):
        self.browser = RoboBrowser()
        self.browser.open('http://robobrowser.com/get/')

    @mock_forms
    def test_get_forms(self):
        forms = self.browser.get_forms()
        assert_equal(len(forms), 2)

    @mock_forms
    def test_get_form_by_id(self):
        form = self.browser.get_form('bass')
        assert_equal(form.parsed.get('id'), 'bass')

    @mock_forms
    def test_submit_form(self):
        form = self.browser.get_form()
        self.browser.submit_form(form)
        assert_equal(
            self.browser.url,
            'http://robobrowser.com/post/?deacon=john'
        )
Пример #2
0
class TestHistoryInternals(unittest.TestCase):

    def setUp(self):
        self.browser = RoboBrowser(history=True)

    @mock_urls
    def test_open_appends_to_history(self):
        assert_equal(len(self.browser._states), 0)
        assert_equal(self.browser._cursor, -1)
        self.browser.open('http://robobrowser.com/page1/')
        assert_equal(len(self.browser._states), 1)
        assert_equal(self.browser._cursor, 0)

    @mock_forms
    def test_submit_appends_to_history(self):
        self.browser.open('http://robobrowser.com/get_form/')
        form = self.browser.get_form()
        self.browser.submit_form(form)

        assert_equal(len(self.browser._states), 2)
        assert_equal(self.browser._cursor, 1)

    @mock_urls
    def test_open_clears_history_after_back(self):
        self.browser.open('http://robobrowser.com/page1/')
        self.browser.open('http://robobrowser.com/page2/')
        self.browser.back()
        self.browser.open('http://robobrowser.com/page3/')
        assert_equal(len(self.browser._states), 2)
        assert_equal(self.browser._cursor, 1)

    @mock_urls
    def test_state_deque_max_length(self):
        browser = RoboBrowser(history=5)
        for _ in range(5):
            browser.open('http://robobrowser.com/page1/')
        assert_equal(len(browser._states), 5)
        browser.open('http://robobrowser.com/page2/')
        assert_equal(len(browser._states), 5)

    @mock_urls
    def test_state_deque_no_history(self):
        browser = RoboBrowser(history=False)
        for _ in range(5):
            browser.open('http://robobrowser.com/page1/')
            assert_equal(len(browser._states), 1)
            assert_equal(browser._cursor, 0)
Пример #3
0
class TestForms(unittest.TestCase):

    def setUp(self):
        self.browser = RoboBrowser()

    @mock_forms
    def test_get_forms(self):
        self.browser.open('http://robobrowser.com/get_form/')
        forms = self.browser.get_forms()
        assert_equal(len(forms), 2)

    @mock_forms
    def test_get_form_by_id(self):
        self.browser.open('http://robobrowser.com/get_form/')
        form = self.browser.get_form('bass')
        assert_equal(form.parsed.get('id'), 'bass')

    @mock_forms
    def test_submit_form_get(self):
        self.browser.open('http://robobrowser.com/get_form/')
        form = self.browser.get_form()
        self.browser.submit_form(form)
        assert_equal(
            self.browser.url,
            'http://robobrowser.com/get_form/?deacon=john'
        )
        assert_true(self.browser.state.response.request.body is None)

    @mock_forms
    def test_submit_form_post(self):
        self.browser.open('http://robobrowser.com/post_form/')
        form = self.browser.get_form()
        self.browser.submit_form(form)
        assert_equal(
            self.browser.url,
            'http://robobrowser.com/submit/'
        )
        assert_equal(
            self.browser.state.response.request.body,
            'deacon=john'
        )