示例#1
0
def test_files_from_list(web_fixture):
    """An explicit list of files can also be added on an URL as if they were in a single
       directory.
    """

    files_dir = temp_dir()
    one_file = files_dir.file_with('any_name_will_do_here', 'one')

    class MainUI(UserInterface):
        def assemble(self):
            list_of_files = [FileOnDisk(one_file.name, 'one_file')]
            self.define_static_files('/morestaticfiles', list_of_files)

    wsgi_app = web_fixture.new_wsgi_app(site_root=MainUI)
    browser = Browser(wsgi_app)

    # How the first file would be accessed
    browser.open('/morestaticfiles/one_file')
    assert browser.raw_html == 'one'

    # The meta-info of the file
    response = browser.last_response
    assert response.content_type == 'application/octet-stream'
    assert response.content_encoding is None
    assert response.content_length == 3
    expected_mtime = datetime.datetime.fromtimestamp(
        int(os.path.getmtime(one_file.name)))
    assert response.last_modified.replace(tzinfo=None) == expected_mtime
    expected_tag = '%s-%s-%s' % (os.path.getmtime(
        one_file.name), 3, abs(hash(one_file.name)))
    assert response.etag == expected_tag

    # When a file does not exist
    browser.open('/morestaticfiles/one_that_does_not_exist', status=404)
示例#2
0
 def new_egg_dir(self):
     egg_dir = temp_dir()
     package_dir = egg_dir.sub_dir('static_files')
     init_file = package_dir.file_with('__init__.py', '')
     js_file = package_dir.file_with('somefile.js', 'contents - js')
     css_file = package_dir.file_with('somefile.css', 'contents - css')
     return egg_dir
示例#3
0
def test_packaged_files(web_fixture):
    """Files can also be served straight from a python egg."""

    # Create an egg with package packaged_files, containing the file packaged_file
    egg_dir = temp_dir()
    package_dir = egg_dir.sub_dir('packaged_files')
    init_file = package_dir.file_with('__init__.py', '')
    afile = package_dir.file_with('packaged_file', 'contents')

    easter_egg.clear()
    pkg_resources.working_set.add(easter_egg)
    easter_egg.location = egg_dir.name

    class MainUI(UserInterface):
        def assemble(self):
            list_of_files = [
                PackagedFile(easter_egg.as_requirement_string(),
                             'packaged_files', 'packaged_file')
            ]
            self.define_static_files('/files', list_of_files)

    wsgi_app = web_fixture.new_wsgi_app(site_root=MainUI)
    browser = Browser(wsgi_app)

    # How the file would be accessed
    browser.open('/files/packaged_file')
    assert browser.raw_html == 'contents'
示例#4
0
def test_concatenated_files(web_fixture, concatenate_scenarios):
    """Files can also be formed by concatenating other files.  Files ending in .css or .js are appropriately
       minified in the process."""

    fixture = concatenate_scenarios

    # Make an egg with a package called packaged_files, and two files in there.
    egg_dir = temp_dir()
    package_dir = egg_dir.sub_dir('packaged_files')
    init_file = package_dir.file_with('__init__.py', '')
    afile = package_dir.file_with('packaged_file', fixture.file1_contents)
    another_file = package_dir.file_with('packaged_file2',
                                         fixture.file2_contents)

    pkg_resources.working_set.add(easter_egg)
    easter_egg.location = egg_dir.name

    class MainUI(UserInterface):
        def assemble(self):
            to_concatenate = [
                PackagedFile('test==1.0', 'packaged_files', 'packaged_file'),
                PackagedFile('test==1.0', 'packaged_files', 'packaged_file2')
            ]
            list_of_files = [
                ConcatenatedFile(fixture.filename, to_concatenate)
            ]
            self.define_static_files('/files', list_of_files)

    web_fixture.config.reahlsystem.debug = False  # To enable minification
    wsgi_app = web_fixture.new_wsgi_app(site_root=MainUI)
    browser = Browser(wsgi_app)

    # How the first file would be accessed
    browser.open('/files/%s' % fixture.filename)
    assert browser.raw_html == fixture.expected_result
示例#5
0
def test_reading_and_writing_repository():
    repository_state_dir = temp_dir()

    @stubclass(SshRepository)
    class RepositoryStub:
        @property
        def unique_id(self):
            return 'myid'

        repository_state_directory = repository_state_dir.name

    repository = RepositoryStub()
    expected_repository_state_file = os.path.join(
        repository_state_dir.name, '%s.uploaded' % repository.unique_id)

    local_state = RepositoryLocalState(repository)

    # Case: on first read, does not break if file does not exist
    assert not os.path.exists(expected_repository_state_file)
    local_state.read()
    assert local_state.uploaded_project_ids == set([])

    # Case: on write, creates file
    assert not os.path.exists(expected_repository_state_file)
    local_state.uploaded_project_ids = {'someid1', 'someid2'}
    local_state.write()
    assert os.path.isfile(expected_repository_state_file)

    # Case: read existing stuff correctly
    local_state.uploaded_project_ids = set([])
    local_state.read()
    assert local_state.uploaded_project_ids == {'someid1', 'someid2'}
示例#6
0
def test_egg_project_file_queries():
    workspace_dir = temp_dir()
    project_dir = workspace_dir.temp_dir()
    project_filename = os.path.join(project_dir.name, '.reahlproject')
    @stubclass(Workspace)
    class WorkspaceStub(object):
        directory = workspace_dir.name
    workspace = WorkspaceStub()

    # Case where the file exists with stuff in it
    xml_file = project_dir.file_with('.reahlproject', '''
<project type="egg" basket="some-basket">
<distpackage type="deb">
<sshdirectory host="localhost1" destination="/a/b"/>
<sshdirectory host="localhost2" login="******" destination="/a/c"/>
</distpackage>
</project>
''')
    project = Project.from_file(workspace, project_dir.name)

    assert isinstance(project, EggProject)
    assert project.basket_name == 'some-basket'

    [package] = project.packages_to_distribute
    assert isinstance(package, DebianPackage)
    assert package.project is project

    [repository1, repository2] = package.repositories
    assert repository1.host == 'localhost1'
    assert repository1.login == os.environ.get('USER', '')
    assert repository1.destination == '/a/b'
    assert repository2.host == 'localhost2'
    assert repository2.login == 'someusername'
    assert repository2.destination == '/a/c'
示例#7
0
 def new_git_directory(self, initialised=True):
     git_directory = temp_dir()
     if initialised:
         with open(os.devnull, 'w') as DEVNULL:
             Executable('git').check_call(['init'],
                                          cwd=git_directory.name,
                                          stdout=DEVNULL,
                                          stderr=DEVNULL)
     return git_directory
示例#8
0
def test_planning(fixture):
    """A plan can be explained by generating graphs used by the migration algorithm.
    """

    egg = ReahlEggStub('my_egg', {'1.0': [], '1.1': []})

    plan = MigrationPlan(egg, fixture.orm_control)
    plan.do_planning()

    with temp_dir().as_cwd() as dir_name:
        plan.explain()
        assert os.path.isfile(os.path.join(dir_name, 'clusters.svg'))
        assert os.path.isfile(os.path.join(dir_name, 'versions.svg'))
        assert os.path.isfile(os.path.join(dir_name, 'schedules.svg'))
示例#9
0
def test_generic_project_file_queries():
    workspace_dir = temp_dir()
    project_dir = workspace_dir.temp_dir()
    project_filename = os.path.join(project_dir.name, '.reahlproject')

    @stubclass(Workspace)
    class WorkspaceStub:
        directory = workspace_dir.name

    workspace = WorkspaceStub()

    # Case where the file does not exist
    assert not os.path.exists(project_filename)
    with expected(NotAValidProjectException):
        Project.from_file(workspace, project_dir.name)

    # Case where the file exists, but is empty
    xml_file = project_dir.file_with('.reahlproject', '')
    with expected(InvalidProjectFileException):
        Project.from_file(workspace, project_dir.name)

    # Case where the file exists with stuff in it
    del xml_file
    xml_file = project_dir.file_with(
        '.reahlproject', '''
<project type="egg">
<distpackage type="deb">
<sshdirectory host="localhost1" destination="/a/b"/>
<sshdirectory host="localhost2" login="******" destination="/a/c"/>
</distpackage>
</project>
''')
    project = Project.from_file(workspace, project_dir.name)

    assert isinstance(project, Project)

    [package] = project.packages_to_distribute
    assert isinstance(package, DebianPackage)
    assert package.project is project

    [repository1, repository2] = package.repositories
    assert repository1.host == 'localhost1'
    assert repository1.login == os.environ.get('USER', '')
    assert repository1.destination == '/a/b'
    assert repository2.host == 'localhost2'
    assert repository2.login == 'someusername'
    assert repository2.destination == '/a/c'
示例#10
0
def test_files_from_disk(web_fixture):
    """A directory in the web.static_root configuration setting, can be mounted on a URL
       named after it on the WebApplication.
    """

    static_root = temp_dir()
    files_dir = static_root.sub_dir('staticfiles')
    sub_dir = files_dir.sub_dir('subdir')
    one_file = files_dir.file_with('one_file.xml', 'one')
    nested_file = sub_dir.file_with('nested_file', 'other')

    # How the config is set
    web_fixture.config.web.static_root = static_root.name

    # How the subdirectory is mounted
    class MainUI(UserInterface):
        def assemble(self):
            self.define_static_directory('/staticfiles')

    wsgi_app = web_fixture.new_wsgi_app(site_root=MainUI)
    browser = Browser(wsgi_app)

    # How the first file would be accessed
    browser.open('/staticfiles/one_file.xml')
    assert browser.raw_html == 'one'

    # The meta-info of the file
    response = browser.last_response
    assert response.content_type == 'application/xml'
    assert response.content_encoding is None
    assert response.content_length == 3
    expected_mtime = datetime.datetime.fromtimestamp(
        int(os.path.getmtime(one_file.name)))
    assert response.last_modified.replace(tzinfo=None) == expected_mtime
    expected_tag = '%s-%s-%s' % (os.path.getmtime(
        one_file.name), 3, abs(hash(one_file.name)))
    assert response.etag == expected_tag

    # How the file in the subdirectory would be accessed
    browser.open('/staticfiles/subdir/nested_file')
    assert browser.raw_html == 'other'

    # When a file does not exist
    browser.open('/staticfiles/one_that_does_not_exist', status=404)
def test_example_renames():
    """When checking out an example with another name, the relevant parts of the code is changed and files are renamed to the new name."""

    cwd = temp_dir()
    with in_directory(cwd.name):
        GetExample().do(['-n', 'newname', 'tutorial.i18nexamplebootstrap'])

    root = pathlib.Path(cwd.name).joinpath('newname')
    assert root.is_dir()
    assert root.joinpath('newname_dev').is_dir()
    test_file = root.joinpath('newname_dev').joinpath('test_newname.py')
    assert test_file.is_file()
    messages_path = root.joinpath('newnamemessages')
    assert messages_path.is_dir()
    po_file = messages_path.joinpath('af').joinpath('LC_MESSAGES').joinpath(
        'newname.po')
    assert po_file.is_file()
    template = messages_path.joinpath('newname')
    assert template.is_file()
    module_file = root.joinpath('newname.py')
    assert module_file.is_file()

    web_config = root.joinpath('etc').joinpath('web.config.py')
    assert 'from newname import AddressBookUI' in web_config.read_text(
    ).splitlines()

    assert 'from newname import AddressBookUI, Address' in test_file.read_text(
    ).splitlines()

    assert any([
        line.startswith('#: newname/newname.py:')
        for line in po_file.read_text().splitlines()
    ])
    assert any([
        line.startswith('#: newname/newname.py:')
        for line in template.read_text().splitlines()
    ])

    assert '_ = Catalogue(\'newname\')' in module_file.read_text().splitlines()
    assert '    __tablename__ = \'newname_address\'' in module_file.read_text(
    ).splitlines()
示例#12
0
 def new_config_dir(self):
     return temp_dir()
示例#13
0
 def new_to_upload_directory(self):
     return temp_dir()
示例#14
0
 def new_state_directory(self):
     return temp_dir()
示例#15
0
 def new_incoming_directory(self):
     return temp_dir()
示例#16
0
def test_setup_project_file_queries():
    workspace_dir = temp_dir()
    project_dir = workspace_dir.temp_dir()
    project_filename = os.path.join(project_dir.name, '.reahlproject')
    project_source = project_dir.sub_dir('this')
    project_source_init = project_source.file_with('__init__.py', '')
    project_package1 = project_source.sub_dir('pack1')
    project_package1_init = project_package1.file_with('__init__.py', '')
    project_package2 = project_source.sub_dir('pack2')
    project_package2_init = project_package2.file_with('__init__.py', '')
    project_egg = project_dir.file_with('projegg.py', '')
    project_dev = project_source.sub_dir('proj_dev')

    @stubclass(Project)
    class ProjectStub:
        version = VersionNumber('1.2.5')

    @stubclass(Workspace)
    class WorkspaceStub:
        directory = workspace_dir.name
        project_name = 'proj'
        projects = []

        def project_named(self, name):
            return ProjectStub()

        def has_project_named(self, name):
            return True

    workspace = WorkspaceStub()

    # Case where the file does not exist
    assert not os.path.exists(project_filename)
    with expected(NotAValidProjectException):
        Project.from_file(workspace, project_dir.name)

    # Case where the file exists, but is empty
    xml_file = project_dir.file_with('.reahlproject', '')
    with expected(InvalidProjectFileException):
        Project.from_file(workspace, project_dir.name)

    # Case where the file exists with stuff in it
    del xml_file
    xml_file = project_dir.file_with(
        '.reahlproject', '''
<project type="egg" packagedata="included">
<namespaces>
<package name="this"/>
</namespaces>

<tag name="sometag"/>

<distpackage type="deb">
<sshdirectory host="localhost1" destination="/a/b"/>
</distpackage>

<version number="0.0">
  <deps purpose="run">
    <egg name="reahl-xmlreader-run"/>
  </deps>
</version>

<deps purpose="test">
<egg name="reahl-xmlreader-test"/>
</deps>

<deps purpose="build">
<egg name="reahl-xmlreader-build"/>
</deps>

<script name="script1" locator="some script"/>
<script name="script2" locator="some other script"/>

<export entrypoint="entrypoint name 1" name="name1" locator="locator1"/>
<export entrypoint="entrypoint name 2" name="name2" locator="locator2"/>

<excludepackage name="this.pack2"/>

<pythonpath path="stuff"/>
<pythonpath path="stuff2"/>

</project>
''')
    project = Project.from_file(workspace, project_dir.name)

    # Default Metadata queries that will com for setup.py:
    assert project.project_name == os.path.basename(project_dir.name)
    assert str(project.version) == '0.0'

    @stubclass(ProjectMetadata)
    class MetadataStub:
        @property
        def version(self):
            return VersionNumber('3.1.2a1-ubuntu1')

        @property
        def project_name(self):
            return 'test-proj'

    project.metadata = MetadataStub()
    assert str(project.version_for_setup()) == '3.1.2a1'
    assert project.project_name == 'test-proj'

    packages = project.packages_for_setup()
    assert packages == ['this', 'this.pack1']
    assert project.py_modules_for_setup() == []
    assert project.include_package_data == True
    assert project.namespace_packages_for_setup() == ['this']

    expected_value = ['reahl-xmlreader-run>=1.2,<1.3']
    actual = project.run_deps_for_setup()
    assert actual == expected_value

    expected_value = ['reahl-xmlreader-test>=1.2,<1.3']
    actual = project.test_deps_for_setup()
    assert actual == expected_value

    expected_value = ['reahl-xmlreader-build>=1.2,<1.3']
    actual = project.build_deps_for_setup()
    assert actual == expected_value

    assert project.test_suite_for_setup() == 'this.proj_dev'

    expected_value = {
        'console_scripts':
        ['script1 = some script', 'script2 = some other script'],
        'entrypoint name 2': ['name2 = locator2'],
        'reahl.eggs': ['Egg = reahl.component.eggs:ReahlEgg'],
        'entrypoint name 1': ['name1 = locator1'],
        'reahl.versiondeps.0.0': ['reahl-xmlreader-run = egg:_'],
        'reahl.versions': ['0.0 = 0.0']
    }

    assert project.entry_points_for_setup() == expected_value

    assert project.python_path == ['stuff', 'stuff2']

    assert project.tags == ['sometag', 'component', 'toplevel']
 def new_egg_directory(self):
     return temp_dir()
示例#18
0
 def new_repository_directory(self):
     return temp_dir()
示例#19
0
 def __init__(self):
     self.temp_directory = temp_dir()
     self.create_files()
 def new_checkout_directory(self):
     return temp_dir()
示例#21
0
 def new_static_dir(self):
     return temp_dir()
示例#22
0
 def new_working_directory(self):
     return temp_dir()
示例#23
0
 def new_dir_to_watch(self):
     return temp_dir()