Skip to content

Commit

Permalink
#404 Create make rule for temp db (#804)
Browse files Browse the repository at this point in the history
* #404  Create make rule for temp db

* se#404  Review#1 fix assert
  • Loading branch information
duker33 committed Apr 4, 2019
1 parent df1500f commit 06ecddd
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
11 changes: 11 additions & 0 deletions docker/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ dc=docker-compose
d=docker
dcb=$(dc) -f docker-compose-build.yml
dcp=$(dc) -f docker-compose-production.yml
# the same const value is used at `test_db` django command
TEST_DB=test_se

# @todo #269 Create docs for build system.

Expand All @@ -20,6 +22,15 @@ fixtures:
&& python manage.py loaddata shopelectro/fixtures/dump.json \
"

gen-fixtures:
$(dc) exec postgres bash -c "\
psql -Upostgres <<< 'CREATE DATABASE $(TEST_DB);' \
"
$(dc) run --rm -e POSTGRES_DB=$(TEST_DB) app python manage.py test_db
$(dc) exec postgres bash -c "\
psql -Upostgres <<< 'DROP DATABASE $(TEST_DB);' \
"

prices:
$(dc) exec app python manage.py price

Expand Down
10 changes: 5 additions & 5 deletions shopelectro/management/commands/test_db.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
from pages.utils import save_custom_pages, init_redirects_app
from shopelectro import models as se_models, tests as se_tests

TEST_DB = 'test_se'


class Command(BaseCommand):

Expand Down Expand Up @@ -70,11 +72,9 @@ def handle(self, *args, **options):
self.save_dump()

def prepare_db(self):
# @todo #389:60m Set db name in `test_db` command. stb2
# Set name instead of asserting.
# You also should create/drop it with postgres driver.
is_test_db = settings.DATABASES['default']['NAME'] == 'test'
assert is_test_db, 'To create fixtures you have to create a database named "test".'
is_test_db = settings.DATABASES['default']['NAME'] == TEST_DB
assert is_test_db, \
f'To create fixtures you have to create a databasenamed "{TEST_DB}".'
call_command('migrate')
self.purge_tables()

Expand Down

1 comment on commit 06ecddd

@0pdd
Copy link
Collaborator

@0pdd 0pdd commented on 06ecddd Apr 4, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Puzzle 389-3679238e disappeared from shopelectro/management/commands/test_db.py, that's why I closed #404. Please, remember that the puzzle was not necessarily removed in this particular commit. Maybe it happened earlier, but we discovered this fact only now.

Please sign in to comment.