def test_create_new_r_experiment(self, mock_social_token):
     """Test if an R experiment can be initialized"""
     mock_social_token.return_value = os.environ.get('GITHUB_TOKEN')
     initialize_repository(self.r_experiment.pk, self.r_cookiecutter.pk)
     self.r_experiment.refresh_from_db()
     self.assertIsNotNone(self.r_experiment)
     github_helper = GitHubHelper('test', self.r_experiment_name)
     self.assertTrue(github_helper.view_file('README.md'))
     self.assertTrue(github_helper.view_file('src/.gitignore'))
    def test_create_r_package_from_experiment(self, mock_social_token):
        """Test to create a R package from an existing experiment"""
        mock_social_token.return_value = os.environ.get('GITHUB_TOKEN')
        task_create_package_from_experiment(self.internal_r_package.pk,
                                            self.r_experiment.pk,
                                            '/src')

        self.assertIsNotNone(self.internal_r_package)
        github_helper = GitHubHelper('test', self.r_package_name)
        self.assertTrue(github_helper.view_file('DESCRIPTION'))
        self.assertIsNotNone(github_helper.view_file('R/make_dataset.R'))
    def test_create_python_package_from_experiment(self, mock_social_token):
        """Test to create a Python package from an existing experiment"""
        github_token = os.environ.get('GITHUB_TOKEN')
        mock_social_token.return_value = github_token
        task_create_package_from_experiment(self.internal_package.pk,
                                           self.python_experiment.pk,
                                            '/src/data/')

        self.assertIsNotNone(self.internal_package)
        github_helper = GitHubHelper('test', self.python_package_name)
        self.assertTrue(github_helper.view_file('requirements.txt'))
        self.assertTrue(github_helper.view_file('/{0}/make_dataset.py'.format(self.python_package_name)))
 def readme_file_of_package(self):
     internalpackage = InternalPackage.objects.get(id=self.kwargs['pk'])
     github_helper = GitHubHelper(internalpackage.owner,
                                  internalpackage.git_repo.name)
     readme = github_helper.view_file('README.md')
     md = Markdown()
     content_file = md.convert(readme)
     return content_file
 def test_create_empty_r_package(self, mock_social_token):
     """Test if an empty R package can be initialized"""
     mock_social_token.return_value = os.environ.get('GITHUB_TOKEN')
     task_create_package(self.internal_r_package.pk)
     self.internal_r_package.refresh_from_db()
     self.assertIsNotNone(self.internal_r_package)
     github_helper = GitHubHelper('test', self.r_package_name)
     self.assertTrue(github_helper.view_file('DESCRIPTION'))
 def test_create_new_python_experiment(self, mock_social_token):
     """Test if a Python experiment can be initialized"""
     mock_social_token.return_value = os.environ.get('GITHUB_TOKEN')
     initialize_repository(self.python_experiment.pk,
                           self.python_cookiecutter.pk)
     self.python_experiment.refresh_from_db()
     self.assertIsNotNone(self.python_experiment)
     github_helper = GitHubHelper('test', self.python_experiment_name)
     self.assertTrue(github_helper.view_file('requirements.txt'))
Beispiel #7
0
 def get(self, request, experiment_id):
     context = super(FileViewGitRepository, self).get(request, experiment_id)
     file_name = request.GET['file_name']
     context['file_name'] = file_name
     experiment = verify_and_get_experiment(request, experiment_id)
     github_helper = GitHubHelper(request.user, experiment.git_repo.name)
     content_file = github_helper.view_file(file_name)
     pylint_results = return_results_for_file(experiment, file_name)
     context['content_file'] = self.add_pylint_results_to_content(pylint_results, content_file)
     return render(request, 'experiments_manager/file_detail.html', context)
Beispiel #8
0
def update_setup_py_with_new_version(package_version_id):
    package_version = PackageVersion.objects.get(pk=package_version_id)
    internal_package = InternalPackage.objects.get(
        pk=package_version.package.pk)
    gh_helper = GitHubHelper(internal_package.owner,
                             internal_package.git_repo.name)
    setup_py = gh_helper.view_file('setup.py')
    setup_py = update_setup_py_new_version(package_version.version_nr,
                                           setup_py)
    gh_helper.update_file('setup.py',
                          contents=setup_py,
                          commit_message="Updated setup.py for new version")
Beispiel #9
0
def task_read_data_schema(repository_name):
    """Reads data schema from a schema/schema.json and converts it to DataSchema models in DB"""
    experiment = get_exp_or_package_from_repo_name(repository_name)
    if isinstance(experiment, Experiment):
        logger.info('reading data schema for: %s', experiment)
        github_helper = GitHubHelper(experiment.owner.user,
                                     experiment.git_repo.name)
        schema_json = json.loads(github_helper.view_file('schema/schema.json'))
        data_schema_fields = parse_json_table_schema(schema_json)
        data_schema = experiment.schema
        for field in data_schema.fields.all():
            data_schema.fields.remove(field)
            data_schema.save()
            field.delete()
        for new_field in data_schema_fields:
            new_field.save()
            data_schema.fields.add(new_field)
            data_schema.save()
        logger.info('read data schema for: %s', experiment, data_schema_fields)
    def test_create_existing_package(self, mock_social_token):
        """Test if an existing package can be added"""
        mock_social_token.return_value = os.environ.get('GITHUB_TOKEN')
        task_create_package(self.internal_package.pk)
        self.internal_package.refresh_from_db()
        self.internal_package.delete()

        new_internal_package = InternalPackage.objects.create(name=self.python_package_name,
                                                              description='Package',
                                                              language_id=2,
                                                              category_id=1,
                                                              owner_id=1,
                                                              template_id=1)

        task_create_package(new_internal_package.pk)
        new_internal_package.refresh_from_db()
        self.assertIsNotNone(new_internal_package)
        github_helper = GitHubHelper('test', self.python_package_name)
        self.assertTrue(github_helper.view_file('requirements.txt'))
Beispiel #11
0
def get_readme_of_experiment(experiment):
    github_helper = GitHubHelper(experiment.owner.user,
                                 experiment.git_repo.name)
    content_file = github_helper.view_file('README.md')
    md = Markdown()
    return md.convert(content_file)