def _create_template(self):
     if not self.config.has_section('server-templates'):
         raise Exception('Ensure that righteous.config has a '
                         'server-templates section')
     multi_cloud_image = self.config.get(
         'server-templates', 'multi_cloud_image')
     success, location = righteous.create_server_template(
         self.template, 'test template', multi_cloud_image)
     self.assertTrue(success)
     self.assertTrue(location is not None)
     if self.delete_template:
         self.templates.append(location)
     self.assertTrue(location)
    def test_create_server_template(self):
        nickname = 'templator'
        description = 'uber template for the masses'
        cloud_image_href = '/foo/bar'

        new_template_href = '/template/new'
        self.response.status_code = 201
        self.response.headers['location'] = new_template_href

        success, location = righteous.create_server_template(
            nickname, description, cloud_image_href)
        assert success
        self.assertEqual(location, new_template_href)

        body = urlencode({
            'server_template[nickname]': nickname,
            'server_template[description]': description,
            'server_template[multi_cloud_image_href]': cloud_image_href,
        })

        self.request.assert_called_once_with(
            '/server_templates', method='POST', body=body)