diff --git a/.gitignore b/.gitignore index 0228584..d50f8a7 100644 --- a/.gitignore +++ b/.gitignore @@ -37,3 +37,5 @@ docs/_build/ db.sqlite3 tmp/ + +.python-version diff --git a/Makefile b/Makefile index b0d2557..54f1af9 100644 --- a/Makefile +++ b/Makefile @@ -16,7 +16,7 @@ test-integration: coverage run --source admin_confirm --branch -m pytest --ignore=admin_confirm/tests/unit docker-exec: - docker-compose exec -T web ${COMMAND} + docker-compose -f docker-compose.dev.yml exec -T web ${COMMAND} check-readme: python -m readme_renderer README.md -o /tmp/README.html diff --git a/docker-compose.dev.yml b/docker-compose.dev.yml index 3641735..e1933c1 100644 --- a/docker-compose.dev.yml +++ b/docker-compose.dev.yml @@ -9,7 +9,15 @@ services: PYTHON_VERSION: "$PYTHON_VERSION" DJANGO_VERSION: "$DJANGO_VERSION" SELENIUM_VERSION: "$SELENIUM_VERSION" - command: python tests/manage.py runserver 0.0.0.0:8000 + # Note: collectstatic runs from inside the docker container and needs + # to access localstack through the host machine using host.docker.internal + # BUT when we access the django server from our host machine, we need to access + # the stored staticfiles via localhost, so export LOCALSTACK_HOST before and after + command: > + sh -c "export LOCALSTACK_HOST=host.docker.internal && + python tests/manage.py collectstatic --no-input && + export LOCALSTACK_HOST=localhost && + python tests/manage.py runserver 0.0.0.0:8000" volumes: - .:/code ports: @@ -18,9 +26,8 @@ services: - selenium - localstack environment: - - SELENIUM_HOST=selenium - # Used for localstack_client as well as our project - LOCALSTACK_HOST=host.docker.internal + - SELENIUM_HOST=host.docker.internal selenium: image: selenium/standalone-firefox @@ -32,8 +39,6 @@ services: localstack: image: localstack/localstack - container_name: localstack_main - network_mode: bridge ports: - "4566:4566" - "4571:4571" diff --git a/docs/development_process.md b/docs/development_process.md index 0a32c68..d0d6f68 100644 --- a/docs/development_process.md +++ b/docs/development_process.md @@ -3,6 +3,8 @@ **Local:** _You can skip this and just use docker if you want_ +_NOTE: as of 2022-04-12 I don't know if 3.8.0 works anymore if you're on newer versions of macOS. See: https://github.com/pyenv/pyenv/issues/2143#issuecomment-1072032647 You can try using another version of python locally or use docker_ + Install pyenv pyenv install 3.8.0 @@ -63,6 +65,13 @@ from admin_confirm.utils import log log('Message to send to stdout') ``` +**Localstack**: +Localstack is used for integration testing and also in the test project. + +To check if localstack is running correctly, go to `http://localhost:4566` +To check if the bucket has been set up correctly, go to `http://localhost:4566/mybucket` +To check if the static files have been set up correctly, go to `http://localhost:4566/mybucket/` + **Docker:** Instead of local set-up, you can also use docker. You may have to delete `.python-version` to do this. @@ -93,6 +102,8 @@ The integration tests are set up within docker. I recommend running the integrat Docker is also set to mirror local folder so that you can edit code/tests and don't have to rebuild to run new code/tests. +Use `docker-compose -f docker-compose.dev.yml up -d --force-recreate` if you need to restart the docker containers. For example when updating the docker-compose.yml file, but if you change `Dockerfile` you have to rebuild. + ### Release process Honestly this part is just for my reference. But who knows :) maybe we'll have another maintainer in the future. diff --git a/tests/market/migrations/0014_auto_20220413_0116.py b/tests/market/migrations/0014_auto_20220413_0116.py new file mode 100644 index 0000000..728402c --- /dev/null +++ b/tests/market/migrations/0014_auto_20220413_0116.py @@ -0,0 +1,19 @@ +# Generated by Django 3.1.7 on 2022-04-13 01:16 + +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + dependencies = [ + ('market', '0013_auto_20210702_0041'), + ] + + operations = [ + migrations.AlterField( + model_name='shoppingmall', + name='general_manager', + field=models.OneToOneField(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, to='market.generalmanager', verbose_name='manager'), + ), + ] diff --git a/tests/market/models.py b/tests/market/models.py index 1b112cd..551b4a9 100644 --- a/tests/market/models.py +++ b/tests/market/models.py @@ -54,7 +54,7 @@ class ShoppingMall(models.Model): name = models.CharField(max_length=120) shops = models.ManyToManyField(Shop, blank=True) general_manager = models.OneToOneField( - GeneralManager, on_delete=models.CASCADE, null=True, blank=True + GeneralManager, on_delete=models.CASCADE, null=True, blank=True, verbose_name="manager" ) town = models.ForeignKey(Town, on_delete=models.CASCADE, null=True, blank=True) diff --git a/tests/test_project/settings/base.py b/tests/test_project/settings/base.py index 092a27f..9650130 100644 --- a/tests/test_project/settings/base.py +++ b/tests/test_project/settings/base.py @@ -138,15 +138,17 @@ AWS_SECRET_ACCESS_KEY = os.getenv("AWS_SECRET_ACCESS_KEY", "test") AWS_STORAGE_BUCKET_NAME = os.getenv("AWS_STORAGE_BUCKET_NAME", "mybucket") AWS_DEFAULT_ACL = None - AWS_S3_CUSTOM_DOMAIN = f"{AWS_STORAGE_BUCKET_NAME}.s3.amazonaws.com" + # AWS_S3_CUSTOM_DOMAIN = f"{AWS_STORAGE_BUCKET_NAME}.s3.amazonaws.com" AWS_S3_OBJECT_PARAMETERS = {"CacheControl": "max-age=86400"} # s3 static settings - STATIC_LOCATION = "static" - STATIC_URL = f"https://{AWS_S3_CUSTOM_DOMAIN}/{STATIC_LOCATION}/" + STATIC_LOCATION = "staticfiles" + STATIC_URL = f"{AWS_S3_ENDPOINT_URL}/{STATIC_LOCATION}/" + STATIC_ROOT = os.path.join(BASE_DIR, STATIC_LOCATION) STATICFILES_STORAGE = "tests.storage_backends.StaticStorage" # s3 public media settings - PUBLIC_MEDIA_LOCATION = "media" - MEDIA_URL = f"https://{AWS_S3_CUSTOM_DOMAIN}/{PUBLIC_MEDIA_LOCATION}/" + PUBLIC_MEDIA_LOCATION = "mediafiles" + MEDIA_URL = f"{AWS_S3_ENDPOINT_URL}/{PUBLIC_MEDIA_LOCATION}/" + MEDIA_ROOT = os.path.join(BASE_DIR, PUBLIC_MEDIA_LOCATION) DEFAULT_FILE_STORAGE = "tests.storage_backends.PublicMediaStorage" else: STATIC_URL = "/staticfiles/"