Skip to content

Commit

Permalink
Address review requests
Browse files Browse the repository at this point in the history
  • Loading branch information
oliverroick committed May 8, 2017
1 parent 6798eec commit 5460f1a
Show file tree
Hide file tree
Showing 9 changed files with 289 additions and 21 deletions.
11 changes: 11 additions & 0 deletions cadasta/organization/tests/files/test_custom.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
name_mouza,j_l,tenure_type,location_type,party_type,name_of_HH,name_father_hus,present_add,village_name,Mobile_No,Occupation_HH,educational_qualification,amount_agriland,amount_othersland,class_HH,How_aquire_landw,How_aquire_landwh,How_aquire_landm,how_aquire_landd,how_aquire_landt,How_aquire_landp,Land_Calculation,deed_of_land,Khatain_of_land,Mutation_of_land,Dakhal_on_land,Everything,female_member,male_member,ownership_conflict,boundary_conflict,others_conflict,conflicts_resoulation,howconflict_resoulation,location_problems,tenure_name,tenure_notes,nid_number,location_geometry,_geopoint_hh_latitude,_geopoint_hh_longitude,_geopoint_hh_altitude,_geopoint_hh_precision,image_hh,audio_hh,start,end,today,deviceid,subscriberid,sim_serial,phonenumber,meta/instanceID,_id,_uuid,_submission_time,_index,_parent_table_name,_parent_index,_tags,_notes,_version,_duration,_submitted_by
chanderhowara,90,AA,BB,IN,সুরুজ্জামান,মৃত শাহালী মন্ডল,মন্ডল বাড়ি,চান্দের হাওড়া,০১৭২৮১০১১৩৩,farmer,Illiterate,১৮০.০০ অারঙ্গহাটি ৩৬০.০০,১৫.০০,others,inheritance,,did_not_get_from_tafshil,inheritance,generations,inheritance,yes,no,yes,no,yes,no,4,5,yes,no,কিছু বেখলে অাছে জোর করে দখল করে ভোগ করে অন্য জমির মালক।,yes,local_justice,"conflict, risk_of_eviction",Freehold,some notes,3913647224045,,,,,,,,2016-02-08T10:43:19.861+06,2016-02-09T09:03:56.526+06,2016-02-08,355335064140032,470034501263565,8988034503012635653f,,uuid:c2b46f0e-dd3c-4c0b-858e-edd582047f6c,5349241,c2b46f0e-dd3c-4c0b-858e-edd582047f6c,2016-02-09T11:30:07,1,,-1,,,201602060307,80437,arifuttaran
chanderhowara,90,AA,BB,GR,অাব্দুল বারেক মন্ডল,মৃত বঙ্গু মন্ডল,মন্ডল বাড়ি,চান্দের হাওড়া,০১৭৯৮০৮১৯৯৪,farmer,Illiterate,৩০.০০ আরঙ্গহাটি ১২০.০০,১৫.০০,others,inheritance,,did_not_get_from_tafshil,inheritance,generations,inheritance,yes,yes,yes,no,yes,no,5,4,no,no,,,,,Leasehold,some notes on the tenure,3913647224033,,,,,,,,2016-02-08T11:13:52.453+06,2016-02-09T13:58:53.495+06,2016-02-08,355335064140032,470034501263565,8988034503012635653f,,uuid:4df81c07-29d2-4a75-9fe4-e7dcc4b05d16,5349244,4df81c07-29d2-4a75-9fe4-e7dcc4b05d16,2016-02-09T11:30:17,2,,-1,,,201602060307,96301,arifuttaran
chanderhowara,90,AA,BB,CO,হানিফ উদ্দিন,মৃত মুগল মন্ডল,অারঙ্গহাটি,পশ্চিম অারঙ্গহাটি,০১৭৯৮০৮১৯৯৪,farmer,litteracy,১৫.০০,১৫.০০,others,inheritance,,did_not_get_from_tafshil,inheritance,generations,inheritance,yes,yes,yes,yes,yes,no,3,4,no,no,,,,,Customary,some more notes,3913647225965,,,,,,,,2016-02-08T11:21:20.859+06,2016-02-09T13:58:16.633+06,2016-02-08,355335064140032,470034501263565,8988034503012635653f,,uuid:405a9d1c-3c54-42ca-929d-ab4f261ce59a,5349247,405a9d1c-3c54-42ca-929d-ab4f261ce59a,2016-02-09T11:30:28,3,,-1,,,201602060307,95816,arifuttaran
chanderhowara,90,AA,BB,IN,মো: অামিনুর ইসলাম,সুরুজ্জামান,মন্ডল বাড়ি,চান্দের হাওড়া,০১৭২৮১০১১৩৩,service,educated,১৫.০০ অারঙ্গহাটি ৩০.০০,১৫.০০,others,inheritance,,did_not_get_from_tafshil,inheritance,generations,inheritance,yes,yes,no,no,yes,no,2,1,no,no,,,,,,,3913647224032,24.850375 89.832815 17.3 4.8,24.850375,89.832815,17.3,4.8,,,2016-02-08T11:27:32.805+06,2016-02-08T11:55:08.868+06,2016-02-08,355335064140032,470034501263565,8988034503012635653f,,uuid:6925434e-37d3-4f09-b308-1e6e9ccf1d11,5349250,6925434e-37d3-4f09-b308-1e6e9ccf1d11,2016-02-09T11:30:38,4,,-1,,,201602060307,1656,arifuttaran
chanderhowara,90,AA,BB,GR,সোজা মন্ডল,মৃত শাহালী মন্ডল,মন্ডল বাড়ি,চান্দের হাওড়া,০১৭২৮১০১১৩৩,farmer,Illiterate,৭০.০০,১৫.০০,others,inheritance,,did_not_get_from_tafshil,inheritance,generations,inheritance,yes,no,no,no,yes,no,0,1,no,no,,,,,,,3913647224043,,,,,,,,2016-02-08T11:32:28.205+06,2016-02-09T13:58:42.516+06,2016-02-08,355335064140032,470034501263565,8988034503012635653f,,uuid:b2cdbeba-1ced-4740-9605-9430d1ed7ead,5349251,b2cdbeba-1ced-4740-9605-9430d1ed7ead,2016-02-09T11:30:40,5,,-1,,,201602060307,95174,arifuttaran
chanderhowara,90,AA,BB,CO,মিজানুর রহমান,সুরুজ্জামান,মন্ডল বাড়ি,চান্দের হাওড়া,০১৭২৮১০১১৩৩,farmer,Illiterate,15,১৫.০০,others,inheritance,,did_not_get_from_tafshil,inheritance,generations,inheritance,no,yes,no,no,yes,no,3,2,no,no,,,,,,,3913647224044,24.85034333333333 89.83295000000001 42.3 7.1,24.8503433333,89.83295,42.3,7.1,,,2016-02-08T11:37:42.708+06,2016-02-08T11:47:20.509+06,2016-02-08,355335064140032,470034501263565,8988034503012635653f,,uuid:d16a03fa-5009-490e-bc4f-c3812e704b46,5349252,d16a03fa-5009-490e-bc4f-c3812e704b46,2016-02-09T11:30:42,6,,-1,,,201602060307,578,arifuttaran
chanderhowara,90,AA,BB,IN, জামিনুর ইসলাম,সুরুজ্জামান,মন্ডল বাড়ি,চান্দের হাওড়া,০১৭২৮১০১১৩৩,farmer,Illiterate,১৫.০০,১৫.০০,others,inheritance,,did_not_get_from_tafshil,inheritance,generations,inheritance,no,yes,no,no,yes,no,2,2,no,no,,no,,,,,3913647224031,24.850428333333337 89.83293166666665 13.2 4.9,24.8504283333,89.8329316667,13.2,4.9,,,2016-02-08T11:47:29.749+06,2016-02-08T11:51:46.250+06,2016-02-08,355335064140032,470034501263565,8988034503012635653f,,uuid:73d91b2a-ff43-4c13-b9ec-9d0f9e68d0cb,5349254,73d91b2a-ff43-4c13-b9ec-9d0f9e68d0cb,2016-02-09T11:30:50,7,,-1,,,201602060307,257,arifuttaran
chanderhowara,90,AA,BB,GR,মো: গোলজার হোসেন,মৃত মো: শাহাজান অালী,মেম্বার বাড়ি,চান্দের হাওড়া,০১৭৪৩০৪৮৪২৩,doctor,educated,0,১৫.০০,poor,inheritance,,did_not_get_from_tafshil,inheritance,generations,inheritance,no,no,no,no,yes,no,4,3,no,no,,,,,,,3913647224185,24.849339999999998 89.83242166666666 -25.9 4.7,24.84934,89.8324216667,-25.9,4.7,,,2016-02-08T12:14:23.738+06,2016-02-08T12:21:48.113+06,2016-02-08,355335064140032,470034501263565,8988034503012635653f,,uuid:35bb0314-bdc4-4e1d-9994-66bd745d0c0b,5349255,35bb0314-bdc4-4e1d-9994-66bd745d0c0b,2016-02-09T11:30:52,8,,-1,,,201602060307,445,arifuttaran
chanderhowara,90,AA,BB,CO, সুমন টিকাদার,মৃত নওয়াব অালি টিকাদার,টিকাদার বাড়ি,চান্দের হাওড়া,০১৭৩৪২৫১৩৩৮,farmer,litteracy,১০.০০,১৫.০০,others,inheritance,,did_not_get_from_tafshil,inheritance,generations,inheritance,no,no,no,no,yes,no,1,4,no,no,,,,,,,3913647224283,24.848106666666663 89.83239833333333 -115.7 5.4,24.8481066667,89.8323983333,-115.7,5.4,,,2016-02-08T12:41:22.328+06,2016-02-08T12:45:05.345+06,2016-02-08,355335064140032,470034501263565,8988034503012635653f,,uuid:2454181a-4d9a-4797-b908-0c1c82c6b92a,5349256,2454181a-4d9a-4797-b908-0c1c82c6b92a,2016-02-09T11:30:53,9,,-1,,,201602060307,223,arifuttaran
chanderhowara,90,AA,BB,IN,অাব্দুল জলিল মন্ডল ,মৃত কুব্বাত মন্ডল,মন্ডল বাড়ি,চান্দের হাওড়া,০১৭৭২৫৬০১৯১,farmer,Illiterate,২৭.০০,১৫.০০,others,inheritance,,did_not_get_from_tafshil,inheritance,generations,inheritance,no,yes,no,no,yes,no,4,8,no,no,,,,,Customary,a few notes,3913647224167,24.848364999999998 89.83268500000001 -50.4 4.9,24.848365,89.832685,-50.4,4.9,,,2016-02-08T12:45:10.187+06,2016-02-08T12:53:02.738+06,2016-02-08,355335064140032,470034501263565,8988034503012635653f,,uuid:68e07841-0eb3-4960-bb5e-bbfffa0b609d,5349258,68e07841-0eb3-4960-bb5e-bbfffa0b609d,2016-02-09T11:30:57,10,,-1,,,201602060307,472,arifuttaran
86 changes: 82 additions & 4 deletions cadasta/organization/tests/test_views_default_projects.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
from party.models import Party, TenureRelationship
from party.tests.factories import PartyFactory
from questionnaires.models import Questionnaire
from questionnaires.tests.factories import QuestionnaireFactory
from questionnaires.tests import factories as q_factories
from questionnaires.messages import MISSING_RELEVANT
from resources.models import Resource
from resources.tests.factories import ResourceFactory
Expand Down Expand Up @@ -953,8 +953,8 @@ class ProjectEditDetailsTest(ViewTestCase, UserTestCase,

def setup_models(self):
self.project = ProjectFactory.create(current_questionnaire='abc')
self.questionnaire = QuestionnaireFactory.create(project=self.project,
id='abc')
self.questionnaire = q_factories.QuestionnaireFactory.create(
project=self.project, id='abc')

def setup_url_kwargs(self):
return {
Expand Down Expand Up @@ -1006,7 +1006,8 @@ def test_get_with_blocked_questionnaire_upload(self):
assert 'Select the questionnaire' not in self.expected_content

def test_get_with_authorized_user_include_questionnaire(self):
questionnaire = QuestionnaireFactory.create(project=self.project)
questionnaire = q_factories.QuestionnaireFactory.create(
project=self.project)
user = UserFactory.create()
assign_policies(user)

Expand Down Expand Up @@ -1483,6 +1484,7 @@ def setUp(self):
)

self.valid_csv = '/organization/tests/files/test.csv'
self.valid_csv_custom = '/organization/tests/files/test_custom.csv'
self.invalid_csv = '/organization/tests/files/test_invalid.csv'
self.geoshape_csv = '/organization/tests/files/test_geoshape.csv'
self.geotrace_csv = '/organization/tests/files/test_geotrace.csv'
Expand Down Expand Up @@ -1654,6 +1656,82 @@ def test_full_flow_valid(self):
assert random_filename.endswith('.csv')
assert len(random_filename.split('.')[0].strip('/')) == 24

def test_full_flow_valid_custom_types(self):
questionnaire = q_factories.QuestionnaireFactory.create(
project=self.project)
question = q_factories.QuestionFactory.create(
type='S1',
name='tenure_type',
questionnaire=questionnaire)
q_factories.QuestionOptionFactory.create(
question=question,
name='AA',
label='AA Label')
question = q_factories.QuestionFactory.create(
type='S1',
name='location_type',
questionnaire=questionnaire)
q_factories.QuestionOptionFactory.create(
question=question,
name='BB',
label='BB Label')

self.client.force_login(self.user)
csvfile = self.get_file(self.valid_csv_custom, 'rb')
file = SimpleUploadedFile('test_custom.csv', csvfile, 'text/csv')
post_data = self.SELECT_FILE_POST_DATA.copy()
post_data['select_file-file'] = file
post_data['select_file-is_resource'] = True
select_file_response = self.client.post(
reverse('organization:project-import',
kwargs={
'organization': self.org.slug,
'project': self.project.slug}),
post_data
)
assert select_file_response.status_code == 200

map_attributes_response = self.client.post(
reverse('organization:project-import',
kwargs={
'organization': self.org.slug,
'project': self.project.slug}),
self.MAP_ATTRIBUTES_POST_DATA
)
assert map_attributes_response.status_code == 200

select_defaults_response = self.client.post(
reverse('organization:project-import',
kwargs={
'organization': self.org.slug,
'project': self.project.slug}),
self.SELECT_DEFAULTS_POST_DATA
)
assert select_defaults_response.status_code == 302

assert ('/organizations/test-org/projects/test-imports/' in
select_defaults_response['location'])

proj = Project.objects.get(
organization=self.org, name='Test Imports')
assert Party.objects.filter(project_id=proj.pk).count() == 10
assert SpatialUnit.objects.filter(project_id=proj.pk).count() == 10
assert Resource.objects.filter(project_id=proj.pk).count() == 1
assert TenureRelationship.objects.filter(
project_id=proj.pk).count() == 10

for su in SpatialUnit.objects.filter(project_id=proj.pk).all():
if su.geometry is not None:
assert type(su.geometry) is Point

# test resource creation
resource = Resource.objects.filter(project_id=proj.pk).first()
assert resource.original_file == 'test_custom.csv'
assert resource.mime_type == 'text/csv'
random_filename = resource.file.url[resource.file.url.rfind('/'):]
assert random_filename.endswith('.csv')
assert len(random_filename.split('.')[0].strip('/')) == 24

def test_full_flow_valid_xls(self):
mime = 'application/vnd.openxmlformats-'
'officedocument.spreadsheetml.sheet'
Expand Down
4 changes: 2 additions & 2 deletions cadasta/organization/views/default.py
Original file line number Diff line number Diff line change
Expand Up @@ -874,11 +874,11 @@ def done(self, form_list, **kwargs):
project = self.get_project()
org = project.organization
allowed_tenure_types = get_types(
'tenure_types',
'tenure_type',
TENURE_RELATIONSHIP_TYPES,
questionnaire_id=project.current_questionnaire)
allowed_location_types = get_types(
'location_types',
'location_type',
TYPE_CHOICES,
questionnaire_id=project.current_questionnaire)

Expand Down
2 changes: 1 addition & 1 deletion cadasta/party/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ class Meta:

def validate_tenure_type(self, value):
prj = self.context['project']
allowed_types = get_types('tenure_types',
allowed_types = get_types('tenure_type',
TENURE_RELATIONSHIP_TYPES,
questionnaire_id=prj.current_questionnaire)

Expand Down
57 changes: 57 additions & 0 deletions cadasta/party/tests/test_serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

from core.tests.utils.cases import UserTestCase
from organization.tests.factories import ProjectFactory
from questionnaires.tests import factories as q_factories
from spatial.tests.factories import SpatialUnitFactory
from party import serializers

Expand Down Expand Up @@ -51,6 +52,33 @@ def test_valid_tenure_type(self):
context={'project': project})
assert serializer.is_valid() is True

def test_valid_custom_tenure_type(self):
project = ProjectFactory.create()

questionnaire = q_factories.QuestionnaireFactory.create(
project=project)
question = q_factories.QuestionFactory.create(
type='S1',
name='tenure_type',
questionnaire=questionnaire)
q_factories.QuestionOptionFactory.create(
question=question,
name='FU',
label='FU Label')

su = SpatialUnitFactory.create(project=project)
party = PartyFactory.create(project=project)
data = {
'tenure_type': 'FU',
'spatial_unit': su.id,
'party': party.id
}

serializer = serializers.TenureRelationshipWriteSerializer(
data=data,
context={'project': project})
assert serializer.is_valid() is True

def test_invalid_tenure_type(self):
project = ProjectFactory.create()
su = SpatialUnitFactory.create(project=project)
Expand All @@ -67,3 +95,32 @@ def test_invalid_tenure_type(self):
assert serializer.is_valid() is False
assert ("'BOO' is not a valid choice for field 'tenure_type'." in
serializer.errors['tenure_type'])

def test_invalid_custom_tenure_type(self):
project = ProjectFactory.create()

questionnaire = q_factories.QuestionnaireFactory.create(
project=project)
question = q_factories.QuestionFactory.create(
type='S1',
name='tenure_type',
questionnaire=questionnaire)
q_factories.QuestionOptionFactory.create(
question=question,
name='FU',
label='FU Label')

su = SpatialUnitFactory.create(project=project)
party = PartyFactory.create(project=project)
data = {
'tenure_type': 'FH',
'spatial_unit': su.id,
'party': party.id
}

serializer = serializers.TenureRelationshipWriteSerializer(
data=data,
context={'project': project})
assert serializer.is_valid() is False
assert ("'FH' is not a valid choice for field 'tenure_type'." in
serializer.errors['tenure_type'])
Loading

0 comments on commit 5460f1a

Please sign in to comment.