Skip to content

Commit

Permalink
Tested field verbose_name locally
Browse files Browse the repository at this point in the history
  • Loading branch information
TrangPham committed Apr 13, 2022
1 parent 7ffed7a commit 340726b
Show file tree
Hide file tree
Showing 7 changed files with 51 additions and 12 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,5 @@ docs/_build/
db.sqlite3

tmp/

.python-version
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
15 changes: 10 additions & 5 deletions docker-compose.dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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
Expand All @@ -32,8 +39,6 @@ services:

localstack:
image: localstack/localstack
container_name: localstack_main
network_mode: bridge
ports:
- "4566:4566"
- "4571:4571"
Expand Down
11 changes: 11 additions & 0 deletions docs/development_process.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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.
Expand Down
19 changes: 19 additions & 0 deletions tests/market/migrations/0014_auto_20220413_0116.py
Original file line number Diff line number Diff line change
@@ -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'),
),
]
2 changes: 1 addition & 1 deletion tests/market/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
12 changes: 7 additions & 5 deletions tests/test_project/settings/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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/"
Expand Down

0 comments on commit 340726b

Please sign in to comment.