def test_not_allowed(self):
        """Test that when a Resource class does not allow certain operations, proper Exceptions are raised."""
        hotel = Hotel()
        hotel.allow_create = False
        hotel.allow_delete = False
        hotel.allow_update = False

        self.assertRaises(ResourceMethodNotAllowed, hotel.create)
        self.assertRaises(ResourceMethodNotAllowed, hotel.delete)
        self.assertRaises(ResourceMethodNotAllowed, hotel.update)
class AbstractBaseResourceTestCase(TestCase):
    """
    A Test case for the Abstract Base Resource
    """

    def setUp(self):
        self.client = APIClient()
        self.hotel = Hotel()

    def tearDown(self):
        pass

    def test_not_implemented(self):
        """Test that when a Resource class has not implemented methods, the right exceptions are raised."""
        self.assertRaises(NotImplementedError, self.hotel.create)
        self.assertRaises(NotImplementedError, self.hotel.delete)
        self.assertRaises(NotImplementedError, self.hotel.update)

    def test_not_allowed(self):
        """Test that when a Resource class does not allow certain operations, proper Exceptions are raised."""
        hotel = Hotel()
        hotel.allow_create = False
        hotel.allow_delete = False
        hotel.allow_update = False

        self.assertRaises(ResourceMethodNotAllowed, hotel.create)
        self.assertRaises(ResourceMethodNotAllowed, hotel.delete)
        self.assertRaises(ResourceMethodNotAllowed, hotel.update)

    def test_construct_resource_request_url(self):
        url = self.hotel.construct_resource_request_url("list")
        response = self.client.request(url)
        self.assertEqual(response.status, 200)
Example #3
0
class HotelResourceTestCase(TestCase):
    """
    A Test case for the Hotel Resource.
    """

    def setUp(self):
        self.client = APIClient()
        self.hotel = Hotel()

    def tearDown(self):
        pass

    def test_manual_specified_client(self):
        """Test hotel Resource object creation with a manually specified APIClient instance"""
        hotel_with_specified_client = Hotel(manual_client=self.client)
        self.assertEqual(
            hotel_with_specified_client.client, self.client, "Client passed and the created client are not equal."
        )

    def test_manual_specified_client_kwargs(self):
        """Test creation of the Hotel resource with manually specified settings through kwargs"""

        manual_client_args = {
            "protocol": "https",
            "api_version": "3",
            "domain": "api.ean.com",
            "shared_secret": "e4t4bth2anoaj",
            "api_key": "6lrf8qinl5jpuh6a9iagmmiaop",
        }

        hotel_with_specified_client_kwargs = Hotel(client_args=manual_client_args)
        self.assertIsInstance(
            hotel_with_specified_client_kwargs.client, APIClient, "Hotel client is not an instance of APICLient."
        )

    def test_get_single(self):
        """Test getting a single hotel"""
        response = self.hotel.get(148505, "09/04/2016", "09/05/2016", (1,))
        self.assertEqual(response.status, 200, "Response was not OK (200)")
        print(response.data)

    def test_list(self):
        """Test getting a list of hotels"""
        response = self.hotel.list("Seattle", "WA", "US", "09/04/2016", "09/05/2016", (1,))
        self.assertEqual(response.status, 200, "Response was not OK (200)")
Example #4
0
 def setUp(self):
     self.client = APIClient()
     self.hotel = Hotel()