All of lore.kernel.org
 help / color / mirror / Atom feed
From: Thomas Petazzoni via buildroot <buildroot@buildroot.org>
To: Marcus Hoffmann via buildroot <buildroot@buildroot.org>
Cc: Marcus Hoffmann <buildroot@bubu1.eu>,
	James Hilliard <james.hilliard1@gmail.com>,
	Asaf Kahlon <asafka7@gmail.com>
Subject: Re: [Buildroot] [PATCH 2/2] package/python-whitenoise: new package
Date: Wed, 5 Feb 2025 11:41:20 +0100	[thread overview]
Message-ID: <20250205114120.758c9da7@windsurf> (raw)
In-Reply-To: <20240216131815.318315-2-buildroot@bubu1.eu>

Hello Marcus,

Sorry for the huge delay in getting back to you.

On Fri, 16 Feb 2024 14:18:14 +0100
Marcus Hoffmann via buildroot <buildroot@buildroot.org> wrote:

> The test is using the django integration of whitenoise as it's the most
> common setup and allows to model the test case after the django one as
> well.
> 
> The setup we need to do is a bit more complicated though and follows
> the whitenoise getting started documentation [1].
> 
> We then request a .css file from the django admin app that is enabled
> by default in template project. Due to running django's development
> server with --nostatic we ensure that static file handling is taken over
> by whitenoise.
> 
> [1] https://whitenoise.readthedocs.io/en/stable/django.html
> 
> Signed-off-by: Marcus Hoffmann <buildroot@bubu1.eu>

This causes some flake8 warnings, which I'm not sure how to fix. See
below.

> diff --git a/support/testing/tests/package/test_python_django.py b/support/testing/tests/package/test_python_django.py
> index 0973467a2a..ac1dc81359 100644
> --- a/support/testing/tests/package/test_python_django.py
> +++ b/support/testing/tests/package/test_python_django.py
> @@ -36,6 +36,7 @@ class TestPythonPy3Django(TestPythonDjango):
>      config = TestPythonDjango.config + \
>          """
>          BR2_PACKAGE_PYTHON3=y
> +        BR2_PACKAGE_PYTHON3_PY_PYC=y
>          BR2_PACKAGE_PYTHON_DJANGO=y
>          BR2_PACKAGE_PYTHON3_SQLITE=y
>          """

When resending, please drop this chunk.

> diff --git a/support/testing/tests/package/test_python_whitenoise.py b/support/testing/tests/package/test_python_whitenoise.py
> new file mode 100644
> index 0000000000..ff9bcf5ee7
> --- /dev/null
> +++ b/support/testing/tests/package/test_python_whitenoise.py
> @@ -0,0 +1,41 @@
> +import time
> +
> +from tests.package.test_python import TestPythonPackageBase
> +
> +
> +class TestPythonPy3Whitenoise(TestPythonPackageBase):
> +    __test__ = True
> +    config = TestPythonPackageBase.config + \
> +        """
> +        BR2_PACKAGE_PYTHON3=y
> +        BR2_PACKAGE_PYTHON_DJANGO=y
> +        BR2_PACKAGE_PYTHON_WHITENOISE=y
> +        BR2_PACKAGE_PYTHON3_SQLITE=y
> +        """
> +
> +    def test_run(self):
> +        self.login()
> +        timeout = 35
> +
> +        cmd = "cd /opt && /usr/bin/django-admin startproject testsite"
> +        self.assertRunOk(cmd, timeout=timeout)
> +        # STATIC_ROOT needs to be set for 'collectstatic' to work.
> +        self.emulator.run("echo 'STATIC_ROOT = BASE_DIR / \"staticfiles\"' >> /opt/testsite/testsite/settings.py")
> +        cmd = "cd /opt/testsite && " + self.interpreter + " ./manage.py collectstatic"
> +        self.assertRunOk(cmd, timeout=timeout)
> +        # whitenoise docs say it needs to be added directly after SecurityMiddleware, so we do this here with sed.
> +        cmd = """sed -i -e /django.middleware.security.SecurityMiddleware/a\ \\"whitenoise.middleware.WhiteNoiseMiddleware\\", /opt/testsite/testsite/settings.py"""

flake8 doesn't like this:

support/testing/tests/package/test_python_whitenoise.py:27:76: W605 invalid escape sequence '\ '
support/testing/tests/package/test_python_whitenoise.py:27:133: E501 line too long (164 > 132 characters)

I tried to use the "r" prefix for the string, which gets rid of the
first warning, but then it doesn't do the right thing on the target.

> +        self.assertRunOk(cmd, timeout=timeout)
> +        # --nostatic ensures the builtin django server doesn't serve the static files,
> +        # so we can test that whitenoise serves them
> +        cmd = "cd /opt/testsite && " + self.interpreter + " ./manage.py runserver --nostatic 0.0.0.0:1234 > /dev/null 2>&1 & "
> +        self.assertRunOk(cmd, timeout=timeout)
> +        # give some time to setup the server
> +        for attempt in range(30 * self.emulator.timeout_multiplier):
> +            time.sleep(1)
> +            cmd = "wget http://127.0.0.1:1234/static/admin/css/base.css"
> +            _, exit_code = self.emulator.run(cmd)
> +            if exit_code == 0:
> +                break
> +        else:
> +            self.assertTrue(False, "Timeout while waiting for django server")

Could you replace self.assertTrue(False, "Timeout while waiting for
django server") with the logic that used in test_python_django.py, ie:

        for attempt in range(30 * self.emulator.timeout_multiplier):
            time.sleep(1)
            cmd = "netstat -ltn 2>/dev/null | grep 0.0.0.0:1234"
            _, exit_code = self.emulator.run(cmd)
            if exit_code == 0:
                break
        self.assertEqual(exit_code, 0, "Timeout while waiting for django server")

Thanks a lot!

Thomas
-- 
Thomas Petazzoni, co-owner and CEO, Bootlin
Embedded Linux and Kernel engineering and training
https://bootlin.com
_______________________________________________
buildroot mailing list
buildroot@buildroot.org
https://lists.buildroot.org/mailman/listinfo/buildroot

  parent reply	other threads:[~2025-02-05 10:41 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-02-16 13:18 [Buildroot] [PATCH 1/2] support/testing: remove hardcoded sleep from python-django test Marcus Hoffmann via buildroot
2024-02-16 13:18 ` [Buildroot] [PATCH 2/2] package/python-whitenoise: new package Marcus Hoffmann via buildroot
2024-08-05 10:02   ` Thomas Petazzoni via buildroot
2024-08-07 10:25     ` Marcus Hoffmann via buildroot
2025-02-05 10:41   ` Thomas Petazzoni via buildroot [this message]
2025-02-05 10:41   ` Thomas Petazzoni via buildroot
2024-02-16 13:23 ` [Buildroot] [PATCH 1/2] support/testing: remove hardcoded sleep from python-django test Marcus Hoffmann via buildroot
2024-02-16 19:55   ` Arnout Vandecappelle via buildroot
2024-02-20 16:46 ` Yann E. MORIN

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20250205114120.758c9da7@windsurf \
    --to=buildroot@buildroot.org \
    --cc=asafka7@gmail.com \
    --cc=buildroot@bubu1.eu \
    --cc=james.hilliard1@gmail.com \
    --cc=thomas.petazzoni@bootlin.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.