Exemplo n.º 1
0
    def test_should_create_new_repository(self):
        # Given
        user = '******'
        repo = self._get_random_string(8)
        full_name = '%s/%s' % (user, repo)
        response = Mock(status_code=201)

        # When
        with patch('requests.post', Mock(return_value=response)) as post:
            created = github_utils.create_new_repository(full_name, GH_TOKEN)

        # Then
        args, kwargs = post.call_args
        self.assertIn(GH_TOKEN, kwargs['headers']['Authorization'])
        self.assertEqual(repo, json.loads(kwargs['data'])['name'])
        self.assertTrue(created)
Exemplo n.º 2
0
def create_repo():

    repo_name = request.form.get('repo_name', '')
    github_token = current_user.github_token

    if len(repo_name) > 0:
        full_name = '%s/%s' % (current_user.username, repo_name)

    else:
        full_name = '{0}/{0}.github.io'.format(current_user.username)

    created = exists = overwrite = False

    # If repo does not exist, create it.
    if not github_utils.is_valid_repository(full_name):
        if github_utils.create_new_repository(full_name, github_token):
            created = True
            message = messages.CREATE_REPO_SUCCESS
        else:
            message = messages.CREATE_REPO_FAILURE

    elif github_utils.exists(full_name, '.travis.yml', github_token):
        exists = True
        overwrite = True
        message = messages.OVERWRITE_YAML

    else:
        exists = True
        message = messages.REPO_EXISTS

    data = {
        'exists': exists,
        'created': created,
        'overwrite': overwrite,
        'message': message,
        'full_name': full_name,
    }

    if exists or created:

        SAMPLE_CONF = [
            ('BLOG_AUTHOR',  "Your Name"),
            ('BLOG_TITLE', "Demo Site"),
            # ('SITE_URL', "http://getnikola.com/"),
            ('BLOG_EMAIL', "*****@*****.**"),
            ('BLOG_DESCRIPTION', "This is a demo site for Nikola."),
            ('COMMENT_SYSTEM', 'disqus'),
            ('COMMENT_SYSTEM_ID', 'nikolademo'),
            # ('DEFAULT_LANG', "en"),
            # ('THEME', 'bootstrap3'),
        ]

        context = {
            'FILES': get_travis_files_content(full_name, github_token, {}),
            'message': message,
            'SAMPLE_CONF': SAMPLE_CONF
        }

        data['contents'] = render_template('form.html', **context)

    return jsonify(data)
Exemplo n.º 3
0
 def test_should_not_create_existing_repository(self):
     self.assertFalse(
         github_utils.create_new_repository(THIS_REPO, GH_TOKEN)
     )