def test_task_async(self):
        with self.patch_push() as push:
            with patch_auth():
                tasks.CalculatePriceTask().delay(price=30, quantity=4, discount=0.2)

        expected_call = dict(
            queue_name="tasks",
            url="http://localhost:8080/tasks/CalculatePriceTask",
            payload=json.dumps({"price": 30, "quantity": 4, "discount": 0.2}),
        )
        push.assert_called_once_with(**expected_call)
    def test_task_async_only_once(self):
        with self.patch_push() as push:
            with patch_auth():
                tasks.FailMiserablyTask().delay(magic_number=666)

        expected_call = dict(
            task_name="FailMiserablyTask",
            queue_name="tasks",
            url="http://localhost:8080/tasks/FailMiserablyTask",
            payload=json.dumps({"magic_number": 666}),
            unique=False,
        )
        push.assert_called_once_with(**expected_call)
    def test_task_async_reused_queue(self):
        effects = [DeletedRecently("Queue tasks"), None]
        with self.patch_push(side_effect=effects) as push:
            with patch_auth():
                tasks.CalculatePriceTask().delay(price=30, quantity=4, discount=0.2)

        expected_call = dict(
            queue_name="tasks",
            url="http://localhost:8080/tasks/CalculatePriceTask",
            payload=json.dumps({"price": 30, "quantity": 4, "discount": 0.2}),
        )
        expected_backup_call = expected_call
        expected_backup_call["queue_name"] += "--temp"

        self.assertEqual(2, push.call_count)
        push.assert_any_call(**expected_call)
        push.assert_called_with(**expected_backup_call)
 def _assert_command(
     self,
     command: str,
     params: List[str] = None,
     expected_schedule_calls: int = 0,
     expected_subscribe_calls: int = 0,
     expected_output: str = None,
 ):
     out = StringIO()
     with patch_auth():
         with self.patch_schedule() as schedule:
             with self.patch_subscribe() as subscribe:
                 call_params = params or []
                 call_command(command,
                              *call_params,
                              no_color=True,
                              stdout=out)
     self.assertEqual(expected_schedule_calls, schedule.call_count)
     self.assertEqual(expected_subscribe_calls, subscribe.call_count)
     if expected_output:
         self.assertEqual(expected_output, out.getvalue())
 def test_task_eager(self):
     with self.settings(EAGER_TASKS=True):
         with patch_auth():
             response = tasks.CalculatePriceTask().delay(price=30, quantity=4, discount=0.2)
     self.assertGreater(response, 0)
Example #6
0
 def test_mocked_auth(self):
     with patch_auth():
         self.get_client()