<commit_before>import sys
import test_helper

if sys.version_info < (2, 7):
    import unittest2 as unittest
else:
    import unittest

from authy import AuthyException
from authy.api import AuthyApiClient
from authy.api.resources import Phones
from authy.api.resources import Phone


class PhonesTest(unittest.TestCase):

    def setUp(self):
        self.api = AuthyApiClient(test_helper.API_KEY, test_helper.API_URL)
        self.phones = Phones(test_helper.API_URL, test_helper.API_KEY)
        self.phone_number = test_helper.PHONE_NUMBER
        self.country_code = test_helper.COUNTRY_CODE

    def test_phones(self):
        self.assertIsInstance(self.api.phones, Phones)

    def test_verification_start_without_via(self):
        phone = self.phones.verification_start(self.phone_number, self.country_code,'sms')
        self.assertTrue(phone.ok(), msg="errors: {0}".format(phone.errors()))
        self.assertRegex(phone['message'], 'Text message sent')

    def test_verification_start(self):
        phone = self.phones.verification_start(self.phone_number, self.country_code)
        self.assertTrue(phone.ok(), msg="errors: {0}".format(phone.errors()))
        self.assertRegex(phone['message'], 'Text message sent')

    def test_verification_check_incorrect_code(self):
        phone = self.phones.verification_check(self.phone_number, self.country_code, '1234')
        self.assertFalse(phone.ok(), msg="errors: {0}".format(phone.errors()))
        self.assertRegex(phone.errors()['message'], 'Verification code is incorrect.')

    def test_verification_check(self):
        self.phones.verification_start(self.phone_number, self.country_code)
        phone = self.phones.verification_check(self.phone_number, self.country_code, '0000')
        self.assertTrue(phone.ok(), msg="errors: {0}".format(phone.errors()))
        self.assertRegex(phone['message'], 'Verification code is correct')
<commit_msg>Use mocks to validate verification_check<commit_after>import sys
import test_helper

if sys.version_info < (2, 7):
    import unittest2 as unittest
else:
    import unittest

from unittest.mock import patch, Mock
from authy import AuthyException
from authy.api import AuthyApiClient
from authy.api.resources import Phones
from authy.api.resources import Phone


class PhonesTest(unittest.TestCase):

    def setUp(self):
        self.api = AuthyApiClient(test_helper.API_KEY, test_helper.API_URL)
        self.phones = Phones(test_helper.API_URL, test_helper.API_KEY)
        self.phone_number = test_helper.PHONE_NUMBER
        self.country_code = test_helper.COUNTRY_CODE

    def test_phones(self):
        self.assertIsInstance(self.api.phones, Phones)

    def test_verification_start_without_via(self):
        phone = self.phones.verification_start(self.phone_number, self.country_code,'sms')
        self.assertTrue(phone.ok(), msg="errors: {0}".format(phone.errors()))
        self.assertRegex(phone['message'], 'Text message sent')

    def test_verification_start(self):
        phone = self.phones.verification_start(self.phone_number, self.country_code)
        self.assertTrue(phone.ok(), msg="errors: {0}".format(phone.errors()))
        self.assertRegex(phone['message'], 'Text message sent')

    @patch('authy.api.resources.Phones')
    def test_verification_check_incorrect_code(self, MockPhones):
        phones = MockPhones()
        phones.verification_check.side_effect = lambda x,y,z: {'0000': 'Verification code is correct.', '1234': 'Verification code is incorrect.'}[z]

        response = phones.verification_check(self.phone_number, self.country_code, '1234')
        self.assertEqual(response, 'Verification code is incorrect.')


    @patch('authy.api.resources.Phones')
    def test_verification_check(self, MockPhones):
        phones = MockPhones()
        phones.verification_check.side_effect = lambda x,y,z: {'0000': 'Verification code is correct.', '1234': 'Verification code is incorrect.'}[z]

        response = phones.verification_check(self.phone_number, self.country_code, '0000')
        self.assertEqual(response, 'Verification code is correct.')

{'fraction_non_alphanumeric': 0.11594555177442878, 'fraction_numerical': 0.0106951871657754, 'mean_word_length': 4.2756410256410255, 'pattern_counts': {'":': 0, '<': 5, '<?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': '2931575', 'n_tokens_mistral': 1273, 'n_tokens_neox': 1234, 'n_words': 241}