
import unittest
import requests

from nap.api import Api


class TestNap(unittest.TestCase):

    def test_unallowed_method(self):
        """Tries to use non-existent HTTP method"""
        api = Api('')

        # lambda trickery is necessary, because otherwise it would raise
        # AttributeError uncontrolled
        self.assertRaises(AttributeError, lambda: api.resource.nonexisting)

    def test_requests_raises_error(self):
        """Test that requests properly raises its own errors

        >>> requests.get('/kk')
        requests.exceptions.MissingSchema: Invalid URL u'/kk':
        No schema supplied. Perhaps you meant http:///kk?
        """
        api = Api('')
        self.assertRaises(requests.exceptions.MissingSchema, api.resource.get)

    def test_resource_not_callable(self):
        """Make sure resource can't be called directly"""
        api = Api('')
        self.assertRaises(TypeError, api.resource)


from mock import MagicMock, patch
import unittest
import requests

from nap.api import Api


class TestNap(unittest.TestCase):

    def test_unallowed_method(self):
        """Tries to use non-existent HTTP method"""
        api = Api('')

        # lambda trickery is necessary, because otherwise it would raise
        # AttributeError uncontrolled
        self.assertRaises(AttributeError, lambda: api.resource.nonexisting)

    def test_requests_raises_error(self):
        """Test that requests properly raises its own errors

        >>> requests.get('/kk')
        requests.exceptions.MissingSchema: Invalid URL u'/kk':
        No schema supplied. Perhaps you meant http:///kk?
        """
        api = Api('')
        self.assertRaises(requests.exceptions.MissingSchema, api.resource.get)

    def test_resource_not_callable(self):
        """Make sure resource can't be called directly"""
        api = Api('')
        self.assertRaises(TypeError, api.resource)

    @patch('requests.get')
    def test_default_parameters(self, requests_get):
        """Test default parameter behavior"""
        api = Api('', auth=('user', 'password'))
        requests.get = MagicMock(return_value=None)

        # Make sure defaults are passed for each request
        api.resource.get()
        requests.get.assert_called_with('/resource', auth=('user', 'password'))

        # Make sure single calls can override defaults
        api.resource.get(auth=('defaults', 'overriden'))
        requests.get.assert_called_with(
            '/resource',
            auth=('defaults', 'overriden')
        )

Add tests which test default parameters for nap api
Add tests which test default parameters for nap api

  
+ from mock import MagicMock, patch
  import unittest
  import requests
  
  from nap.api import Api
  
  
  class TestNap(unittest.TestCase):
  
      def test_unallowed_method(self):
          """Tries to use non-existent HTTP method"""
          api = Api('')
  
          # lambda trickery is necessary, because otherwise it would raise
          # AttributeError uncontrolled
          self.assertRaises(AttributeError, lambda: api.resource.nonexisting)
  
      def test_requests_raises_error(self):
          """Test that requests properly raises its own errors
  
          >>> requests.get('/kk')
          requests.exceptions.MissingSchema: Invalid URL u'/kk':
          No schema supplied. Perhaps you meant http:///kk?
          """
          api = Api('')
          self.assertRaises(requests.exceptions.MissingSchema, api.resource.get)
  
      def test_resource_not_callable(self):
          """Make sure resource can't be called directly"""
          api = Api('')
          self.assertRaises(TypeError, api.resource)
  
+     @patch('requests.get')
+     def test_default_parameters(self, requests_get):
+         """Test default parameter behavior"""
+         api = Api('', auth=('user', 'password'))
+         requests.get = MagicMock(return_value=None)
+ 
+         # Make sure defaults are passed for each request
+         api.resource.get()
+         requests.get.assert_called_with('/resource', auth=('user', 'password'))
+ 
+         # Make sure single calls can override defaults
+         api.resource.get(auth=('defaults', 'overriden'))
+         requests.get.assert_called_with(
+             '/resource',
+             auth=('defaults', 'overriden')
+         )
+ 
Add tests which test default parameters for nap api
## Code Before:

import unittest
import requests

from nap.api import Api


class TestNap(unittest.TestCase):

    def test_unallowed_method(self):
        """Tries to use non-existent HTTP method"""
        api = Api('')

        # lambda trickery is necessary, because otherwise it would raise
        # AttributeError uncontrolled
        self.assertRaises(AttributeError, lambda: api.resource.nonexisting)

    def test_requests_raises_error(self):
        """Test that requests properly raises its own errors

        >>> requests.get('/kk')
        requests.exceptions.MissingSchema: Invalid URL u'/kk':
        No schema supplied. Perhaps you meant http:///kk?
        """
        api = Api('')
        self.assertRaises(requests.exceptions.MissingSchema, api.resource.get)

    def test_resource_not_callable(self):
        """Make sure resource can't be called directly"""
        api = Api('')
        self.assertRaises(TypeError, api.resource)

## Instruction:
Add tests which test default parameters for nap api
## Code After:

from mock import MagicMock, patch
import unittest
import requests

from nap.api import Api


class TestNap(unittest.TestCase):

    def test_unallowed_method(self):
        """Tries to use non-existent HTTP method"""
        api = Api('')

        # lambda trickery is necessary, because otherwise it would raise
        # AttributeError uncontrolled
        self.assertRaises(AttributeError, lambda: api.resource.nonexisting)

    def test_requests_raises_error(self):
        """Test that requests properly raises its own errors

        >>> requests.get('/kk')
        requests.exceptions.MissingSchema: Invalid URL u'/kk':
        No schema supplied. Perhaps you meant http:///kk?
        """
        api = Api('')
        self.assertRaises(requests.exceptions.MissingSchema, api.resource.get)

    def test_resource_not_callable(self):
        """Make sure resource can't be called directly"""
        api = Api('')
        self.assertRaises(TypeError, api.resource)

    @patch('requests.get')
    def test_default_parameters(self, requests_get):
        """Test default parameter behavior"""
        api = Api('', auth=('user', 'password'))
        requests.get = MagicMock(return_value=None)

        # Make sure defaults are passed for each request
        api.resource.get()
        requests.get.assert_called_with('/resource', auth=('user', 'password'))

        # Make sure single calls can override defaults
        api.resource.get(auth=('defaults', 'overriden'))
        requests.get.assert_called_with(
            '/resource',
            auth=('defaults', 'overriden')
        )
