<commit_before>import json

from django.test import TestCase

from package.repos.bitbucket import repo_handler as bitbucket_handler
from package.repos.github import repo_handler as github_handler
from package.repos.base_handler import BaseHandler
from package.models import Commit, Package, Category


class BaseBase(TestCase):

    def setUp(self):

        self.category = Category.objects.create(
            title='dummy',
            slug='dummy'
        )
        self.category.save()


class TestBaseHandler(BaseBase):
    def setUp(self):
        super(TestBaseHandler, self).setUp()
        self.package = Package.objects.create(
            title="Django Piston",
            slug="django-piston",
            repo_url="https://bitbucket.org/jespern/django-piston",
            category=self.category
        )

    def test_not_implemented(self):
        # TODO switch the NotImplemented to the other side
        handler = BaseHandler()
        self.assertEquals(NotImplemented, handler.title)
        self.assertEquals(NotImplemented, handler.url)
        self.assertEquals(NotImplemented, handler.repo_regex)
        self.assertEquals(NotImplemented, handler.slug_regex)
        self.assertEquals(NotImplemented, handler.__str__())
        self.assertEquals(NotImplemented, handler.fetch_metadata(self.package))
        self.assertEquals(NotImplemented, handler.fetch_commits(self.package))

    def test_is_other(self):
        handler = BaseHandler()
        self.assertEquals(handler.is_other, False)


class TestBitbucketRepo(TestBaseHandler):
    def setUp(self):
        super(TestBitbucketRepo, self).setUp()
        self.package = Package.objects.create(
            title="Django Registration",
            slug="django-registration",
            repo_url="https://bitbucket.org/ubernostrum/django-registration",
            category=self.category
        )

    def test_fetch_commits(self):
        self.assertEqual(Commit.objects.count(), 0)
        bitbucket_handler.fetch_commits(self.package)
        self.assertNotEqual(Commit.objects.count(), 0)

    def test_fetch_metadata(self):
        package = bitbucket_handler.fetch_metadata(self.package)
        self.assertEqual(package.repo_description,
            "A user registration app for Django.")
        self.assertTrue(package.repo_watchers > 0)
        self.assertTrue(package.repo_forks > 0)
        self.assertEquals(package.participants, "ubernostrum")


class TestGithubRepo(TestBaseHandler):
    def setUp(self):
        super(TestGithubRepo, self).setUp()
        self.package = Package.objects.create(
            title="Django",
            slug="django",
            repo_url="https://github.com/django/django",
            category=self.category
        )

    def test_fetch_commits(self):
        self.assertEqual(Commit.objects.count(), 0)
        github_handler.fetch_commits(self.package)
        #commit_list = "[%s]" % self.package.commits_over_52()
        #commit_list = json.loads(commit_list)
        self.assertTrue(Commit.objects.count() > 0)

    def test_fetch_metadata(self):
        # Currently a live tests that access github
        package = github_handler.fetch_metadata(self.package)
        self.assertEqual(package.repo_description, "The Web framework for perfectionists with deadlines.")
        self.assertTrue(package.repo_watchers > 100)<commit_msg>Change integration to use more often updated bitbucket repo<commit_after>import json

from django.test import TestCase

from package.repos.bitbucket import repo_handler as bitbucket_handler
from package.repos.github import repo_handler as github_handler
from package.repos.base_handler import BaseHandler
from package.models import Commit, Package, Category


class BaseBase(TestCase):

    def setUp(self):

        self.category = Category.objects.create(
            title='dummy',
            slug='dummy'
        )
        self.category.save()


class TestBaseHandler(BaseBase):
    def setUp(self):
        super(TestBaseHandler, self).setUp()
        self.package = Package.objects.create(
            title="Django Piston",
            slug="django-piston",
            repo_url="https://bitbucket.org/jespern/django-piston",
            category=self.category
        )

    def test_not_implemented(self):
        # TODO switch the NotImplemented to the other side
        handler = BaseHandler()
        self.assertEquals(NotImplemented, handler.title)
        self.assertEquals(NotImplemented, handler.url)
        self.assertEquals(NotImplemented, handler.repo_regex)
        self.assertEquals(NotImplemented, handler.slug_regex)
        self.assertEquals(NotImplemented, handler.__str__())
        self.assertEquals(NotImplemented, handler.fetch_metadata(self.package))
        self.assertEquals(NotImplemented, handler.fetch_commits(self.package))

    def test_is_other(self):
        handler = BaseHandler()
        self.assertEquals(handler.is_other, False)


class TestBitbucketRepo(TestBaseHandler):
    def setUp(self):
        super(TestBitbucketRepo, self).setUp()
        self.package = Package.objects.create(
            title="Python packaging guide",
            slug="python-packaging-user-guide",
            repo_url="https://bitbucket.org/pypa/python-packaging-user-guide",
            category=self.category
        )

    def test_fetch_commits(self):
        self.assertEqual(Commit.objects.count(), 0)
        bitbucket_handler.fetch_commits(self.package)
        self.assertNotEqual(Commit.objects.count(), 0)

    def test_fetch_metadata(self):
        package = bitbucket_handler.fetch_metadata(self.package)
        self.assertEqual(package.repo_description,
            "Python Packaging User Guide")
        self.assertTrue(package.repo_watchers > 0)
        self.assertTrue(package.repo_forks > 0)
        self.assertEquals(package.participants, "pypa")


class TestGithubRepo(TestBaseHandler):
    def setUp(self):
        super(TestGithubRepo, self).setUp()
        self.package = Package.objects.create(
            title="Django",
            slug="django",
            repo_url="https://github.com/django/django",
            category=self.category
        )

    def test_fetch_commits(self):
        self.assertEqual(Commit.objects.count(), 0)
        github_handler.fetch_commits(self.package)
        #commit_list = "[%s]" % self.package.commits_over_52()
        #commit_list = json.loads(commit_list)
        self.assertTrue(Commit.objects.count() > 0)

    def test_fetch_metadata(self):
        # Currently a live tests that access github
        package = github_handler.fetch_metadata(self.package)
        self.assertEqual(package.repo_description, "The Web framework for perfectionists with deadlines.")
        self.assertTrue(package.repo_watchers > 100)
{'fraction_non_alphanumeric': 0.09854175872735307, 'fraction_numerical': 0.00324053616143762, 'mean_word_length': 2.996468510888758, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 11, 'https://': 6, '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': '4710135', 'n_tokens_mistral': 1905, 'n_tokens_neox': 1851, 'n_words': 334}