예제 #1
0
    def test_add_flavor_exist(self, value, mock_session, mock_execute):
        self.fc.get = mock.Mock(return_value=model_flavor.Flavor(
            flavor_id=value['id']))

        # mock the response from cassandra
        mock_execute.execute.return_value = value
        new_flavor = flavor.load_from_json(value)

        self.assertRaises(ValueError, self.fc.add, new_flavor)
예제 #2
0
    def test_add_flavor_exist(self, value, mock_session, mock_execute):
        self.fc.get = mock.Mock(return_value=model_flavor.Flavor(
            flavor_id=value['id']
        ))

        # mock the response from cassandra
        mock_execute.execute.return_value = value
        new_flavor = flavor.load_from_json(value)

        self.assertRaises(ValueError, self.fc.add, new_flavor)
예제 #3
0
    def test_get_one(self, value, mock_manager):

        return_flavor = flavor.load_from_json(value)

        # mock the storage response
        mock_response = return_flavor
        mock_manager.get.return_value = mock_response

        url = u'/v1.0/flavors/{0}'.format(uri.encode(value['id']))
        response = self.app.get(url, headers={'X-Project-ID': self.project_id})

        self.assertEqual(200, response.status_code)
예제 #4
0
    def test_get_one(self, value, mock_manager):

        return_flavor = flavor.load_from_json(value)

        # mock the storage response
        mock_response = return_flavor
        mock_manager.get.return_value = mock_response

        url = u'/v1.0/flavors/{0}'.format(uri.encode(value['id']))
        response = self.app.get(url, headers={'X-Project-ID': self.project_id})

        self.assertEqual(200, response.status_code)
예제 #5
0
    def test_add_flavor(self, value, mock_session, mock_execute):
        self.fc.get = mock.Mock(side_effect=LookupError(
            "More than one flavor/no record was retrieved."))

        # mock the response from cassandra
        mock_execute.execute.return_value = value

        new_flavor = flavor.load_from_json(value)

        actual_response = self.fc.add(new_flavor)

        self.assertEqual(actual_response, None)
예제 #6
0
    def test_add_flavor(self, value, mock_session, mock_execute):
        self.fc.get = mock.Mock(side_effect=LookupError(
            "More than one flavor/no record was retrieved."
        ))

        # mock the response from cassandra
        mock_execute.execute.return_value = value

        new_flavor = flavor.load_from_json(value)

        actual_response = self.fc.add(new_flavor)

        self.assertEqual(actual_response, None)
예제 #7
0
    def post(self):
        """POST

        :returns JSON flavor(HTTP 200) or HTTP 400
        """
        flavors_controller = self.driver.manager.flavors_controller
        flavor_json = json.loads(pecan.request.body.decode('utf-8'))
        try:
            new_flavor = flavor_request.load_from_json(flavor_json)
            flavors_controller.add(new_flavor)

            # form the success response
            flavor_url = str(
                uri.encode(u'{0}/flavors/{1}'.format(
                    self.base_url,
                    new_flavor.flavor_id)))
            pecan.response.status = 201
            pecan.response.headers["Location"] = flavor_url

            result = flavors_controller.get(new_flavor.flavor_id)
            return flavor_response.Model(result, self)

        except Exception as e:
            pecan.abort(400, detail=str(e))
예제 #8
0
    def test_add_flavor(self, mock_session, value):
        new_flavor = flavor.load_from_json(value)

        actual_response = self.fc.add(new_flavor)

        self.assertEqual(actual_response, None)
예제 #9
0
    def test_add_flavor(self, mock_session, value):
        new_flavor = flavor.load_from_json(value)

        actual_response = self.fc.add(new_flavor)

        self.assertEqual(actual_response, None)