<commit_before># -*- coding: utf-8 -*-
import unittest

from bitbucket.bitbucket import Bitbucket
from bitbucket.tests.private import USERNAME, PASSWORD, CONSUMER_KEY, CONSUMER_SECRET

TEST_REPO_SLUG = 'test_bitbucket_api'

# Store oauth credentials between tests
OAUTH_ACCESS_TOKEN = ''
OAUTH_ACCESS_TOKEN_SECRET = ''

class AuthenticatedBitbucketTest(unittest.TestCase):
    """ Bitbucket test base class for authenticated methods."""
    def setUp(self):
        """Creating a new authenticated Bitbucket..."""

        if USERNAME and PASSWORD:
            self.bb = Bitbucket(USERNAME, PASSWORD)
        elif USERNAME and CONSUMER_KEY and CONSUMER_SECRET:
            global OAUTH_ACCESS_TOKEN, OAUTH_ACCESS_TOKEN_SECRET

            self.bb = Bitbucket(USERNAME)
            
            # First time we need to open up a browser to enter the verifier            
            if not OAUTH_ACCESS_TOKEN and not OAUTH_ACCESS_TOKEN_SECRET:
                self.bb.authorize(CONSUMER_KEY, CONSUMER_SECRET, 'http://localhost/')
                # open a webbrowser and get the token
                import webbrowser
                webbrowser.open(self.bb.url('AUTHENTICATE', token=self.bb.access_token))
                # Copy the verifier field from the URL in the browser into the console
                oauth_verifier = raw_input('Enter verifier from url [oauth_verifier]')
                self.bb.verify(oauth_verifier)
                OAUTH_ACCESS_TOKEN = self.bb.access_token
                OAUTH_ACCESS_TOKEN_SECRET = self.bb.access_token_secret
            else:
                self.bb.authorize(CONSUMER_KEY, CONSUMER_SECRET, 'http://localhost/', OAUTH_ACCESS_TOKEN, OAUTH_ACCESS_TOKEN_SECRET)

        # Create a repository.
        success, result = self.bb.repository.create(TEST_REPO_SLUG, has_issues=True)
        # Save repository's id
        assert success
        self.bb.repo_slug = result[u'slug']

    def tearDown(self):
        """Destroying the Bitbucket..."""<commit_msg>Force user to entered a valid token before starting private tests, in case of oauth authentication.<commit_after># -*- coding: utf-8 -*-
import unittest
import webbrowser

from bitbucket.bitbucket import Bitbucket
from bitbucket.tests.private import USERNAME, PASSWORD, CONSUMER_KEY, CONSUMER_SECRET

TEST_REPO_SLUG = 'test_bitbucket_api'

# Store oauth credentials between tests
OAUTH_ACCESS_TOKEN = ''
OAUTH_ACCESS_TOKEN_SECRET = ''


class AuthenticatedBitbucketTest(unittest.TestCase):
    """ Bitbucket test base class for authenticated methods."""
    def setUp(self):
        """Creating a new authenticated Bitbucket..."""
        if USERNAME and PASSWORD:
            self.bb = Bitbucket(USERNAME, PASSWORD)
        elif USERNAME and CONSUMER_KEY and CONSUMER_SECRET:
            # Try Oauth authentication
            global OAUTH_ACCESS_TOKEN, OAUTH_ACCESS_TOKEN_SECRET
            self.bb = Bitbucket(USERNAME)

            # First time we need to open up a browser to enter the verifier
            if not OAUTH_ACCESS_TOKEN and not OAUTH_ACCESS_TOKEN_SECRET:
                self.bb.authorize(CONSUMER_KEY, CONSUMER_SECRET, 'http://localhost/')
                # open a webbrowser and get the token
                webbrowser.open(self.bb.url('AUTHENTICATE', token=self.bb.access_token))
                # Copy the verifier field from the URL in the browser into the console
                token_is_valid = False
                while not token_is_valid:
                    # Ensure a valid oauth_verifier before starting tests
                    oauth_verifier = raw_input('Enter verifier from url [oauth_verifier]')
                    token_is_valid = bool(oauth_verifier and self.bb.verify(oauth_verifier)[0])
                    if not token_is_valid:
                        print('Invalid oauth_verifier, please try again or quit with CONTROL-C.')
                OAUTH_ACCESS_TOKEN = self.bb.access_token
                OAUTH_ACCESS_TOKEN_SECRET = self.bb.access_token_secret
            else:
                self.bb.authorize(CONSUMER_KEY, CONSUMER_SECRET, 'http://localhost/', OAUTH_ACCESS_TOKEN, OAUTH_ACCESS_TOKEN_SECRET)

        # Create a repository.
        success, result = self.bb.repository.create(TEST_REPO_SLUG, has_issues=True)
        # Save repository's id
        assert success
        self.bb.repo_slug = result[u'slug']

    def tearDown(self):
        """Destroying the Bitbucket..."""
{'fraction_non_alphanumeric': 0.0746335963923337, 'fraction_numerical': 0.0006764374295377678, 'mean_word_length': 2.5831987075928917, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3203347', 'n_tokens_mistral': 1326, 'n_tokens_neox': 1289, 'n_words': 326}