Ejemplo n.º 1
0
    def test_request_object_type_error(self):
        class NotARequest:
            pass

        with self.assertRaises(TypeError):
            with web_request_context(self.user, NotARequest()):
                pass
Ejemplo n.º 2
0
    def test_plugin_webhook_with_body(self):
        """
        Verify that webhook body_template is correctly used.
        """
        self.clear_worker()
        self.update_headers("test_plugin_webhook_with_body")

        self.webhook.body_template = '{"message": "{{ event }}"}'
        self.webhook.save()

        # Make change to model
        with web_request_context(self.user):
            ExampleModel.objects.create(name="bar", number=100)

        self.wait_on_active_tasks()
        self.assertTrue(
            os.path.exists(
                os.path.join(tempfile.gettempdir(),
                             "test_plugin_webhook_with_body")))
        with open(
                os.path.join(tempfile.gettempdir(),
                             "test_plugin_webhook_with_body"), "r") as f:
            self.assertEqual(json.loads(f.read()), {"message": "created"})
        os.remove(
            os.path.join(tempfile.gettempdir(),
                         "test_plugin_webhook_with_body"))
Ejemplo n.º 3
0
 def test_plugin_webhook_create(self):
     """
     Test that webhooks are correctly triggered by a plugin model create.
     """
     self.clear_worker()
     self.update_headers("test_plugin_webhook_create")
     # Make change to model
     with web_request_context(self.user):
         DummyModel.objects.create(name="foo", number=100)
     self.wait_on_active_tasks()
     self.assertTrue(os.path.exists(os.path.join(tempfile.gettempdir(), "test_plugin_webhook_create")))
     os.remove(os.path.join(tempfile.gettempdir(), "test_plugin_webhook_create"))
Ejemplo n.º 4
0
    def test_change_webhook_enqueued(self):

        with web_request_context(self.user):
            site = Site(name="Test Site 2")
            site.save()

        # Verify that a job was queued for the object creation webhook
        site = Site.objects.get(name="Test Site 2")
        self.assertEqual(self.queue.count, 1)
        job = self.queue.jobs[0]
        self.assertEqual(job.args[0], Webhook.objects.get(type_create=True))
        self.assertEqual(job.args[1]["id"], str(site.pk))
        self.assertEqual(job.args[2], "site")
Ejemplo n.º 5
0
    def test_change_log_created(self):

        with web_request_context(self.user):
            site = Site(name="Test Site 1")
            site.save()

        site = Site.objects.get(name="Test Site 1")
        oc_list = ObjectChange.objects.filter(
            changed_object_type=ContentType.objects.get_for_model(Site),
            changed_object_id=site.pk,
        ).order_by("pk")
        self.assertEqual(len(oc_list), 1)
        self.assertEqual(oc_list[0].changed_object, site)
        self.assertEqual(oc_list[0].action, ObjectChangeActionChoices.ACTION_CREATE)
Ejemplo n.º 6
0
 def _web_request_context(user):
     if request:
         yield request
     else:
         yield web_request_context(user=user)
Ejemplo n.º 7
0
    def test_user_object_type_error(self):

        with self.assertRaises(TypeError):
            with web_request_context("a string is not a user object"):
                pass