<commit_before>import fudge

from django.conf import settings
from django.test import TestCase

from model_mommy import mommy

from ..models import Issue, Bid, Claim, Vote
from ..views import BidStatusView, ClaimStatusView
from ..views import BidList, ClaimList, VoteList


class BidStatusTestCase(TestCase):
    def setUp(self):
        self.view = BidStatusView()
        self.url = 'http://github.com/codesy/codesy/issues/37'
        self.issue = mommy.make(Issue, url=self.url)
        self.user1 = mommy.make(settings.AUTH_USER_MODEL,
                                email='<EMAIL>')
        self.bid1 = mommy.make(
            Bid, user=self.user1, url=self.url, issue=self.issue)

    def test_get_by_url_returns_context(self):
        self.view.request = (fudge.Fake()
                             .has_attr(GET={'url': self.url})
                             .has_attr(user=self.user1))
        context = self.view.get_context_data()
        self.assertEqual(self.bid1, context['bid'])

    @fudge.patch('auctions.views.messages')
    def test_post_new_offer(self, mock_messages):
        mock_messages.is_a_stub()
        self.view.request = (fudge.Fake().has_attr(
            POST={
                'url': self.url,
                'ask': 0,
                'offer': 44,
            })
            .has_attr(user=self.user1))
        self.view.post()
        retreive_bid = Bid.objects.get(pk=self.bid1.id)
        self.assertEqual(retreive_bid.offer, 44)


class ClaimStatusTestCase(TestCase):
    def setUp(self):
        self.view = ClaimStatusView()
        self.url = 'http://github.com/codesy/codesy/issues/37'
        self.issue = mommy.make(Issue, url=self.url)
        self.user1 = mommy.make(settings.AUTH_USER_MODEL,
                                email='<EMAIL>')
        self.user2 = mommy.make(settings.AUTH_USER_MODEL,
                                email='<EMAIL>')

        self.claim = mommy.make(Claim, user=self.user1, issue=self.issue)

    def payout_post(self, user):
        self.view.request = (fudge.Fake()
                             .has_attr(user=user))
        self.view.kwargs = {'pk': self.claim.id}
        response = self.view.post(self.view.request)
        self.assertTrue(response)

    def test_get_by_id_returns_context(self):
        self.view.request = (fudge.Fake()
                             .has_attr(user=self.user1))
        self.view.kwargs = {'pk': self.claim.id}
        context = self.view.get_context_data()
        self.assertEqual(self.claim, context['claim'])

    def test_get_by_non_claimaint_returns_context(self):
        self.view.request = (fudge.Fake()
                             .has_attr(user=self.user2))
        self.view.kwargs = {'pk': self.claim.id}
        context = self.view.get_context_data()
        self.assertEqual(self.claim, context['claim'])

    @fudge.patch('auctions.models.Claim.payout_request')
    @fudge.patch('auctions.views.messages')
    def test_post_success_by_claimaint(self, mock_paypal, mock_messages):
        mock_paypal.is_callable().returns(True)
        mock_messages.expects('success')
        self.payout_post(self.user1)

    @fudge.patch('auctions.models.Claim.payout_request')
    @fudge.patch('auctions.views.messages')
    def test_post_fail_by_claimaint(self, mock_paypal, mock_messages):
        mock_paypal.is_callable().returns(False)
        mock_messages.expects('error')
        self.payout_post(self.user1)

    @fudge.patch('auctions.models.Claim.payout_request')
    @fudge.patch('auctions.views.messages')
    def test_post_exception_by_claimaint(self, mock_paypal, mock_messages):
        mock_paypal.is_callable().raises(Exception('Paypal error'))
        mock_messages.expects('error')
        self.payout_post(self.user1)

    @fudge.patch('auctions.views.messages')
    def test_post_fail_by_other_user(self, mock_messages):
        mock_messages.expects('error')
        self.payout_post(self.user2)

<commit_msg>comment out payout test while manually paying out claims<commit_after>import fudge

from django.conf import settings
from django.test import TestCase

from model_mommy import mommy

from ..models import Issue, Bid, Claim, Vote
from ..views import BidStatusView, ClaimStatusView
from ..views import BidList, ClaimList, VoteList


class BidStatusTestCase(TestCase):
    def setUp(self):
        self.view = BidStatusView()
        self.url = 'http://github.com/codesy/codesy/issues/37'
        self.issue = mommy.make(Issue, url=self.url)
        self.user1 = mommy.make(settings.AUTH_USER_MODEL,
                                email='<EMAIL>')
        self.bid1 = mommy.make(
            Bid, user=self.user1, url=self.url, issue=self.issue)

    def test_get_by_url_returns_context(self):
        self.view.request = (fudge.Fake()
                             .has_attr(GET={'url': self.url})
                             .has_attr(user=self.user1))
        context = self.view.get_context_data()
        self.assertEqual(self.bid1, context['bid'])

    @fudge.patch('auctions.views.messages')
    def test_post_new_offer(self, mock_messages):
        mock_messages.is_a_stub()
        self.view.request = (fudge.Fake().has_attr(
            POST={
                'url': self.url,
                'ask': 0,
                'offer': 44,
            })
            .has_attr(user=self.user1))
        self.view.post()
        retreive_bid = Bid.objects.get(pk=self.bid1.id)
        self.assertEqual(retreive_bid.offer, 44)


class ClaimStatusTestCase(TestCase):
    def setUp(self):
        self.view = ClaimStatusView()
        self.url = 'http://github.com/codesy/codesy/issues/37'
        self.issue = mommy.make(Issue, url=self.url)
        self.user1 = mommy.make(settings.AUTH_USER_MODEL,
                                email='<EMAIL>')
        self.user2 = mommy.make(settings.AUTH_USER_MODEL,
                                email='<EMAIL>')

        self.claim = mommy.make(Claim, user=self.user1, issue=self.issue)

    def payout_post(self, user):
        self.view.request = (fudge.Fake()
                             .has_attr(user=user))
        self.view.kwargs = {'pk': self.claim.id}
        response = self.view.post(self.view.request)
        self.assertTrue(response)

    def test_get_by_id_returns_context(self):
        self.view.request = (fudge.Fake()
                             .has_attr(user=self.user1))
        self.view.kwargs = {'pk': self.claim.id}
        context = self.view.get_context_data()
        self.assertEqual(self.claim, context['claim'])

    def test_get_by_non_claimaint_returns_context(self):
        self.view.request = (fudge.Fake()
                             .has_attr(user=self.user2))
        self.view.kwargs = {'pk': self.claim.id}
        context = self.view.get_context_data()
        self.assertEqual(self.claim, context['claim'])

    # @fudge.patch('auctions.models.Claim.payout_request')
    # @fudge.patch('auctions.views.messages')
    # def test_post_success_by_claimaint(self, mock_paypal, mock_messages):
    #     mock_paypal.is_callable().returns(True)
    #     mock_messages.expects('success')
    #     self.payout_post(self.user1)

    @fudge.patch('auctions.models.Claim.payout_request')
    @fudge.patch('auctions.views.messages')
    def test_post_fail_by_claimaint(self, mock_paypal, mock_messages):
        mock_paypal.is_callable().returns(False)
        mock_messages.expects('error')
        self.payout_post(self.user1)

    @fudge.patch('auctions.models.Claim.payout_request')
    @fudge.patch('auctions.views.messages')
    def test_post_exception_by_claimaint(self, mock_paypal, mock_messages):
        mock_paypal.is_callable().raises(Exception('Paypal error'))
        mock_messages.expects('error')
        self.payout_post(self.user1)

    @fudge.patch('auctions.views.messages')
    def test_post_fail_by_other_user(self, mock_messages):
        mock_messages.expects('error')
        self.payout_post(self.user2)


{'fraction_non_alphanumeric': 0.12482732638452844, 'fraction_numerical': 0.006279040562602034, 'mean_word_length': 2.5099162626707803, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, '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': '788060', 'n_tokens_mistral': 2603, 'n_tokens_neox': 2529, 'n_words': 356}