From 1eaeebea677c7f1724d950b3dfe5bc47de931a92 Mon Sep 17 00:00:00 2001 From: lowit Date: Wed, 18 Nov 2020 12:40:05 +0300 Subject: [PATCH 1/4] issue-64: Changes max_length for LogEntry.path --- http_stubs/models.py | 1 + 1 file changed, 1 insertion(+) diff --git a/http_stubs/models.py b/http_stubs/models.py index 123f814..7b1c4b0 100644 --- a/http_stubs/models.py +++ b/http_stubs/models.py @@ -108,6 +108,7 @@ class LogEntry(models.Model): path = models.URLField( verbose_name='Full request path', + max_length=2000, ) method = models.CharField( verbose_name='Request method', From dca2d3bbadc2ef688d294c05827dd976e589d0e5 Mon Sep 17 00:00:00 2001 From: lowit Date: Wed, 18 Nov 2020 13:19:23 +0300 Subject: [PATCH 2/4] issue-64: adds migrations --- .../0003_translation_model_fields.py | 96 +++++++++++++++++++ .../0004_increase_logentry_path_max_length.py | 18 ++++ 2 files changed, 114 insertions(+) create mode 100644 http_stubs/migrations/0003_translation_model_fields.py create mode 100644 http_stubs/migrations/0004_increase_logentry_path_max_length.py diff --git a/http_stubs/migrations/0003_translation_model_fields.py b/http_stubs/migrations/0003_translation_model_fields.py new file mode 100644 index 0000000..8b1368a --- /dev/null +++ b/http_stubs/migrations/0003_translation_model_fields.py @@ -0,0 +1,96 @@ +# Generated by Django 3.0.6 on 2020-11-18 10:11 + +import django.contrib.postgres.fields.hstore +import django.core.validators +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + dependencies = [ + ('http_stubs', '0002_auto_20200626_0154'), + ] + + operations = [ + migrations.AlterField( + model_name='httpstub', + name='is_active', + field=models.BooleanField(default=True, verbose_name='Enabled'), + ), + migrations.AlterField( + model_name='httpstub', + name='method', + field=models.CharField(choices=[('GET', 'GET'), ('POST', 'POST'), ('PUT', 'PUT'), ('PATCH', 'PATCH'), ('DELETE', 'DELETE'), ('HEAD', 'HEAD'), ('OPTIONS', 'OPTIONS'), ('TRACE', 'TRACE')], db_index=True, max_length=10, verbose_name='Request method'), + ), + migrations.AlterField( + model_name='httpstub', + name='path', + field=models.CharField(db_index=True, max_length=2000, verbose_name='Request path'), + ), + migrations.AlterField( + model_name='httpstub', + name='regex_path', + field=models.BooleanField(default=False, help_text='Path is a regular expression', verbose_name='REGEX path'), + ), + migrations.AlterField( + model_name='httpstub', + name='resp_body', + field=models.TextField(blank=True, default='[]', verbose_name='Response body'), + ), + migrations.AlterField( + model_name='httpstub', + name='resp_content_type', + field=models.CharField(default='application/json', max_length=255, verbose_name='Response Content-Type'), + ), + migrations.AlterField( + model_name='httpstub', + name='resp_delay', + field=models.PositiveIntegerField(default=0, help_text='In milliseconds', verbose_name='Response delay'), + ), + migrations.AlterField( + model_name='httpstub', + name='resp_headers', + field=django.contrib.postgres.fields.hstore.HStoreField(blank=True, default=dict, help_text='In JSON format', verbose_name='Response headers'), + ), + migrations.AlterField( + model_name='httpstub', + name='resp_status', + field=models.IntegerField(default=200, validators=[django.core.validators.MinValueValidator(0), django.core.validators.MaxValueValidator(600)], verbose_name='Response status'), + ), + migrations.AlterField( + model_name='logentry', + name='body', + field=models.TextField(verbose_name='Request body'), + ), + migrations.AlterField( + model_name='logentry', + name='date', + field=models.DateTimeField(auto_now_add=True, verbose_name='Request timestamp'), + ), + migrations.AlterField( + model_name='logentry', + name='headers', + field=django.contrib.postgres.fields.hstore.HStoreField(verbose_name='Request headers'), + ), + migrations.AlterField( + model_name='logentry', + name='http_stub', + field=models.ForeignKey(blank=True, on_delete=django.db.models.deletion.CASCADE, related_name='logs', to='http_stubs.HTTPStub', verbose_name='Related stub'), + ), + migrations.AlterField( + model_name='logentry', + name='method', + field=models.CharField(choices=[('GET', 'GET'), ('POST', 'POST'), ('PUT', 'PUT'), ('PATCH', 'PATCH'), ('DELETE', 'DELETE'), ('HEAD', 'HEAD'), ('OPTIONS', 'OPTIONS'), ('TRACE', 'TRACE')], max_length=10, verbose_name='Request method'), + ), + migrations.AlterField( + model_name='logentry', + name='path', + field=models.URLField(verbose_name='Full request path'), + ), + migrations.AlterField( + model_name='logentry', + name='source_ip', + field=models.GenericIPAddressField(verbose_name='Source IP'), + ), + ] diff --git a/http_stubs/migrations/0004_increase_logentry_path_max_length.py b/http_stubs/migrations/0004_increase_logentry_path_max_length.py new file mode 100644 index 0000000..2160fc3 --- /dev/null +++ b/http_stubs/migrations/0004_increase_logentry_path_max_length.py @@ -0,0 +1,18 @@ +# Generated by Django 3.0.6 on 2020-11-18 10:13 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('http_stubs', '0003_translation_model_fields'), + ] + + operations = [ + migrations.AlterField( + model_name='logentry', + name='path', + field=models.URLField(max_length=2000, verbose_name='Full request path'), + ), + ] From bc1d6222220d6801693409073c60e7f396955952 Mon Sep 17 00:00:00 2001 From: lowit Date: Wed, 18 Nov 2020 13:19:37 +0300 Subject: [PATCH 3/4] issue-64: fixes test --- http_stubs/tests/tests.py | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/http_stubs/tests/tests.py b/http_stubs/tests/tests.py index b1a8d8e..5d5f51d 100644 --- a/http_stubs/tests/tests.py +++ b/http_stubs/tests/tests.py @@ -48,8 +48,15 @@ def test_write_log(self, http_stub_factory, client): :param client: http client fixture """ content_type = 'text/plain' - http_body = http_stub_factory(method=HTTPMethod.POST.name) - client.post('/default_path/', 'test', content_type=content_type) + http_body = http_stub_factory( + method=HTTPMethod.POST.name, + path='/regex/.*', + regex_path=True, + ) + + request_path = f'/regex/?query={"search" * 300}' + + client.post(request_path, 'test', content_type=content_type) log = LogEntry.objects.last() def _datefmt(date) -> str: # noqa:WPS430 @@ -72,7 +79,7 @@ def _datefmt(date) -> str: # noqa:WPS430 assert log.body == 'test' assert log.http_stub == http_body assert log.method == HTTPMethod.POST.name - assert log.path == 'http://testserver/default_path/' + assert log.path == f'http://testserver{request_path}' @pytest.mark.parametrize('method', HTTPMethod.names()) def test_exist_regexp_stub(self, method: str, http_stub_factory, client): From 0ace41a79e74abfdcd0d5a56770dc3492fa160fd Mon Sep 17 00:00:00 2001 From: lowit Date: Wed, 18 Nov 2020 13:36:10 +0300 Subject: [PATCH 4/4] issue-64: deletes wildcard --- http_stubs/tests/tests.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/http_stubs/tests/tests.py b/http_stubs/tests/tests.py index 5d5f51d..c12dff6 100644 --- a/http_stubs/tests/tests.py +++ b/http_stubs/tests/tests.py @@ -50,7 +50,7 @@ def test_write_log(self, http_stub_factory, client): content_type = 'text/plain' http_body = http_stub_factory( method=HTTPMethod.POST.name, - path='/regex/.*', + path='/regex/', regex_path=True, )