<reponame>gogasca/news_ml
import unittest
import json
from .validator import check_campaign, check_person, check_email_addresses, \
    check_report, check_translation, check_limit


class TestValidator(unittest.TestCase):
    """Our basic test class."""

    def test_campaign(self):
        """

        :return:
        """
        # Valid request
        self.assertTrue(check_campaign(
            json_request=json.loads("""{
                "provider": "techmeme",
                "report": {
                    "email": "<EMAIL>"
                },
                "translate": {
                    "language": "es"
                }}""")))
        # Valid campaign
        self.assertTrue(check_campaign(
            json_request=json.loads("""{
                "provider": "techmeme",
                "report": {
                    "email": "<EMAIL>"
                }}""")))
        # Valid campaign with limit
        self.assertTrue(check_campaign(
            json_request=json.loads("""{
                        "provider": "techmeme",
                        "limit": 8,
                        "report": {
                            "email": "<EMAIL>"
                        }}""")))
        # Valid campaign with report
        self.assertTrue(check_campaign(
            json_request=json.loads("""{
                                "provider": "techmeme",                                
                                "report": {
                                    "email": "<EMAIL>"
                                }}""")))
        # Invalid language.
        self.assertFalse(check_campaign(
            json_request=json.loads("""{
                "provider": "techmeme",
                "report": {
                    "email": "<EMAIL>"
                },
                "translate": {
                    "language": "en"
                }}""")))

        # Invalid campaign with invalid limit number
        self.assertTrue(check_campaign(
            json_request=json.loads("""{
                                "provider": "techmeme",
                                "limit": 0,
                                "report": {
                                    "email": "<EMAIL>"
                                }}""")))

    def test_person(self):
        """

        :return:
        """
        self.assertTrue(check_person(
            json_request=json.loads("""{"name": "<NAME>"}""")))

    def test_email(self):
        """
        The actual test.
        Any method which starts with ``test_`` will considered as a test case.
        """
        self.assertTrue(check_email_addresses('<EMAIL>'))
        self.assertTrue(check_email_addresses(
            '<EMAIL>;<EMAIL>'))
        self.assertTrue(check_email_addresses('<EMAIL>;'))
        self.assertTrue(
            check_email_addresses(';<EMAIL>;'))
        self.assertFalse(
            check_email_addresses('gon<EMAIL>', check_mx=True))

    def test_report(self):
        """

        :return:
        """
        self.assertTrue(check_report(
            json.loads("""{"report": { "email": "<EMAIL>"}}""")))
        self.assertFalse(check_report(
            json.loads("""{"report": { "email": ""}}""")))
        self.assertFalse(
            check_report(json.loads("""{"report": { }}""")))

    def test_language(self):
        """

        :return:
        """
        self.assertTrue(check_translation(
            json.loads("""{"translate": {"language": "es"}}""")))
        self.assertTrue(check_translation(
            json.loads("""{"translate": {"language": "fr"}}""")))
        self.assertTrue(check_translation(
            json.loads("""{"translate": {"language": "de"}}""")))
        self.assertFalse(check_translation(
            json.loads("""{"translate": {"language": "xx"}}""")))
        self.assertFalse(check_translation(
            json.loads("""{"translate": {"language": 1}}""")))

    def test_limit(self):
        self.assertTrue(check_limit(
            json.loads("""{"limit": 5}""")))
        self.assertTrue(check_limit(
            json.loads("""{"limit": 1000000}""")))
        self.assertTrue(check_limit(
            json.loads("""{"limit": 1}""")))
        self.assertFalse(check_limit(
            json.loads("""{"limit": -1}""")))
        self.assertFalse(check_limit(
            json.loads("""{"limit": 0}""")))
        self.assertFalse(check_limit(
            json.loads("""{"limits": 1}""")))


if __name__ == '__main__':
    unittest.main()

import unittest
import json
from .validator import check_campaign, check_person, check_email_addresses, \
    check_report, check_translation, check_limit


class TestValidator(unittest.TestCase):
    """Our basic test class."""

    def test_campaign(self):
        """

        :return:
        """
        # Valid request
        self.assertTrue(check_campaign(
            json_request=json.loads("""{
                "provider": "techmeme",
                "report": {
                    "email": "<EMAIL>"
                },
                "translate": {
                    "language": "es"
                }}""")))
        # Valid campaign
        self.assertTrue(check_campaign(
            json_request=json.loads("""{
                "provider": "techmeme",
                "report": {
                    "email": "<EMAIL>"
                }}""")))
        # Valid campaign with limit
        self.assertTrue(check_campaign(
            json_request=json.loads("""{
                        "provider": "techmeme",
                        "limit": 8,
                        "report": {
                            "email": "<EMAIL>"
                        }}""")))
        # Valid campaign with report
        self.assertTrue(check_campaign(
            json_request=json.loads("""{
                                "provider": "techmeme",                                
                                "report": {
                                    "email": "<EMAIL>"
                                }}""")))
        # Invalid language.
        self.assertFalse(check_campaign(
            json_request=json.loads("""{
                "provider": "techmeme",
                "report": {
                    "email": "<EMAIL>"
                },
                "translate": {
                    "language": "en"
                }}""")))

        # Invalid campaign with invalid limit number
        self.assertTrue(check_campaign(
            json_request=json.loads("""{
                                "provider": "techmeme",
                                "limit": 0,
                                "report": {
                                    "email": "<EMAIL>"
                                }}""")))

    def test_person(self):
        """

        :return:
        """
        self.assertTrue(check_person(
            json_request=json.loads("""{"name": "<NAME>"}""")))

    def test_email(self):
        """
        The actual test.
        Any method which starts with ``test_`` will considered as a test case.
        """
        self.assertTrue(check_email_addresses('<EMAIL>'))
        self.assertTrue(check_email_addresses(
            '<EMAIL>;<EMAIL>'))
        self.assertTrue(check_email_addresses('<EMAIL>;'))
        self.assertTrue(
            check_email_addresses(';<EMAIL>;'))
        self.assertFalse(
            check_email_addresses('gon<EMAIL>', check_mx=True))

    def test_report(self):
        """

        :return:
        """
        self.assertTrue(check_report(
            json.loads("""{"report": { "email": "<EMAIL>"}}""")))
        self.assertFalse(check_report(
            json.loads("""{"report": { "email": ""}}""")))
        self.assertFalse(
            check_report(json.loads("""{"report": { }}""")))

    def test_language(self):
        """

        :return:
        """
        self.assertTrue(check_translation(
            json.loads("""{"translate": {"language": "es"}}""")))
        self.assertTrue(check_translation(
            json.loads("""{"translate": {"language": "fr"}}""")))
        self.assertTrue(check_translation(
            json.loads("""{"translate": {"language": "de"}}""")))
        self.assertFalse(check_translation(
            json.loads("""{"translate": {"language": "xx"}}""")))
        self.assertFalse(check_translation(
            json.loads("""{"translate": {"language": 1}}""")))

    def test_limit(self):
        self.assertTrue(check_limit(
            json.loads("""{"limit": 5}""")))
        self.assertTrue(check_limit(
            json.loads("""{"limit": 1000000}""")))
        self.assertTrue(check_limit(
            json.loads("""{"limit": 1}""")))
        self.assertFalse(check_limit(
            json.loads("""{"limit": -1}""")))
        self.assertFalse(check_limit(
            json.loads("""{"limit": 0}""")))
        self.assertFalse(check_limit(
            json.loads("""{"limits": 1}""")))


if __name__ == '__main__':
    unittest.main()
Our basic test class. :return: # Valid request {                 "provider": "techmeme",                 "report": {                     "email": "<EMAIL>"                 },                 "translate": {                     "language": "es"                 }} # Valid campaign {                 "provider": "techmeme",                 "report": {                     "email": "<EMAIL>"                 }} # Valid campaign with limit {                         "provider": "techmeme",                         "limit": 8,                         "report": {                             "email": "<EMAIL>"                         }} # Valid campaign with report {                                 "provider": "techmeme",                                                                 "report": {                                     "email": "<EMAIL>"                                 }} # Invalid language. {                 "provider": "techmeme",                 "report": {                     "email": "<EMAIL>"                 },                 "translate": {                     "language": "en"                 }} # Invalid campaign with invalid limit number {                                 "provider": "techmeme",                                 "limit": 0,                                 "report": {                                     "email": "<EMAIL>"                                 }} :return: {"name": "<NAME>"} The actual test.         Any method which starts with ``test_`` will considered as a test case. :return: {"report": { "email": "<EMAIL>"}} {"report": { "email": ""}} {"report": { }} :return: {"translate": {"language": "es"}} {"translate": {"language": "fr"}} {"translate": {"language": "de"}} {"translate": {"language": "xx"}} {"translate": {"language": 1}} {"limit": 5} {"limit": 1000000} {"limit": 1} {"limit": -1} {"limit": 0} {"limits": 1}