<commit_before>from django.test import TestCase
from django.test.client import RequestFactory

import fudge

from ..base.models import EMAIL_URL, User, add_email_from_signup


VERIFIED_PRIMARY_EMAIL = "<EMAIL>"
VERIFIED_EMAIL = "<EMAIL>"
UNVERIFIED_EMAIL = "<EMAIL>"

GITHUB_DATA_WITH_VERIFIED_PRIMARY_EMAIL = [
    {u'verified': True,
     u'email': u'%s' % VERIFIED_PRIMARY_EMAIL,
     u'primary': True}
]
GITHUB_DATA_WITH_VERIFIED_EMAIL = [
    {u'verified': True,
     u'email': u'%s' % VERIFIED_EMAIL,
     u'primary': False}
]
GITHUB_DATA_WITH_UNVERIFIED_EMAIL = [
    {u'verified': False,
     u'email': u'%s' % UNVERIFIED_EMAIL,
     u'primary': False}
]
GITHUB_DATA_WITH_MANY_EMAILS = (GITHUB_DATA_WITH_UNVERIFIED_EMAIL +
                                GITHUB_DATA_WITH_VERIFIED_PRIMARY_EMAIL +
                                GITHUB_DATA_WITH_VERIFIED_EMAIL)


class SignUpReceiverTest(TestCase):
    def setUp(self):
        self.sociallogin = fudge.Fake().has_attr(token='<PASSWORD>')
        self.params = {'access_token': self.sociallogin.token}
        self.sender = User
        self.request = RequestFactory()
        self.user = (fudge.Fake('User')
                     .has_attr(email=None)
                     .expects('save'))
        self.kwargs = {'sociallogin': self.sociallogin}
        self.fake_get = fudge.Fake('requests.get')

    @fudge.patch('requests.get')
    def test_verified_primary_email_from_github_api(self, fake_get):
        (fake_get.expects_call()
                 .with_args(EMAIL_URL, params=self.params)
                 .returns_fake()
                 .expects('json')
                 .returns(
                     GITHUB_DATA_WITH_VERIFIED_PRIMARY_EMAIL))

        add_email_from_signup(self.sender,
                              self.request,
                              self.user,
                              **self.kwargs)
        self.assertEquals(VERIFIED_PRIMARY_EMAIL, self.user.email)

    @fudge.patch('requests.get')
    def test_verified_email_from_github_api(self, fake_get):
        (fake_get.expects_call()
                 .with_args(EMAIL_URL, params=self.params)
                 .returns_fake()
                 .expects('json')
                 .returns(
                     GITHUB_DATA_WITH_VERIFIED_EMAIL))

        add_email_from_signup(self.sender,
                              self.request,
                              self.user,
                              **self.kwargs)
        self.assertEquals(VERIFIED_EMAIL, self.user.email)

    @fudge.patch('requests.get')
    def test_unverified_email_from_github_api(self, fake_get):
        (fake_get.expects_call()
                 .with_args(EMAIL_URL, params=self.params)
                 .returns_fake()
                 .expects('json')
                 .returns(
                     GITHUB_DATA_WITH_UNVERIFIED_EMAIL))

        add_email_from_signup(self.sender,
                              self.request,
                              self.user,
                              **self.kwargs)
        self.assertEquals(None, self.user.email)

    @fudge.patch('requests.get')
    def test_many_emails_from_github_api(self, fake_get):
        (fake_get.expects_call()
                 .with_args(EMAIL_URL, params=self.params)
                 .returns_fake()
                 .expects('json')
                 .returns(
                     GITHUB_DATA_WITH_MANY_EMAILS))

        add_email_from_signup(self.sender,
                              self.request,
                              self.user,
                              **self.kwargs)
        self.assertEquals(VERIFIED_PRIMARY_EMAIL, self.user.email)<commit_msg>test for saving cc account<commit_after>from django.test import TestCase
from django.test.client import RequestFactory

import fudge
from model_mommy import mommy


from ..base.models import EMAIL_URL, User, add_email_from_signup


VERIFIED_PRIMARY_EMAIL = "<EMAIL>"
VERIFIED_EMAIL = "<EMAIL>"
UNVERIFIED_EMAIL = "<EMAIL>"

GITHUB_DATA_WITH_VERIFIED_PRIMARY_EMAIL = [
    {u'verified': True,
     u'email': u'%s' % VERIFIED_PRIMARY_EMAIL,
     u'primary': True}
]
GITHUB_DATA_WITH_VERIFIED_EMAIL = [
    {u'verified': True,
     u'email': u'%s' % VERIFIED_EMAIL,
     u'primary': False}
]
GITHUB_DATA_WITH_UNVERIFIED_EMAIL = [
    {u'verified': False,
     u'email': u'%s' % UNVERIFIED_EMAIL,
     u'primary': False}
]
GITHUB_DATA_WITH_MANY_EMAILS = (GITHUB_DATA_WITH_UNVERIFIED_EMAIL +
                                GITHUB_DATA_WITH_VERIFIED_PRIMARY_EMAIL +
                                GITHUB_DATA_WITH_VERIFIED_EMAIL)


class SignUpReceiverTest(TestCase):
    def setUp(self):
        self.sociallogin = fudge.Fake().has_attr(token='<PASSWORD>')
        self.params = {'access_token': self.sociallogin.token}
        self.sender = User
        self.request = RequestFactory()
        self.user = (fudge.Fake('User')
                     .has_attr(email=None)
                     .expects('save'))
        self.kwargs = {'sociallogin': self.sociallogin}
        self.fake_get = fudge.Fake('requests.get')

    @fudge.patch('requests.get')
    def test_verified_primary_email_from_github_api(self, fake_get):
        (fake_get.expects_call()
                 .with_args(EMAIL_URL, params=self.params)
                 .returns_fake()
                 .expects('json')
                 .returns(
                     GITHUB_DATA_WITH_VERIFIED_PRIMARY_EMAIL))

        add_email_from_signup(self.sender,
                              self.request,
                              self.user,
                              **self.kwargs)
        self.assertEquals(VERIFIED_PRIMARY_EMAIL, self.user.email)

    @fudge.patch('requests.get')
    def test_verified_email_from_github_api(self, fake_get):
        (fake_get.expects_call()
                 .with_args(EMAIL_URL, params=self.params)
                 .returns_fake()
                 .expects('json')
                 .returns(
                     GITHUB_DATA_WITH_VERIFIED_EMAIL))

        add_email_from_signup(self.sender,
                              self.request,
                              self.user,
                              **self.kwargs)
        self.assertEquals(VERIFIED_EMAIL, self.user.email)

    @fudge.patch('requests.get')
    def test_unverified_email_from_github_api(self, fake_get):
        (fake_get.expects_call()
                 .with_args(EMAIL_URL, params=self.params)
                 .returns_fake()
                 .expects('json')
                 .returns(
                     GITHUB_DATA_WITH_UNVERIFIED_EMAIL))

        add_email_from_signup(self.sender,
                              self.request,
                              self.user,
                              **self.kwargs)
        self.assertEquals(None, self.user.email)

    @fudge.patch('requests.get')
    def test_many_emails_from_github_api(self, fake_get):
        (fake_get.expects_call()
                 .with_args(EMAIL_URL, params=self.params)
                 .returns_fake()
                 .expects('json')
                 .returns(
                     GITHUB_DATA_WITH_MANY_EMAILS))

        add_email_from_signup(self.sender,
                              self.request,
                              self.user,
                              **self.kwargs)
        self.assertEquals(VERIFIED_PRIMARY_EMAIL, self.user.email)

    class SignUpReceiverTest(TestCase):

        @fudge.patch('stripe.Customer')
        def test_save_cc_token(self, mock_stripe):
            mock_stripe.provides('create').returns_fake().has_attr(id='dammit')
            user = mommy.make(User)
            user.stripe_account_token = "<PASSWORD>"
            user.save()
{'fraction_non_alphanumeric': 0.09859703819173811, 'fraction_numerical': 0.0, 'mean_word_length': 1.8201465201465201, 'pattern_counts': {'":': 0, '<': 12, '<?xml version=': 0, '>': 12, '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': '2459024', 'n_tokens_mistral': 2428, 'n_tokens_neox': 2344, 'n_words': 299}