-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #122 from OpenUpSA/fix/save-point-without-image
Allow images and data in points.Location to be null
- Loading branch information
Showing
6 changed files
with
130 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import pytest | ||
|
||
from django.contrib.admin.sites import AdminSite | ||
from django.contrib.gis.geos import Point | ||
|
||
from wazimap_ng.points.models import Location | ||
from wazimap_ng.points.admin import LocationAdmin | ||
|
||
from tests.points import factoryboy as points_factoryboy | ||
|
||
@pytest.fixture() | ||
def test_location(): | ||
point = Point(0,0) | ||
return points_factoryboy.LocationFactory(name="Test Location", coordinates=point) | ||
|
||
from django.urls import reverse | ||
def test(admin_user, rf, test_location): | ||
url = reverse("admin:points_location_add") | ||
request = rf.get(url) | ||
request.user = admin_user | ||
location_admin = LocationAdmin(model=Location, admin_site=AdminSite()) | ||
location_form = location_admin.get_form(request) | ||
|
||
form = location_form(data={ | ||
"name": test_location.name, | ||
"coordinates": test_location.coordinates, | ||
"category": test_location.category | ||
}) | ||
|
||
assert "image" not in form.errors | ||
assert "data" not in form.errors |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import factory | ||
|
||
from tests.profile.factoryboy import ProfileFactory | ||
from wazimap_ng.points import models | ||
|
||
|
||
class ThemeFactory(factory.django.DjangoModelFactory): | ||
class Meta: | ||
model = models.Theme | ||
|
||
profile = factory.SubFactory(ProfileFactory) | ||
|
||
class CategoryFactory(factory.django.DjangoModelFactory): | ||
class Meta: | ||
model = models.Category | ||
|
||
profile = factory.SubFactory(ProfileFactory) | ||
|
||
|
||
class LocationFactory(factory.django.DjangoModelFactory): | ||
class Meta: | ||
model = models.Location | ||
|
||
category = factory.SubFactory(CategoryFactory) | ||
|
||
class ProfileCategory(factory.django.DjangoModelFactory): | ||
class Meta: | ||
model = models.ProfileCategory | ||
|
||
theme = factory.SubFactory(ThemeFactory) | ||
category = factory.SubFactory(CategoryFactory) | ||
profile = factory.SubFactory(ProfileFactory) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
# Generated by Django 2.2.13 on 2020-09-28 22:55 | ||
|
||
import django.core.validators | ||
from django.db import migrations, models | ||
import wazimap_ng.datasets.models.upload | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('datasets', '0108_auto_20200805_1449'), | ||
] | ||
|
||
operations = [ | ||
migrations.AlterField( | ||
model_name='datasetfile', | ||
name='document', | ||
field=models.FileField(help_text='\n Uploaded document should be less than 3000.0 MiB in size and \n file extensions should be one of xls, xlsx, csv.\n ', upload_to=wazimap_ng.datasets.models.upload.get_file_path, validators=[django.core.validators.FileExtensionValidator(allowed_extensions=['xls', 'xlsx', 'csv']), wazimap_ng.datasets.models.upload.file_size]), | ||
), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
# Generated by Django 2.2.13 on 2020-09-28 22:55 | ||
|
||
import django.contrib.postgres.fields.jsonb | ||
from django.db import migrations, models | ||
import wazimap_ng.points.models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('points', '0035_remove_profilecategory_permission_type'), | ||
] | ||
|
||
operations = [ | ||
migrations.AlterField( | ||
model_name='location', | ||
name='data', | ||
field=django.contrib.postgres.fields.jsonb.JSONField(default=dict), | ||
), | ||
migrations.AlterField( | ||
model_name='location', | ||
name='image', | ||
field=models.ImageField(blank=True, help_text='Optional image for point', null=True, upload_to=wazimap_ng.points.models.get_file_path), | ||
), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
# Generated by Django 2.2.13 on 2020-09-28 23:09 | ||
|
||
import django.contrib.postgres.fields.jsonb | ||
from django.db import migrations | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('points', '0036_auto_20200928_2255'), | ||
] | ||
|
||
operations = [ | ||
migrations.AlterField( | ||
model_name='location', | ||
name='data', | ||
field=django.contrib.postgres.fields.jsonb.JSONField(blank=True, default=dict), | ||
), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters