當前位置: 首頁>>代碼示例>>Python>>正文


Python recipe.Recipe類代碼示例

本文整理匯總了Python中djangorecipe.recipe.Recipe的典型用法代碼示例。如果您正苦於以下問題:Python Recipe類的具體用法?Python Recipe怎麽用?Python Recipe使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


在下文中一共展示了Recipe類的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: test_boilerplate_1_2

    def test_boilerplate_1_2(self):
        """Test the boilerplate for django 1.2."""

        recipe = Recipe({
                'buildout': {'eggs-directory': self.eggs_dir,
                             'develop-eggs-directory': self.develop_eggs_dir,
                             'python': 'python-version',
                             'bin-directory': self.bin_dir,
                             'parts-directory': self.parts_dir,
                             'directory': self.buildout_dir,
                             'find-links': '',
                             'allow-hosts': '',
                             'versions': 'versions',
                             },
                'versions': {'django': '1.2.5'},
                'python-version': {'executable': '/python4k'},
                'py5k': {'executable': '/python5k'}},
                        'django',
                        {'recipe': 'djangorecipe',
                         'python': 'py5k', 'wsgi': 'true'})

        secret = '$55upfci7a#[email protected]&e9o1-hb*k+f$3+(&b$j=cn67h#22*0%-bj0'
        recipe.generate_secret = lambda: secret

        project_dir = os.path.join(self.buildout_dir, 'project')
        recipe.create_project(project_dir)
        settings = open(os.path.join(project_dir, 'settings.py')).read()
        settings_dict = {'project': self.recipe.options['project'],
                         'secret': secret,
                         'urlconf': self.recipe.options['urlconf'],
                         }
        from djangorecipe.boilerplate import versions
        self.assertEquals(versions['1.2']['settings'] % settings_dict,
                          settings)
開發者ID:Abouplah,項目名稱:nefpy,代碼行數:34,代碼來源:tests.py

示例2: test_relative_paths_true

    def test_relative_paths_true(self):
        recipe = Recipe(
            {
                "buildout": {
                    "eggs-directory": self.eggs_dir,
                    "develop-eggs-directory": self.develop_eggs_dir,
                    "python": "python-version",
                    "bin-directory": self.bin_dir,
                    "parts-directory": self.parts_dir,
                    "directory": self.buildout_dir,
                    "find-links": "",
                    "allow-hosts": "",
                    "develop": ".",
                    "relative-paths": "true",
                },
                "python-version": {"executable": sys.executable},
            },
            "django",
            {"recipe": "djangorecipe", "wsgi": "true"},
        )
        recipe.make_wsgi_script([], [])
        recipe.create_manage_script([], [])

        manage = os.path.join(self.bin_dir, "django")
        wsgi_script = os.path.join(self.bin_dir, "django.wsgi")

        expected = "base = os.path.dirname(os.path.abspath(os.path.realpath(__file__)))"
        self.assertTrue(expected in open(manage).read())
        self.assertTrue(expected in open(wsgi_script).read())
開發者ID:rvanlaar,項目名稱:djangorecipe,代碼行數:29,代碼來源:tests.py

示例3: test_relative_paths_true

    def test_relative_paths_true(self):
        recipe = Recipe({
                'buildout': {
                    'eggs-directory': self.eggs_dir,
                    'develop-eggs-directory': self.develop_eggs_dir,
                    'python': 'python-version',
                    'bin-directory': self.bin_dir,
                    'parts-directory': self.parts_dir,
                    'directory': self.buildout_dir,
                    'find-links': '',
                    'allow-hosts': '',
                    'develop': '.',
                    'relative-paths': 'true'
                    },
                'python-version': {'executable': sys.executable}},
                             'django',
                             {'recipe': 'djangorecipe',
                              'wsgi': 'true'})
        recipe.make_scripts([], [])
        recipe.create_manage_script([], [])

        manage = os.path.join(self.bin_dir, 'django')
        wsgi_script = os.path.join(self.bin_dir, 'django.wsgi')

        expected = base = 'base = os.path.dirname(os.path.abspath(os.path.realpath(__file__)))'
        self.assertTrue(expected in open(manage).read())
        self.assertTrue(expected in open(wsgi_script).read())
開發者ID:ethirajit,項目名稱:onlinepos,代碼行數:27,代碼來源:tests.py

示例4: test_python_option

 def test_python_option(self):
     # Changing the option for only the part will change the used Python
     # version.
     recipe_args = copy.deepcopy(self.recipe_initialisation)
     recipe_args[0].update({'py5k': {'executable': '/python5k'}})
     recipe_args[2].update({'python': 'py5k',
                            'wsgi': 'true'})
     recipe = Recipe(*recipe_args)
     wsgi_script = os.path.join(self.bin_dir, 'django.wsgi')
     recipe.make_scripts([], [])
     self.assertEqual(open(wsgi_script).readlines()[0], '#!/python5k\n')
開發者ID:sirex,項目名稱:djangorecipe,代碼行數:11,代碼來源:tests.py

示例5: setUp

    def setUp(self):
        # Create a directory for our buildout files created by the recipe
        self.buildout_dir = tempfile.mkdtemp('djangorecipe')

        self.bin_dir = os.path.join(self.buildout_dir, 'bin')
        self.develop_eggs_dir = os.path.join(self.buildout_dir,
                                             'develop-eggs')
        self.eggs_dir = os.path.join(self.buildout_dir, 'eggs')
        self.parts_dir = os.path.join(self.buildout_dir, 'parts')

        # We need to create the bin dir since the recipe should be able to
        # expect it exists
        os.mkdir(self.bin_dir)

        self.recipe = Recipe({
                'buildout': {
                    'eggs-directory': self.eggs_dir,
                    'develop-eggs-directory': self.develop_eggs_dir,
                    'python': 'python-version',
                    'bin-directory': self.bin_dir,
                    'parts-directory': self.parts_dir,
                    'directory': self.buildout_dir,
                    'find-links': '',
                    'allow-hosts': '',
                    },
                'python-version': {'executable': sys.executable}},
                             'django',
                             {'recipe': 'djangorecipe'})
開發者ID:Abouplah,項目名稱:nefpy,代碼行數:28,代碼來源:tests.py

示例6: test_python_option

 def test_python_option(self):
     # The python option makes it possible to specify a specific Python 
     # executable which is to be used for the generated scripts.
     recipe = Recipe({'buildout': {'eggs-directory': self.eggs_dir,
                                   'develop-eggs-directory': self.develop_eggs_dir,
                                   'python': 'python-version',
                                   'bin-directory': self.bin_dir,
                                   'parts-directory': self.parts_dir,
                                   'directory': self.buildout_dir,
                                  },
                      'python-version': {'executable': '/python4k'}}, 
                     'django',
                     {'recipe': 'djangorecipe', 'version': 'trunk',
                      'wsgi': 'true'})
     recipe.make_scripts([], [])
     # This should have created a script in the bin dir
     wsgi_script = os.path.join(self.bin_dir, 'django.wsgi')
     self.assertEqual(open(wsgi_script).readlines()[0], '#!/python4k\n')
     # Changeing the option for only the part will change the used Python
     # version.
     recipe = Recipe({'buildout': {'eggs-directory': self.eggs_dir,
                                   'develop-eggs-directory': self.develop_eggs_dir,
                                   'python': 'python-version',
                                   'bin-directory': self.bin_dir,
                                   'parts-directory': self.parts_dir,
                                   'directory': self.buildout_dir,
                                  },
                      'python-version': {'executable': '/python4k'},
                      'py5k': {'executable': '/python5k'}}, 
                     'django',
                     {'recipe': 'djangorecipe', 'version': 'trunk',
                      'python': 'py5k', 'wsgi': 'true'})
     recipe.make_scripts([], [])
     self.assertEqual(open(wsgi_script).readlines()[0], '#!/python5k\n')        
開發者ID:attilaolah,項目名稱:djangorecipe,代碼行數:34,代碼來源:tests.py

示例7: test_boilerplate_1_2

    def test_boilerplate_1_2(self):
        """Test the boilerplate for django 1.2."""

        recipe_args = copy.deepcopy(self.recipe_initialisation)

        recipe_args[0]['versions'] = {'django': '1.2.5'}
        recipe = Recipe(*recipe_args)

        secret = '$55upfci7a#[email protected]&e9o1-hb*k+f$3+(&b$j=cn67h#22*0%-bj0'
        recipe.generate_secret = lambda: secret

        project_dir = os.path.join(self.buildout_dir, 'project')
        recipe.create_project(project_dir)
        settings = open(os.path.join(project_dir, 'settings.py')).read()
        settings_dict = {'project': self.recipe.options['project'],
                         'secret': secret,
                         'urlconf': self.recipe.options['urlconf'],
                         }
        from djangorecipe.boilerplate import versions

        self.assertEqual(versions['1.2']['settings'] % settings_dict,
                          settings)
開發者ID:hekevintran,項目名稱:djangorecipe,代碼行數:22,代碼來源:tests.py

示例8: test_boilerplate_1_2

    def test_boilerplate_1_2(self):
        """Test the boilerplate for django 1.2."""

        recipe_args = copy.deepcopy(self.recipe_initialisation)

        recipe_args[0]["versions"] = {"django": "1.2.5"}
        recipe = Recipe(*recipe_args)

        secret = "$55upfci7a#[email protected]&e9o1-hb*k+f$3+(&b$j=cn67h#22*0%-bj0"
        recipe.generate_secret = lambda: secret

        project_dir = os.path.join(self.buildout_dir, "project")
        recipe.create_project(project_dir)
        settings = open(os.path.join(project_dir, "settings.py")).read()
        settings_dict = {
            "project": self.recipe.options["project"],
            "secret": secret,
            "urlconf": self.recipe.options["urlconf"],
        }
        from djangorecipe.boilerplate import versions

        self.assertEqual(versions["1.2"]["settings"] % settings_dict, settings)
開發者ID:redsnapper8t8,項目名稱:djangorecipe,代碼行數:22,代碼來源:tests.py

示例9: TestRecipe

class TestRecipe(unittest.TestCase):

    def setUp(self):
        # Create a directory for our buildout files created by the recipe
        self.buildout_dir = tempfile.mkdtemp('djangorecipe')

        self.bin_dir = os.path.join(self.buildout_dir, 'bin')
        self.develop_eggs_dir = os.path.join(self.buildout_dir,
                                             'develop-eggs')
        self.eggs_dir = os.path.join(self.buildout_dir, 'eggs')
        self.parts_dir = os.path.join(self.buildout_dir, 'parts')

        # We need to create the bin dir since the recipe should be able to
        # expect it exists
        os.mkdir(self.bin_dir)

        self.recipe = Recipe({
                'buildout': {
                    'eggs-directory': self.eggs_dir,
                    'develop-eggs-directory': self.develop_eggs_dir,
                    'python': 'python-version',
                    'bin-directory': self.bin_dir,
                    'parts-directory': self.parts_dir,
                    'directory': self.buildout_dir,
                    'find-links': '',
                    'allow-hosts': '',
                    },
                'python-version': {'executable': sys.executable}},
                             'django',
                             {'recipe': 'djangorecipe'})

    def tearDown(self):
        # Remove our test dir
        shutil.rmtree(self.buildout_dir)

    def test_consistent_options(self):
        # Buildout is pretty clever in detecting changing options. If
        # the recipe modifies it's options during initialisation it
        # will store this to determine wheter it needs to update or do
        # a uninstall & install. We need to make sure that we normally
        # do not trigger this. That means running the recipe with the
        # same options should give us the same results.
        self.assertEqual(*[
                Recipe({'buildout': {
                            'eggs-directory': self.eggs_dir,
                            'develop-eggs-directory': self.develop_eggs_dir,
                            'python': 'python-version',
                            'bin-directory': self.bin_dir,
                            'parts-directory': self.parts_dir,
                            'directory': self.buildout_dir,
                            'find-links': '',
                            'allow-hosts':'',
                            },
                        'python-version': {'executable': sys.executable}},
                       'django',
                       {'recipe': 'djangorecipe'}).options.copy()
                for i in range(2)])

    def test_create_file(self):
        # The create file helper should create a file at a certain
        # location unless it already exists. We will need a
        # non-existing file first.
        f, name = tempfile.mkstemp()
        # To show the function in action we need to delete the file
        # before testing.
        os.remove(name)
        # The method accepts a template argument which it will use
        # with the options argument for string substitution.
        self.recipe.create_file(name, 'Spam %s', 'eggs')
        # Let's check the contents of the file
        self.assertEqual(open(name).read(), 'Spam eggs')
        # If we try to write it again it will just ignore our request
        self.recipe.create_file(name, 'Spam spam spam %s', 'eggs')
        # The content of the file should therefore be the same
        self.assertEqual(open(name).read(), 'Spam eggs')
        # Now remove our temp file
        os.remove(name)

    def test_generate_secret(self):
        # To create a basic skeleton the recipe also generates a
        # random secret for the settings file. Since it should very
        # unlikely that it will generate the same key a few times in a
        # row we will test it with letting it generate a few keys.
        self.assert_(len(set(
                    [self.recipe.generate_secret() for i in range(10)])) > 1)

    def test_make_protocol_scripts(self):
        # To ease deployment a WSGI script can be generated. The
        # script adds any paths from the `extra_paths` option to the
        # Python path.
        self.recipe.options['wsgi'] = 'true'
        self.recipe.options['fcgi'] = 'true'
        self.recipe.make_scripts([], [])
        # This should have created a script in the bin dir
        wsgi_script = os.path.join(self.bin_dir, 'django.wsgi')
        self.assert_(os.path.exists(wsgi_script))
        # The contents should list our paths
        contents = open(wsgi_script).read()
        # It should also have a reference to our settings module
        self.assert_('project.development' in contents)
#.........這裏部分代碼省略.........
開發者ID:Abouplah,項目名稱:nefpy,代碼行數:101,代碼來源:tests.py

示例10: TestRecipe

class TestRecipe(unittest.TestCase):

    def setUp(self):
        # Create a directory for our buildout files created by the recipe
        self.buildout_dir = tempfile.mkdtemp('djangorecipe')
        
        self.bin_dir = os.path.join(self.buildout_dir, 'bin')
        self.develop_eggs_dir = os.path.join(self.buildout_dir, 
                                             'develop-eggs')
        self.eggs_dir = os.path.join(self.buildout_dir, 'eggs')
        self.parts_dir = os.path.join(self.buildout_dir, 'parts')

        # We need to create the bin dir since the recipe should be able to expect it exists
        os.mkdir(self.bin_dir)

        self.recipe = Recipe({'buildout': {'eggs-directory': self.eggs_dir,
                                           'develop-eggs-directory': self.develop_eggs_dir,
                                           'python': 'python-version',
                                           'bin-directory': self.bin_dir,
                                           'parts-directory': self.parts_dir,
                                           'directory': self.buildout_dir,
                                           },
                              'python-version': {'executable': sys.executable}}, 
                             'django', 
                             {'recipe': 'djangorecipe',
                              'version': 'trunk'})

    def tearDown(self):
        # Remove our test dir
        shutil.rmtree(self.buildout_dir)

    def test_consistent_options(self):
        # Buildout is pretty clever in detecting changing options. If
        # the recipe modifies it's options during initialisation it
        # will store this to determine wheter it needs to update or do
        # a uninstall & install. We need to make sure that we normally
        # do not trigger this. That means running the recipe with the
        # same options should give us the same results.
        self.assertEqual(*[
                Recipe({'buildout': {'eggs-directory': self.eggs_dir,
                                     'develop-eggs-directory': self.develop_eggs_dir,
                                     'python': 'python-version',
                                     'bin-directory': self.bin_dir,
                                     'parts-directory': self.parts_dir,
                                     'directory': self.buildout_dir,
                                     },
                        'python-version': {'executable': sys.executable}}, 
                       'django', 
                       {'recipe': 'djangorecipe',
                        'version': 'trunk'}).options.copy() for i in range(2)])

    def test_svn_url(self):
        # Make sure that only a few specific type of url's are
        # considered svn url's

        # This is a plain release version so it should indicate it is
        # not a svn url
        self.failIf(self.recipe.is_svn_url('0.96.2'))
        # The next line specifies a proper link with the trunk
        self.assert_(self.recipe.is_svn_url('trunk'))
        # A url looking like trunk should also fail
        self.failIf(self.recipe.is_svn_url('trunka'))
        # A full svn url including version should work
        self.assert_(self.recipe.is_svn_url(
            'http://code.djangoproject.com/svn/django/branches/[email protected]'))
        # HTTPS should work too
        self.assert_(self.recipe.is_svn_url(
            'https://code.djangoproject.com/svn/django/branches/[email protected]'))
        # Svn+ssh should work
        self.assert_(self.recipe.is_svn_url(
            'svn+ssh://myserver/[email protected]'))
        # Svn protocol through any custom tunnel defined in ~/.subversion/config should work
        self.assert_(self.recipe.is_svn_url(
            'svn+MY_Custom-tunnel://myserver/[email protected]'))
        # Using a non existent protocol should not be a svn url?
        self.failIf(self.recipe.is_svn_url(
            'unknown://myserver/[email protected]'))

    def test_command(self):
        # The command method is a wrapper for subprocess which excutes
        # a command and return's it's status code. We will demonstrate
        # this with a simple test of running `dir`.
        self.failIf(self.recipe.command('echo'))
        # Executing a non existing command should return an error code
        self.assert_(self.recipe.command('spamspamspameggs'))

    @mock.patch('subprocess', 'Popen')
    def test_command_verbose_mode(self, popen):
        # When buildout is put into verbose mode the command methode
        # should stop capturing the ouput of it's commands.
        popen.return_value = mock.Mock()
        self.recipe.buildout['buildout']['verbosity'] = 'verbose'
        self.recipe.command('silly-command')
        self.assertEqual(
            popen.call_args, 
            (('silly-command',), {'shell': True, 'stdout': None}))
        
    def test_create_file(self):
        # The create file helper should create a file at a certain
        # location unless it already exists. We will need a
#.........這裏部分代碼省略.........
開發者ID:attilaolah,項目名稱:djangorecipe,代碼行數:101,代碼來源:tests.py


注:本文中的djangorecipe.recipe.Recipe類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。