<commit_before>from mock import patch
from all_voice.models import AlexaSkill
from all_voice.models.all_voice import AllVoice

from tests.base import TestBaseIntent


class TestSkillFactory(TestBaseIntent):

    def setUp(self):
        class MockClass(AllVoice):
            pass
        self.MockClass = MockClass

    def test_get_skill_returns_alexa(self):
        event = self.get_mock_alexa_event()

        skill = self.MockClass(event)
        self.assertIn("convert_to_ssml", dir(skill), "Skill did not extent Alexa")
        self.assertNotIn("DEFAULT_CONTEXT", dir(skill), "Skill extended google.")

    def test_get_skill_returns_google_home(self):
        event = self.get_mock_google_home_event()

        skill = self.MockClass(event)

        self.assertIn("DEFAULT_CONTEXT", dir(skill), "Skill did not extent Google")
        self.assertNotIn("convert_to_ssml", dir(skill), "Skill extented Alexa")

    def test_get_skill_accesses_parent_class(self):
        event = self.get_mock_alexa_event(intent="LaunchRequest")

        skill = self.MockClass(event)
        self.assertEqual(skill.intent_name, "LaunchRequest")

        response = skill.response()
        self.assertTrue(response.get("response"), "No Response returned")

    @patch.object(AlexaSkill, "CancelIntent")
    def test_all_voice_calls_parent(self, cancel_mock):
        event = self.get_mock_alexa_event(intent="CancelIntent")
        cancel_mock.return_value = {"test": 1}

        skill = self.MockClass(event)
        response = skill.CancelIntent()

        self.assertEqual(response.get("test"), 1)
        cancel_mock.assert_called_once()

    @patch.object(AlexaSkill, "CancelIntent")
    def test_all_voice_calls_super(self, cancel_mock):
        event = self.get_mock_alexa_event(intent="CancelIntent")
        cancel_mock.return_value = {"test": 1}

        class MockClass(AllVoice):
            def CancelIntent(self):
                return super(AllVoice, self).CancelIntent()

        skill = MockClass(event)
        response = skill.CancelIntent()

        self.assertEqual(response.get("test"), 1)
        cancel_mock.assert_called_once()

    @patch.object(AlexaSkill, "CancelIntent")
    def test_all_voice_override(self, cancel_mock):
        event = self.get_mock_alexa_event(intent="CancelIntent")
        cancel_mock.return_value = {"test": 1}

        class MockClass(AllVoice):
            def CancelIntent(self):
                return {"test": 2}

        skill = MockClass(event)
        response = skill.CancelIntent()

        self.assertEqual(response.get("test"), 2)
        cancel_mock.assert_not_called()
<commit_msg>name update.<commit_after>from mock import patch
from all_voice.models import AlexaSkill
from all_voice.models.all_skill import AllVoice

from tests.base import TestBaseIntent


class TestSkillFactory(TestBaseIntent):

    def setUp(self):
        class MockClass(AllVoice):
            pass
        self.MockClass = MockClass

    def test_get_skill_returns_alexa(self):
        event = self.get_mock_alexa_event()

        skill = self.MockClass(event)
        self.assertIn("convert_to_ssml", dir(skill), "Skill did not extent Alexa")
        self.assertNotIn("DEFAULT_CONTEXT", dir(skill), "Skill extended google.")

    def test_get_skill_returns_google_home(self):
        event = self.get_mock_google_home_event()

        skill = self.MockClass(event)

        self.assertIn("DEFAULT_CONTEXT", dir(skill), "Skill did not extent Google")
        self.assertNotIn("convert_to_ssml", dir(skill), "Skill extented Alexa")

    def test_get_skill_accesses_parent_class(self):
        event = self.get_mock_alexa_event(intent="LaunchRequest")

        skill = self.MockClass(event)
        self.assertEqual(skill.intent_name, "LaunchRequest")

        response = skill.response()
        self.assertTrue(response.get("response"), "No Response returned")

    @patch.object(AlexaSkill, "CancelIntent")
    def test_all_voice_calls_parent(self, cancel_mock):
        event = self.get_mock_alexa_event(intent="CancelIntent")
        cancel_mock.return_value = {"test": 1}

        skill = self.MockClass(event)
        response = skill.CancelIntent()

        self.assertEqual(response.get("test"), 1)
        cancel_mock.assert_called_once()

    @patch.object(AlexaSkill, "CancelIntent")
    def test_all_voice_calls_super(self, cancel_mock):
        event = self.get_mock_alexa_event(intent="CancelIntent")
        cancel_mock.return_value = {"test": 1}

        class MockClass(AllVoice):
            def CancelIntent(self):
                return super(AllVoice, self).CancelIntent()

        skill = MockClass(event)
        response = skill.CancelIntent()

        self.assertEqual(response.get("test"), 1)
        cancel_mock.assert_called_once()

    @patch.object(AlexaSkill, "CancelIntent")
    def test_all_voice_override(self, cancel_mock):
        event = self.get_mock_alexa_event(intent="CancelIntent")
        cancel_mock.return_value = {"test": 1}

        class MockClass(AllVoice):
            def CancelIntent(self):
                return {"test": 2}

        skill = MockClass(event)
        response = skill.CancelIntent()

        self.assertEqual(response.get("test"), 2)
        cancel_mock.assert_not_called()

{'fraction_non_alphanumeric': 0.10525317655983311, 'fraction_numerical': 0.0026550350843921864, 'mean_word_length': 3.2773722627737225, 'pattern_counts': {'":': 8, '<': 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': '3925725', 'n_tokens_mistral': 1612, 'n_tokens_neox': 1562, 'n_words': 281}