Ejemplo n.º 1
0
    def _test_wizard(self, mock_project_access, conf=None, target='default',
                     image=None, sh_yml=None, scrapy_cfg=True,
                     dockerfile=False, **kwargs):
        if not conf:
            conf = ShubConfig()
            conf.apikeys = {'default': 'abcdef'}
        mock_project_access.return_value = self.has_project_access

        @click.command()
        def call_wizard():
            utils.create_scrapinghub_yml_wizard(
                conf, target=target, image=image)

        with self.runner.isolated_filesystem():
            if scrapy_cfg:
                open('scrapy.cfg', 'w').close()
            if dockerfile:
                open('Dockerfile', 'w').close()
            if sh_yml:
                with open('scrapinghub.yml', 'w') as f:
                    f.write(sh_yml)
                conf.load_file('scrapinghub.yml')
            result = self.runner.invoke(call_wizard, **kwargs)
            if os.path.exists('scrapinghub.yml'):
                with open('scrapinghub.yml', 'r') as f:
                    sh_yml = yaml.safe_load(f.read())
            else:
                sh_yml = None
            return result, conf, sh_yml
Ejemplo n.º 2
0
    def _test_wizard(self, mock_project_access, conf=None, target='default',
                     image=None, sh_yml=None, scrapy_cfg=True,
                     dockerfile=False, **kwargs):
        if not conf:
            conf = ShubConfig()
            conf.apikeys = {'default': 'abcdef'}
        mock_project_access.return_value = self.has_project_access

        @click.command()
        def call_wizard():
            utils.create_scrapinghub_yml_wizard(
                conf, target=target, image=image)

        with self.runner.isolated_filesystem():
            if scrapy_cfg:
                open('scrapy.cfg', 'w').close()
            if dockerfile:
                open('Dockerfile', 'w').close()
            if sh_yml:
                with open('scrapinghub.yml', 'w') as f:
                    f.write(sh_yml)
                conf.load_file('scrapinghub.yml')
            result = self.runner.invoke(call_wizard, **kwargs)
            if os.path.exists('scrapinghub.yml'):
                with open('scrapinghub.yml', 'r') as f:
                    sh_yml = yaml.safe_load(f.read())
            else:
                sh_yml = None
            return result, conf, sh_yml
Ejemplo n.º 3
0
 def test_dont_leak_global_config(self):
     conf = ShubConfig()
     conf.projects = {'prod': 33333}
     conf.apikeys = {'default': 'abc'}
     result, conf, sh_yml = self._test_wizard(conf=conf, input='12345\n')
     assert result.exit_code == 0
     assert conf.projects == {'default': 12345, 'prod': 33333}
     assert conf.apikeys == {'default': 'abc'}
     assert sh_yml == {'project': 12345}
Ejemplo n.º 4
0
 def test_dont_leak_global_config(self):
     conf = ShubConfig()
     conf.projects = {'prod': 33333}
     conf.apikeys = {'default': 'abc'}
     result, conf, sh_yml = self._test_wizard(conf=conf, input='12345\n')
     assert result.exit_code == 0
     assert conf.projects == {'default': 12345, 'prod': 33333}
     assert conf.apikeys == {'default': 'abc'}
     assert sh_yml == {'project': 12345}
Ejemplo n.º 5
0
 def test_dont_leak_global_config_on_image(self):
     conf = ShubConfig()
     conf.projects = {'prod': 33333}
     conf.apikeys = {'default': 'abc'}
     result, conf, sh_yml = self._test_wizard(
         conf=conf, scrapy_cfg=False, dockerfile=True,
         input='12345\nrepo\n')
     assert result.exit_code == 0
     assert conf.projects == {'default': 12345, 'prod': 33333}
     assert conf.apikeys == {'default': 'abc'}
     assert conf.images == {'default': 'repo'}
     assert sh_yml == {'project': 12345, 'image': 'repo'}
Ejemplo n.º 6
0
 def test_dont_leak_global_config_on_image(self):
     conf = ShubConfig()
     conf.projects = {'prod': 33333}
     conf.apikeys = {'default': 'abc'}
     result, conf, sh_yml = self._test_wizard(
         conf=conf, scrapy_cfg=False, dockerfile=True,
         input='12345\nrepo\n')
     assert result.exit_code == 0
     assert conf.projects == {'default': 12345, 'prod': 33333}
     assert conf.apikeys == {'default': 'abc'}
     assert conf.images == {'default': 'repo'}
     assert sh_yml == {'project': 12345, 'image': 'repo'}