コード例 #1
0
    def test_methods_in_task_name(self):
        """Ensure the resultant task name contains an encoded form of the
        methods, so that the name is unique.
        """
        from sosbeacon.event.message import get_contact_broadcast_task

        student_key = Mock()
        student_key.urlsafe.return_value = "STUDENTKEY"

        event_key = Mock()
        event_key.urlsafe.return_value = "EVENTKEY"

        message_key = Mock()
        message_key.urlsafe.return_value = "MESSAGEKEY"

        batch_id = "BATCHID"

        contact_one = {
            "name": "Johny Jones",
            "methods": ({"type": "t", "value": "1234567890"}, {"type": "e", "value": "*****@*****.**"}),
        }

        contact_two = {
            "name": "Johny Jones",
            "methods": ({"type": "t", "value": "1234567890"}, {"type": "e", "value": "*****@*****.**"}),
        }

        task_one = get_contact_broadcast_task(event_key, message_key, student_key, contact_one, batch_id)

        task_two = get_contact_broadcast_task(event_key, message_key, student_key, contact_two, batch_id)

        self.assertNotEqual(task_one.name, task_two.name)
コード例 #2
0
    def test_task_params(self):
        """Ensure the resultant task parms contain all info."""
        from sosbeacon.event.message import get_contact_broadcast_task

        student_key = Mock()
        student_key.urlsafe.return_value = "ASTUDENTKEY"

        event_key = Mock()
        event_key.urlsafe.return_value = "ANEVENTKEY"

        message_key = Mock()
        message_key.urlsafe.return_value = "SOMEMESSAGEKEY"

        batch_id = "THEBATCHID"

        contact = {
            "name": "Johny Jones",
            "methods": ({"type": "t", "value": "1234567890"}, {"type": "e", "value": "*****@*****.**"}),
        }

        task = get_contact_broadcast_task(event_key, message_key, student_key, contact, batch_id)

        check_params = {
            "student": "ASTUDENTKEY",
            "event": "ANEVENTKEY",
            "message": "SOMEMESSAGEKEY",
            "batch": "THEBATCHID",
            "contact": json.dumps(contact),
        }
        self.assertEqual(check_params, task.extract_params())
コード例 #3
0
    def test_task_name(self):
        """Ensure the resultant task name contains enough to be unique."""
        from sosbeacon.event.message import get_contact_broadcast_task

        student_key = Mock()
        student_key.urlsafe.return_value = "STUDENTKEY"

        event_key = Mock()
        event_key.urlsafe.return_value = "EVENTKEY"

        message_key = Mock()
        message_key.urlsafe.return_value = "MESSAGEKEY"

        batch_id = "BATCHID"

        contact = {
            "name": "Johny Jones",
            "methods": ({"type": "t", "value": "1234567890"}, {"type": "e", "value": "*****@*****.**"}),
        }

        task = get_contact_broadcast_task(event_key, message_key, student_key, contact, batch_id)

        self.assertIn("STUDENTKEY", task.name)
        self.assertNotIn("EVENTKEY", task.name)
        self.assertIn("MESSAGEKEY", task.name)
        self.assertIn("BATCHID", task.name)
        self.assertNotIn("*****@*****.**", task.name)
コード例 #4
0
    def test_no_methods(self):
        """Ensure no task is returned when there are no contact methods."""
        # raise Exception("Make sure it doesn't send a task if no methods.")
        from sosbeacon.event.message import get_contact_broadcast_task

        student_key = Mock()
        student_key.urlsafe.return_value = "ASTUDENTKEY"

        event_key = Mock()
        event_key.urlsafe.return_value = "SOMEEVENTKEY"

        message_key = Mock()
        message_key.urlsafe.return_value = "SOMEMESSAGEKEY"

        batch_id = "THEBATCHID"

        contact = {"name": "Johny Jones", "methods": ()}

        task = get_contact_broadcast_task(event_key, message_key, student_key, contact, batch_id)

        self.assertIsNone(task)
コード例 #5
0
    def test_missing_methods(self):
        """Ensure there is no exception raised and no task is return when the
        methods key is missing.
        """
        # raise Exception("Make sure it doesn't send a task if no methods.")
        from sosbeacon.event.message import get_contact_broadcast_task

        student_key = Mock()
        student_key.urlsafe.return_value = "ASTUDENTKEY"

        event_key = Mock()
        event_key.urlsafe.return_value = "ANEVENTKEY"

        message_key = Mock()
        message_key.urlsafe.return_value = "SOMEMESSAGEKEY"

        batch_id = "THEBATCHID"

        contact = {"name": "Johny Jones"}

        ret_value = get_contact_broadcast_task(event_key, message_key, student_key, contact, batch_id)

        self.assertIsNone(ret_value)