def test_api_token(self):
        """Test if the api token is set in the request"""

        setup_genderize_server()

        genderize('John', api_token='abcdefghi')

        expected = {'name': ['John'], 'apikey': ['abcdefghi']}

        req = httpretty.last_request()
        self.assertEqual(req.method, 'GET')
        self.assertEqual(req.querystring, expected)
    def test_api_token(self):
        """Test if the api token is set in the request"""

        setup_genderize_server()

        genderize('John', api_token='abcdefghi')

        expected = {
            'name': ['John'],
            'apikey': ['abcdefghi']
        }

        req = httpretty.last_request()
        self.assertEqual(req.method, 'GET')
        self.assertEqual(req.querystring, expected)
    def test_name_not_found(self):
        """Test if a null response is returned when the name is not found"""

        setup_genderize_server()

        gender, acc = genderize('Jack')
        self.assertEqual(gender, None)
        self.assertEqual(acc, None)

        expected = {'name': ['Jack']}

        req = httpretty.last_request()
        self.assertEqual(req.method, 'GET')
        self.assertEqual(req.querystring, expected)
    def test_genderize(self):
        """Test if the gender of a name is obtained"""

        setup_genderize_server()

        gender, acc = genderize('John')
        self.assertEqual(gender, 'male')
        self.assertEqual(acc, 99)

        expected = {'name': ['John']}

        req = httpretty.last_request()
        self.assertEqual(req.method, 'GET')
        self.assertEqual(req.querystring, expected)
    def test_name_not_found(self):
        """Test if a null response is returned when the name is not found"""

        setup_genderize_server()

        gender, acc = genderize('Jack')
        self.assertEqual(gender, None)
        self.assertEqual(acc, None)

        expected = {
            'name': ['Jack']
        }

        req = httpretty.last_request()
        self.assertEqual(req.method, 'GET')
        self.assertEqual(req.querystring, expected)
    def test_genderize(self):
        """Test if the gender of a name is obtained"""

        setup_genderize_server()

        gender, acc = genderize('John')
        self.assertEqual(gender, 'male')
        self.assertEqual(acc, 99)

        expected = {
            'name': ['John']
        }

        req = httpretty.last_request()
        self.assertEqual(req.method, 'GET')
        self.assertEqual(req.querystring, expected)
    def test_retry(self):
        """Test if the request is retried when an error is returned"""

        http_requests = setup_genderize_server()

        with self.assertRaises(requests.exceptions.RetryError):
            _, _ = genderize('error')

        expected = {'name': ['error']}

        self.assertEqual(len(http_requests), 6)

        for i in range(5):
            req = http_requests[i]
            self.assertEqual(req.method, 'GET')
            self.assertEqual(req.querystring, expected)
    def test_retry(self):
        """Test if the request is retried when an error is returned"""

        http_requests = setup_genderize_server()

        with self.assertRaises(requests.exceptions.RetryError):
            _, _ = genderize('error')

        expected = {
            'name': ['error']
        }

        self.assertEqual(len(http_requests), 6)

        for i in range(5):
            req = http_requests[i]
            self.assertEqual(req.method, 'GET')
            self.assertEqual(req.querystring, expected)