-
Notifications
You must be signed in to change notification settings - Fork 9
Development tips
This wiki page contains tips for developers that are outside of the scope of the project README.
When you run back-end (python) tests, consider passing the name of the test file/directory to run and/or use the -k option to narrow down the number of tests you run.
Also consider passing the --reuse-db option, which can shed a few (or even several) seconds off test runs. It won't do anything at first, but subsequent test runs will be very fast. You just don't want to use it if you've just added a migration (or just done a git pull that includes a migration).
Here's an example that includes all the above suggestions:
pytest onboarding/tests/test_forms.py -k step_4 --reuse-db
This will run only tests that contain step_4 in their name, in a specific test file.
Some of tenants2's dependencies are taken from our monorepo, justfix-ts. It may sometimes be preferable to develop those dependencies in concert with tenants2, e.g. so that you can make a change in a dependency and instantly see how it changes the behavior of tenants2, without needing to re-publish anything or update any package.json files.
This can be done via the yarn link command.
The rest of these instructions will assume you want to make live changes to @justfixnyc/geosearch-requester, for sake of example.
First, in a terminal you'll want to get the monorepo up and running; see the justfix-ts README for instructions. Go into the package directory for @justfixnyc/geosearch-requester and run:
yarn link
yarn watch
The next step is to configure tenants2 to use the "live" version of the dependency you're working on. If you're using docker, the easiest way to proceed will actually be to build your front-end code outside of docker, while running everything else inside docker. This means you'll want to install node on your host system and run yarn in the root of the repository to install all its dependencies.
Next you'll want to open a separate terminal, tell yarn to use the live version of the dependency, and start the front-end build process:
yarn link @justfixnyc/geosearch-requester
yarn start
Finally, in a separate terminal, you can use docker to run the rest of the project in containers:
docker-compose up app db
Now you should see that, as you modify code in the dependency, the front-end will automatically re-bundle itself, and the behavior of the tenants2 front-end should change accordingly.
The tenants2 codebase can serve two totally different websites— the JustFix.nyc tenant platform as well as NoRent.org (see bottom of ReadMe for more info). The following steps will walk you through setting up your local hosting environment so you can navigate between the two sites in your browser simultaneously while developing.
First, you're going to want to edit your etc/hosts file on your local machine. You can find specific instructions on that process in this how-to guide. Once you're in this file, you should see the line
127.0.0.1 localhost
somewhere near the top. Below this line, add a new entry with the same IP address but a slightly different hostname— one that will help you differentiate one of the tenants2 sites from another. For example, you can add on:
127.0.0.1 localhost
127.0.0.1 localhost.norent
Next, you're going to want to make sure you have two Django site models defined in your development instance of tenants2. The easiest way to do this is to log in to the Django database as an admin user and go to the "Sites" view in the Admin Dashboard. From here, you can add new Sites entries, which will map hostnames to the name of the tenants2 Site you want to show at that hostname. You need to make sure that "Display Name" property contains JUSTFIX to show the JustFix.nyc Tenant Platform, and should contain NORENT to show the NoRent.org site. For this example, the Sites configuration looks like this:
DOMAIN NAME DISPLAY NAME
localhost JUSTFIX
localhost.norent NORENT
Once that's configured, you should now be able to view the JustFix.nyc Tenant Platform at http://localhost:8000/ and the NoRent.org site at http://localhost.norent:8000/.