familysearch.Request

Here are the examples of the python api familysearch.Request taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.

6 Examples 7

Example 1

Project: familysearch-python-sdk-opensource Source File: test_enhanced_request.py
Function: test_head
    def test_head(self):
        expected = [
            ('Access-Control-Allow-Credentials', 'true'),
            ('Access-Control-Allow-Origin', '*'),
            ('Content-length', '294'),
            ('Content-Type', 'application/json'),
            ('Date', 'Thu, 18 Sep 2014 00:29:57 GMT'),
            ('Server', 'gunicorn/18.0'),
            ('Connection', 'Close')
        ]
        url = self.base_url + '/get'
        request = Request(url, method='HEAD')
        response = urlopen(request)
        actual = response.getheaders()
        expected_fields = [value[0] for value in expected]
        actual_fields = [value[0] for value in actual]
        self.assertTrue(actual)
        self.assertTrue(actual_fields == expected_fields)

Example 2

Project: familysearch-python-sdk-opensource Source File: test_enhanced_request.py
Function: test_delete
    def test_delete(self):
        expected = {
            'args': {},
            'form': {},
            'origin': '192.168.1.1',
            'headers': {
                'X-Request-Id': 'e4f0cb78-afc7-4617-aac1-a0c13fa746cc',
                'Accept-Encoding': 'identity',
                'User-Agent': 'Python-urllib/3.4',
                'Host': 'httpbin.org',
                'Connection': 'close'
            },
            'data': '',
            'files': {},
            'url': 'http://httpbin.org/delete',
            'json': None
        }
        url = self.base_url + '/delete'
        request = Request(url, method='DELETE')
        response = urlopen(request)
        actual = json.loads(response.read().decode('utf-8'))
        self.assertTrue(actual)
        self.assertTrue(actual.keys() == expected.keys())
        self.assertTrue(actual.get('headers', {}).keys() ==
            expected['headers'].keys())

Example 3

Project: familysearch-python-sdk-opensource Source File: test_enhanced_request.py
Function: test_get
    def test_get(self):
        expected = {
            'args': {},
            'origin': '192.168.1.1',
            'headers': {
                'X-Request-Id': 'e4f0cb78-afc7-4617-aac1-a0c13fa746cc',
                'Accept-Encoding': 'identity',
                'User-Agent': 'Python-urllib/3.4',
                'Host': 'httpbin.org',
                'Connection': 'close'
            },
            'url': 'http://httpbin.org/get',
        }
        url = self.base_url + '/get'
        request = Request(url)
        response = urlopen(request)
        actual = json.loads(response.read().decode('utf-8'))
        self.assertTrue(actual)
        self.assertTrue(actual.keys() == expected.keys())
        self.assertTrue(actual.get('headers', {}).keys() ==
            expected['headers'].keys())

Example 4

Project: familysearch-python-sdk-opensource Source File: test_enhanced_request.py
Function: test_options
    def test_options(self):
        expected = [
            ('Access-Control-Allow-Credentials', 'true'),
            ('Access-Control-Allow-Methods', 'GET, POST, PUT, DELETE, PATCH, OPTIONS'),
            ('Access-Control-Allow-Origin', '*'),
            ('Access-Control-Max-Age', '3600'),
            ('Allow', 'GET, HEAD, OPTIONS'),
            ('Content-Type', 'text/html; charset=utf-8'),
            ('Date', 'Thu, 18 Sep 2014 00:29:57 GMT'),
            ('Server', 'gunicorn/18.0'),
            ('Content-Length', '0'),
            ('Connection', 'Close')
        ]
        url = self.base_url
        request = Request(url, method='OPTIONS')
        response = urlopen(request)
        actual = response.getheaders()
        expected_fields = [value[0] for value in expected]
        actual_fields = [value[0] for value in actual]
        self.assertTrue(actual)
        self.assertTrue(actual_fields == expected_fields)

Example 5

Project: familysearch-python-sdk-opensource Source File: test_enhanced_request.py
Function: test_post
    def test_post(self):
        expected = {
            'args': {},
            'form': {'spam': '1', 'eggs': '2', 'bacon': '3'},
            'origin': '192.168.1.1',
            'headers': {
                'Content-Length': '21',
                'X-Request-Id': 'e4f0cb78-afc7-4617-aac1-a0c13fa746cc',
                'Accept-Encoding': 'identity',
                'Content-Type': 'application/x-www-form-urlencoded',
                'User-Agent': 'Python-urllib/3.4',
                'Host': 'httpbin.org',
                'Connection': 'close'
            },
            'data': '',
            'files': {},
            'url': 'http://httpbin.org/delete',
            'json': None
        }
        url = self.base_url + '/post'
        data_dict = {'spam': 1, 'eggs': 2, 'bacon': 3}
        data = urlencode(data_dict)
        data = data.encode('utf-8')
        request = Request(url, data)
        response = urlopen(request)
        actual = json.loads(response.read().decode('utf-8'))
        self.assertTrue(actual)
        self.assertTrue(actual.keys() == expected.keys())
        self.assertTrue(actual.get('headers', {}).keys() ==
            expected['headers'].keys())
        self.assertTrue(actual.get('form', None) == expected['form'])

Example 6

Project: familysearch-python-sdk-opensource Source File: test_enhanced_request.py
Function: test_put
    def test_put(self):
        expected = {
            'args': {},
            'form': {},
            'origin': '192.168.1.1',
            'headers': {
                'Content-Length': '0',
                'X-Request-Id': 'e4f0cb78-afc7-4617-aac1-a0c13fa746cc',
                'Accept-Encoding': 'identity',
                'User-Agent': 'Python-urllib/3.4',
                'Host': 'httpbin.org',
                'Connection': 'close'
            },
            'data': '',
            'files': {},
            'url': 'http://httpbin.org/delete',
            'json': None
        }
        url = self.base_url + '/put'
        request = Request(url, method='PUT')
        response = urlopen(request)
        actual = json.loads(response.read().decode('utf-8'))
        self.assertTrue(actual)
        self.assertTrue(actual.keys() == expected.keys())
        self.assertTrue(actual.get('headers', {}).keys() ==
            expected['headers'].keys())