Exemple #1
0
    def test_get_with_proxy(self):
        # ZAP or other proxy on port 8080 must be started before
        requester = Requester(
            host='http://docs.python-requests.org/en/master/user/advanced/',
            referer=self.default_referer,
            accept=self.accept,
            force_ssl=True,
            proxies={'http': 'localhost:8080', 'https': 'localhost:8080'}
        )

        response = requester.open_request()

        self.assertEqual(response.status_code, 200)
Exemple #2
0
    def test_post_json(self):
        requester = Requester(
            host=self.url_json,
            referer=self.default_referer,
            accept=self.accept,
            force_ssl=True)

        # requester.update_headers({'Content-Type': self.content_type_json})

        # Submit form with json field
        post_fields = {
            'result': self.submit_content
        }
        response = requester.open_request(
            post_fields=post_fields
        )
        result = requester.read_response(response=response)

        self.assertEqual(result, self.submit_content)
Exemple #3
0
    def test_steps_sequence(self):
        requester = Requester(
            host=self.url_form,
            referer=self.default_referer,
            accept=self.accept,
            force_ssl=True)

        requester.update_headers({'Content-Type': self.content_type_www})

        # Get page and cookie
        response = requester.open_request()

        self.assertEqual(response.status_code, 200)

        # Submit form with cookie
        post_fields = {
            'text_field': self.submit_content,
            'submit': 'Submit'
        }
        response = requester.open_request(
            post_fields=post_fields
        )
        result = requester.read_response(response=response)

        self.assertEqual(result, self.submit_content)
Exemple #4
0
#
# This script uses the php form located into current directory. The php form
# must be able to execute by the web server. And the web address must be
# configured according to the php form destination.
#

from __future__ import absolute_import
from __future__ import print_function
from requester.Requester import Requester

EXPECTED_RESULT = 'OK'

print('Submitting php form...')

requester = Requester(host='https://localhost/test/scrap-utils/form.php',
                      referer='http://leadtech.com',
                      accept='text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',
                      force_ssl=True)

post_fields = {
    'text_field': EXPECTED_RESULT,
    'submit': 'Submit'
}

response = requester.open_request(post_fields=post_fields)

result = requester.read_response(response=response)

if result != EXPECTED_RESULT:
    print('ERROR: Result is not as expected.')
    exit(1)