Re: Prevent Django tests from accessing internet (except localhost)
On donderdag 26 juli 2018 02:35:01 CEST Gene wrote: > Preventing code from using networking is a common approach for unit tests > Firewall is a completely different story and has nothing common with this > matter It does, because he's looking for a catch-all button. If you read the entire thread you'll see we've offered several times, several strategies for different approaches for unit tests. But he's looking for the equivalent of "turning off the main water line" - and that's a firewall or sandboxes / virtual machines without network routing. Django has absolutely no way to do that and cannot, because there's no telling what 3rd party apps do (not that python has such a switch or even C). -- Melvyn Sopacua -- You received this message because you are subscribed to the Google Groups "Django users" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscr...@googlegroups.com. To post to this group, send email to django-users@googlegroups.com. Visit this group at https://groups.google.com/group/django-users. To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/1777274.KOJhutkDlD%40fritzbook. For more options, visit https://groups.google.com/d/optout.
Re: Prevent Django tests from accessing internet (except localhost)
By the way, another approach which is quite convenient is to run unit tests in docker during build stage (you will need to use settings with sqlite) Quite convenient in combination with pipeline or CI framework, for example bitbucket pipelines Or even on localhost On Monday, 23 July 2018 19:04:48 UTC+8, Kum wrote: > > Hi, > > Is there a global config I can enable to prevent any Django tests in a > project from accessing the internet (i.e., only allow network calls to > localhost) ? > > Thanks > -- You received this message because you are subscribed to the Google Groups "Django users" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscr...@googlegroups.com. To post to this group, send email to django-users@googlegroups.com. Visit this group at https://groups.google.com/group/django-users. To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/43e58c46-951a-4cf4-a92c-f75fb02ff04b%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.
Re: Prevent Django tests from accessing internet (except localhost)
Preventing code from using networking is a common approach for unit tests Firewall is a completely different story and has nothing common with this matter On Thursday, 26 July 2018 04:50:58 UTC+8, Melvyn Sopacua wrote: > > On dinsdag 24 juli 2018 04:21:07 CEST Kum wrote: > > Is there a way to prevent people from accidentally doing so? > > To prevent network access, there are firewalls. Django isn't the thing for > it. > > -- > Melvyn Sopacua > > > -- You received this message because you are subscribed to the Google Groups "Django users" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscr...@googlegroups.com. To post to this group, send email to django-users@googlegroups.com. Visit this group at https://groups.google.com/group/django-users. To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/f956487a-4264-443e-a708-e19c1d00f5f8%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.
Re: Prevent Django tests from accessing internet (except localhost)
On dinsdag 24 juli 2018 04:21:07 CEST Kum wrote: > Is there a way to prevent people from accidentally doing so? To prevent network access, there are firewalls. Django isn't the thing for it. -- Melvyn Sopacua -- You received this message because you are subscribed to the Google Groups "Django users" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscr...@googlegroups.com. To post to this group, send email to django-users@googlegroups.com. Visit this group at https://groups.google.com/group/django-users. To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/3373993.c7B7MrKRp2%40fritzbook. For more options, visit https://groups.google.com/d/optout.
Re: Prevent Django tests from accessing internet (except localhost)
There is no such config, but you can make it through socket interface mocking https://stackoverflow.com/questions/18601828/python-block-network-connections-for-testing-purposes You can also split all tests into two groups: - unit tests - should run without internet and all required requests should be mocked - integration tests - should run with internet as in production system For integration tests you can use decorator skipUnless (from unittest import skipUnless) You can have settings_test.py and settings_integration_tests for example, there can be a parameter in settings INTEGRATION_TESTS = True (or False in unit test settings) and then, test functions can be decorated like @skipUnless(settings.INTEGRATION_TESTS) On Monday, 23 July 2018 19:04:48 UTC+8, Kum wrote: > > Hi, > > Is there a global config I can enable to prevent any Django tests in a > project from accessing the internet (i.e., only allow network calls to > localhost) ? > > Thanks > -- You received this message because you are subscribed to the Google Groups "Django users" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscr...@googlegroups.com. To post to this group, send email to django-users@googlegroups.com. Visit this group at https://groups.google.com/group/django-users. To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/7d457e8a-34a8-4f8f-8a27-99f05e31dffc%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.
Re: Prevent Django tests from accessing internet (except localhost)
Have a switch that is set to OFF by default (then your tests will switch to using a mocked approach) and then have test that can only be be run with direct access to the API if you deliberately set it ON. No "accidents". On Tuesday, 24 July 2018 04:21:07 UTC+2, Kum wrote: > > Is there a way to prevent people from accidentally doing so? > > On Monday, July 23, 2018 at 7:39:27 AM UTC-4, Jason wrote: >> >> you shouldn't be accessing external services with your tests, you should >> mock or patch them with expected responses/failures and test based on that. >> > -- You received this message because you are subscribed to the Google Groups "Django users" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscr...@googlegroups.com. To post to this group, send email to django-users@googlegroups.com. Visit this group at https://groups.google.com/group/django-users. To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/c4df2697-41ab-42ad-86cb-65b94d64f5fd%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.
Re: Prevent Django tests from accessing internet (except localhost)
Is there a way to prevent people from accidentally doing so? On Monday, July 23, 2018 at 7:39:27 AM UTC-4, Jason wrote: > > you shouldn't be accessing external services with your tests, you should > mock or patch them with expected responses/failures and test based on that. > -- You received this message because you are subscribed to the Google Groups "Django users" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscr...@googlegroups.com. To post to this group, send email to django-users@googlegroups.com. Visit this group at https://groups.google.com/group/django-users. To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/f883c2ee-defc-4480-a57e-c2c6534f236e%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.
Re: Prevent Django tests from accessing internet (except localhost)
On maandag 23 juli 2018 17:23:20 CEST chuck.horow...@packetviper.us wrote: > Hi Kum, > > I think Melvyn's suggestion is a good one. Is there any reason you > couldn't do: > > > import DEBUG from yourapp.settings > > > And then check against that for your testing? Here's some code I used in a test: class KvkApiTester(Testcase): def skip_live_tests(self): api_config = getattr(settings, 'KVKAPI', dict()) if not kvk_config or kvk_config['live_tests'] is False: raise self.skipTest('live tests disabled or no KVKAPI configuration) def test_api_key(self): self.skip_live_tests() ... # actual tests That way you know why tests are not running. > > On Monday, July 23, 2018 at 8:22:17 AM UTC-4, Melvyn Sopacua wrote: > > On maandag 23 juli 2018 13:39:27 CEST Jason wrote: > > > you shouldn't be accessing external services with your tests > > > > Non-sense. Part of interacting with a remote API is making sure it works > > and > > they didn't change anything (trust me, there's plenty of API's that change > > without changing version numbers). > > > > As for a global setting: no there isn't one. Your tests should have a > > switch > > of their own if you're worried about that. -- Melvyn Sopacua -- You received this message because you are subscribed to the Google Groups "Django users" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscr...@googlegroups.com. To post to this group, send email to django-users@googlegroups.com. Visit this group at https://groups.google.com/group/django-users. To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/5218345.80TMzJj1UW%40fritzbook. For more options, visit https://groups.google.com/d/optout.
Re: Prevent Django tests from accessing internet (except localhost)
Hi Kum, I think Melvyn's suggestion is a good one. Is there any reason you couldn't do: import DEBUG from yourapp.settings And then check against that for your testing? On Monday, July 23, 2018 at 8:22:17 AM UTC-4, Melvyn Sopacua wrote: > > On maandag 23 juli 2018 13:39:27 CEST Jason wrote: > > you shouldn't be accessing external services with your tests > > Non-sense. Part of interacting with a remote API is making sure it works > and > they didn't change anything (trust me, there's plenty of API's that change > without changing version numbers). > > As for a global setting: no there isn't one. Your tests should have a > switch > of their own if you're worried about that. > > -- > Melvyn Sopacua > > > -- You received this message because you are subscribed to the Google Groups "Django users" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscr...@googlegroups.com. To post to this group, send email to django-users@googlegroups.com. Visit this group at https://groups.google.com/group/django-users. To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/3634f858-d56a-4fa0-b946-398c344c64c6%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.
Re: Prevent Django tests from accessing internet (except localhost)
On maandag 23 juli 2018 13:39:27 CEST Jason wrote: > you shouldn't be accessing external services with your tests Non-sense. Part of interacting with a remote API is making sure it works and they didn't change anything (trust me, there's plenty of API's that change without changing version numbers). As for a global setting: no there isn't one. Your tests should have a switch of their own if you're worried about that. -- Melvyn Sopacua -- You received this message because you are subscribed to the Google Groups "Django users" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscr...@googlegroups.com. To post to this group, send email to django-users@googlegroups.com. Visit this group at https://groups.google.com/group/django-users. To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/4215975.Nr0BvRUCs3%40fritzbook. For more options, visit https://groups.google.com/d/optout.
Re: Prevent Django tests from accessing internet (except localhost)
you shouldn't be accessing external services with your tests, you should mock or patch them with expected responses/failures and test based on that. -- You received this message because you are subscribed to the Google Groups "Django users" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscr...@googlegroups.com. To post to this group, send email to django-users@googlegroups.com. Visit this group at https://groups.google.com/group/django-users. To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/babc8253-b18b-4e98-b637-b2b4ddd749a1%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.
Prevent Django tests from accessing internet (except localhost)
Hi, Is there a global config I can enable to prevent any Django tests in a project from accessing the internet (i.e., only allow network calls to localhost) ? Thanks -- You received this message because you are subscribed to the Google Groups "Django users" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscr...@googlegroups.com. To post to this group, send email to django-users@googlegroups.com. Visit this group at https://groups.google.com/group/django-users. To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/fdec55c6-03eb-4ae8-8693-09187244c642%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.