Skip to content

Commit

Permalink
test default app
Browse files Browse the repository at this point in the history
  • Loading branch information
sheppard committed Jun 16, 2023
1 parent db80271 commit 5470d93
Show file tree
Hide file tree
Showing 4 changed files with 179 additions and 35 deletions.
140 changes: 140 additions & 0 deletions tests/expected/config0.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,140 @@
{
"pages": {
"login": {
"url": "login",
"name": "login"
},
"logout": {
"url": "logout",
"name": "logout"
},
"category": {
"cache": "all",
"background_sync": false,
"name": "category",
"url": "categories",
"list": true,
"form": [
{
"name": "name",
"label": "Name",
"bind": {
"required": true
},
"wq:length": 255,
"type": "string"
},
{
"name": "description",
"label": "Description",
"type": "text"
}
],
"verbose_name": "category",
"verbose_name_plural": "categories",
"label_template": "{{name}}"
},
"observation": {
"cache": "first_page",
"background_sync": true,
"map": [
{
"mode": "list",
"autoLayers": true,
"layers": []
},
{
"mode": "detail",
"autoLayers": true,
"layers": []
},
{
"mode": "edit",
"layers": []
}
],
"name": "observation",
"url": "observations",
"list": true,
"form": [
{
"name": "date",
"label": "Date",
"hint": "The date when the observation was taken",
"type": "date"
},
{
"name": "category",
"label": "Category",
"hint": "Observation type",
"type": "select one",
"wq:ForeignKey": "category",
"wq:related_name": "observation_set"
},
{
"name": "geometry",
"label": "Location",
"bind": {
"required": true
},
"hint": "The location of the observation",
"type": "geopoint"
},
{
"name": "photo",
"label": "Photo",
"hint": "Photo of the observation",
"type": "image"
},
{
"name": "notes",
"label": "Notes",
"hint": "Field observations and notes",
"type": "text",
"multiline": true
}
],
"verbose_name": "observation",
"verbose_name_plural": "observations",
"ordering": [
"-date"
],
"label_template": "{{date}}"
},
"index": {
"url": "",
"name": "index",
"show_in_index": false,
"verbose_name": "test Project"
}
},
"site_title": "test Project",
"router": {
"base_url": ""
},
"store": {
"service": "",
"defaults": {
"format": "json"
}
},
"material": {
"theme": {
"primary": "#7500ae",
"secondary": "#0088bd"
}
},
"map": {
"bounds": [
[
-180,
-70
],
[
180,
70
]
]
},
"debug": true
}
7 changes: 5 additions & 2 deletions tests/json-compare.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
#!/usr/bin/env python
import sys
import json
import pathlib

file1, file2 = sys.argv[1:]

json1 = json.load(open(file1))
json2 = json.load(open(file2))
root = pathlib.Path(__file__).parent

json1 = json.load(open(root / file1))
json2 = json.load(open(root / file2))

for key in ('debug',):
json1.pop(key, None)
Expand Down
65 changes: 33 additions & 32 deletions tests/test-deploy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ else
fi;


MANAGE="test_project/db/manage.py"
MANAGE="db/manage.py"
OUTPUT="../output"
COMPARE="../json-compare.py"
PORT=8000

# wq create: Create new project
Expand All @@ -32,56 +34,55 @@ fi;
wq create test_project ./test_project -d test.wq.io -t "test Project" $NPM_FLAG $GIS_FLAG
cd test_project

# Remove example app
rm -rf db/test_project_survey/
sed -i 's/"test_project_survey",//' db/test_project/settings/base.py

# Verify ./deploy.sh works
./deploy.sh 0.0.0
cd ..;

# Load db and verify initial config
if [[ "$TEST_VARIANT" == "postgis" ]]; then
sed -i "s/'USER': 'test_project'/'USER': '$USER'/" test_project/db/test_project/settings/prod.py
sed -i "s/ALLOWED_HOSTS.*/ALLOWED_HOSTS = ['localhost']/" test_project/db/test_project/settings/prod.py
sed -i "s/'USER': 'test_project'/'USER': '$USER'/" db/test_project/settings/prod.py
sed -i "s/ALLOWED_HOSTS.*/ALLOWED_HOSTS = ['localhost']/" db/test_project/settings/prod.py
else
# See https://code.djangoproject.com/ticket/32935
$MANAGE shell -c "import django;django.db.connection.cursor().execute('SELECT InitSpatialMetaData(1);')";
fi;
$MANAGE migrate
$MANAGE dump_config > output/config1.json
./json-compare.py expected/config1.json output/config1.json
$MANAGE dump_config > $OUTPUT/config0.json
$COMPARE expected/config0.json output/config0.json

# Remove example app and verify deploy still works
rm -rf db/test_project_survey/
sed -i 's/"test_project_survey",//' db/test_project/settings/base.py
./deploy.sh 0.0.1
$MANAGE migrate
$MANAGE dump_config > $OUTPUT/config1.json
$COMPARE expected/config1.json output/config1.json

# wq addform: Add a single form and verify changed config
cd test_project/db
wq addform -f ../../location.csv
sed -i "s/class Meta:/def __str__(self):\n return self.name\n\n class Meta:/" location/models.py
cd ../../
$MANAGE dump_config > output/config2.json
./json-compare.py expected/config2.json output/config2.json
wq addform -f ../location.csv
sed -i "s/class Meta:/def __str__(self):\n return self.name\n\n class Meta:/" db/location/models.py
$MANAGE dump_config > $OUTPUT/config2.json
$COMPARE expected/config2.json output/config2.json

# wq addform: Add a second form that references the first
cd test_project/db
wq addform -f ../../observation.csv
sed -i "s/class Meta:/def __str__(self):\n return '%s on %s' % (self.location, self.date)\n\n class Meta:/" observation/models.py
cd ../../
$MANAGE dump_config > output/config3.json
./json-compare.py expected/config3.json output/config3.json
wq addform -f ../observation.csv
sed -i "s/class Meta:/def __str__(self):\n return '%s on %s' % (self.location, self.date)\n\n class Meta:/" db/observation/models.py
$MANAGE dump_config > $OUTPUT/config3.json
$COMPARE expected/config3.json output/config3.json

# Enable anonymous submissions and start webserver
sed -i "s/WSGI_APPLICATION/ANONYMOUS_PERMISSIONS = ['location.add_location', 'observation.add_observation']\n\nWSGI_APPLICATION/" test_project/db/test_project/settings/base.py
sed -i "s/WSGI_APPLICATION/ANONYMOUS_PERMISSIONS = ['location.add_location', 'observation.add_observation']\n\nWSGI_APPLICATION/" db/test_project/settings/base.py
$MANAGE runserver $PORT & sleep 5

# Submit a new site
curl -sf http://localhost:$PORT/locations.json > output/locations1.json
./json-compare.py expected/locations1.json output/locations1.json
curl -sf http://localhost:$PORT/locations.json > $OUTPUT/locations1.json
$COMPARE expected/locations1.json output/locations1.json
curl -sf http://localhost:$PORT/locations.json -d name="Site 1" -d type="water" -d geometry='{"type": "Point", "coordinates": [-93.28, 44.98]}' > /dev/null
curl -sf http://localhost:$PORT/locations.geojson > output/locations2.geojson
./json-compare.py expected/locations2.geojson output/locations2.geojson
curl -sf http://localhost:$PORT/locations.geojson > $OUTPUT/locations2.geojson
$COMPARE expected/locations2.geojson output/locations2.geojson

# Submit a new observation
curl -sf http://localhost:$PORT/observations.json -F location_id=1 -F date="2015-10-08" -F notes="A cold winter day in Minneapolis" -F photo=@photo.jpg > /dev/null
curl -sf http://localhost:$PORT/observations.json > output/observations1.json
sed -i "s/$PORT/8000/" output/observations1.json
./json-compare.py expected/observations1.json output/observations1.json
diff photo.jpg test_project/media/observations/photo.jpg
curl -sf http://localhost:$PORT/observations.json -F location_id=1 -F date="2015-10-08" -F notes="A cold winter day in Minneapolis" -F photo=@../photo.jpg > /dev/null
curl -sf http://localhost:$PORT/observations.json > $OUTPUT/observations1.json
sed -i "s/$PORT/8000/" $OUTPUT/observations1.json
$COMPARE expected/observations1.json output/observations1.json
diff ../photo.jpg media/observations/photo.jpg
2 changes: 1 addition & 1 deletion wq/create/django_project

0 comments on commit 5470d93

Please sign in to comment.