import os

from unittest2 import TestCase

from chef.api import ChefAPI

TEST_ROOT = os.path.dirname(os.path.abspath(__file__))

def test_chef_api():
    return ChefAPI('https://api.opscode.com/organizations/pycheftest', os.path.join(TEST_ROOT, 'client.pem'), 'unittests')


class ChefTestCase(TestCase):
    """Base class for Chef unittests."""
    
    def setUp(self):
        super(ChefTestCase, self).setUp()
        self.api = test_chef_api
        self.api.set_default()

import os
import random

from unittest2 import TestCase

from chef.api import ChefAPI

TEST_ROOT = os.path.dirname(os.path.abspath(__file__))

def test_chef_api():
    return ChefAPI('https://api.opscode.com/organizations/pycheftest', os.path.join(TEST_ROOT, 'client.pem'), 'unittests')


class ChefTestCase(TestCase):
    """Base class for Chef unittests."""
    
    def setUp(self):
        super(ChefTestCase, self).setUp()
        self.api = test_chef_api
        self.api.set_default()

    def random(self, length=8, alphabet='0123456789abcdef'):
        return ''.join(random.choice(alphabet) for _ in xrange(length))

Add a method to generate random names for testing.
Add a method to generate random names for testing.
  import os
+ import random
  
  from unittest2 import TestCase
  
  from chef.api import ChefAPI
  
  TEST_ROOT = os.path.dirname(os.path.abspath(__file__))
  
  def test_chef_api():
      return ChefAPI('https://api.opscode.com/organizations/pycheftest', os.path.join(TEST_ROOT, 'client.pem'), 'unittests')
  
  
  class ChefTestCase(TestCase):
      """Base class for Chef unittests."""
      
      def setUp(self):
          super(ChefTestCase, self).setUp()
          self.api = test_chef_api
          self.api.set_default()
  
+     def random(self, length=8, alphabet='0123456789abcdef'):
+         return ''.join(random.choice(alphabet) for _ in xrange(length))
+ 
Add a method to generate random names for testing.
## Code Before:
import os

from unittest2 import TestCase

from chef.api import ChefAPI

TEST_ROOT = os.path.dirname(os.path.abspath(__file__))

def test_chef_api():
    return ChefAPI('https://api.opscode.com/organizations/pycheftest', os.path.join(TEST_ROOT, 'client.pem'), 'unittests')


class ChefTestCase(TestCase):
    """Base class for Chef unittests."""
    
    def setUp(self):
        super(ChefTestCase, self).setUp()
        self.api = test_chef_api
        self.api.set_default()

## Instruction:
Add a method to generate random names for testing.
## Code After:
import os
import random

from unittest2 import TestCase

from chef.api import ChefAPI

TEST_ROOT = os.path.dirname(os.path.abspath(__file__))

def test_chef_api():
    return ChefAPI('https://api.opscode.com/organizations/pycheftest', os.path.join(TEST_ROOT, 'client.pem'), 'unittests')


class ChefTestCase(TestCase):
    """Base class for Chef unittests."""
    
    def setUp(self):
        super(ChefTestCase, self).setUp()
        self.api = test_chef_api
        self.api.set_default()

    def random(self, length=8, alphabet='0123456789abcdef'):
        return ''.join(random.choice(alphabet) for _ in xrange(length))
