Tests pass, woohoo

This commit is contained in:
Anna Sidwell 2018-12-02 01:10:12 +00:00
parent 0a47ea3724
commit 73a746d83e
2 changed files with 48 additions and 38 deletions

View File

@ -15,6 +15,32 @@ from .models import CaseStudy, SpatialRefSys, PointOfInterest
from .widgets import JSONFileListWidget
SECTOR_HELP = {
'RN': _("including electricity, heat or combined heat and power generation"),
'PG': '',
'ST': _('Biological, chemical, electrical, electromagnetic, electrochemical, mechanical including gravitational potential, thermal etc.'),
'SM': _("including supply of minerals"),
'MA': '',
}
POWER_TECHNOLOGY_HELP = {
'PT': _('Lines, transformers, machinery etc.'),
'HN': _('District heating/cooling, etc.'),
'OT': '',
}
def add_explanatory_text(model_choices, explanatory_text):
return [
(
choice[0],
mark_safe('<b>%s</b><br><span class="text-muted">%s</span>' %
(choice[1], explanatory_text[choice[0]])
)
) for choice in model_choices
]
class MinimumZoomWidget(LeafletWidget):
geometry_field_class = 'MinimumZoomField'
@ -87,6 +113,16 @@ class ShortCaseStudyForm(BaseCaseStudyForm):
self.helper.form_action = reverse('short-form')
self.helper.add_input(Submit('submit', _('Submit'), css_class='btn-success center-block'))
# Duplicate code from long form, below...
self.fields['sector_of_economy'] = forms.ChoiceField(
widget=forms.RadioSelect(),
choices=add_explanatory_text(
CaseStudy.SECTOR_CHOICES,
SECTOR_HELP
),
required=False
)
class Meta(BaseCaseStudyForm.Meta):
fields = [
'entry_name',
@ -176,32 +212,6 @@ class LongCaseStudyForm(BaseCaseStudyForm):
initial=4326,
)
SECTOR_HELP = {
'RN': _("including electricity, heat or combined heat and power generation"),
'PG': '',
'ST': _('Biological, chemical, electrical, electromagnetic, electrochemical, mechanical including gravitational potential, thermal etc.'),
'SM': _("including supply of minerals"),
'MA': '',
}
POWER_TECHNOLOGY_HELP = {
'PT': _('Lines, transformers, machinery etc.'),
'HN': _('District heating/cooling, etc.'),
'OT': '',
}
# TODO: Allow explanatory_text to not contain text for every option
# TODO: Only output <span> if there is explanatory text
def add_explanatory_text(self, model_choices, explanatory_text):
return [
(
choice[0],
mark_safe('<b>%s</b><br><span class="text-muted">%s</span>' %
(choice[1], explanatory_text[choice[0]])
)
) for choice in model_choices
]
def __init__(self, *args, **kwargs):
super(LongCaseStudyForm, self).__init__(*args, **kwargs)
@ -210,18 +220,18 @@ class LongCaseStudyForm(BaseCaseStudyForm):
self.fields['sector_of_economy'] = forms.ChoiceField(
widget=forms.RadioSelect(),
choices=self.add_explanatory_text(
choices=add_explanatory_text(
CaseStudy.SECTOR_CHOICES,
self.SECTOR_HELP
SECTOR_HELP
),
required=False
)
self.fields['power_technology'] = forms.ChoiceField(
widget=forms.RadioSelect(),
choices=self.add_explanatory_text(
choices=add_explanatory_text(
CaseStudy.POWER_TECHNOLOGY_CHOICES,
self.POWER_TECHNOLOGY_HELP
POWER_TECHNOLOGY_HELP
),
required=False
)

View File

@ -119,14 +119,14 @@ class MapTest(SeleniumTest):
self.sl.find_element_by_id('id_entry_name').send_keys('Short Entry');
Select(self.sl.find_element_by_id('id_country')).select_by_visible_text('Albania');
self.sl.find_element_by_id('id_area_of_land').send_keys('123');
Select(self.sl.find_element_by_id('id_land_ownership')).select_by_visible_text('Private Land');
Select(self.sl.find_element_by_id('id_land_ownership')).select_by_visible_text('Private land');
Select(self.sl.find_element_by_id('id_location_context')).select_by_visible_text('Urban');
self.sl.find_element_by_id('id_describe_ecosystem').send_keys('test');
Select(self.sl.find_element_by_id('id_project_status')).select_by_visible_text('Existing Project');
Select(self.sl.find_element_by_id('id_sector_of_economy')).select_by_visible_text('Power Grids');
Select(self.sl.find_element_by_id('id_project_status')).select_by_visible_text('In planning and design');
self.sl.find_element_by_css_selector('[name=sector_of_economy][value=ST]').click()
self.sl.find_element_by_id('id_synopsis').send_keys('test');
self.sl.find_element_by_id('id_full_description').send_keys('test');
Select(self.sl.find_element_by_id('id_positive_or_negative')).select_by_visible_text('Positive');
Select(self.sl.find_element_by_id('id_positive_or_negative')).select_by_visible_text('There is/was an organising process in favour of the project');
# you can submit the form on any field. Using this one because the submit button sometimes isn't visible
self.sl.find_element_by_id('id_area_of_land').submit();
self.assertTrue("Thanks!" in self.sl.page_source, "Success message not shown")
@ -140,18 +140,18 @@ class MapTest(SeleniumTest):
self.sl.find_element_by_id('id_entry_name').send_keys('Long Entry');
Select(self.sl.find_element_by_id('id_country')).select_by_visible_text('Albania');
self.sl.find_element_by_id('id_area_of_land').send_keys('123');
Select(self.sl.find_element_by_id('id_land_ownership')).select_by_visible_text('Private Land');
Select(self.sl.find_element_by_id('id_land_ownership')).select_by_visible_text('Private land');
Select(self.sl.find_element_by_id('id_location_context')).select_by_visible_text('Urban');
self.sl.find_element_by_id('id_describe_ecosystem').send_keys('test');
Select(self.sl.find_element_by_id('id_project_status')).select_by_visible_text('Existing Project');
Select(self.sl.find_element_by_id('id_project_status')).select_by_visible_text('In planning and design');
self.sl.find_element_by_id('id_synopsis').send_keys('test');
self.sl.find_element_by_id('id_full_description').send_keys('test');
self.sl.find_element_by_id('id_project_owners').send_keys('test');
self.sl.find_element_by_id('id_shareholders').send_keys('test');
self.sl.find_element_by_css_selector('a[href="#technical-and-economic-analysis"]').click()
Select(self.sl.find_element_by_id('id_sector_of_economy')).select_by_visible_text('Power Grids');
self.sl.find_element_by_css_selector('[name=sector_of_economy][value=ST]').click()
self.sl.find_element_by_css_selector('a[href="#socio-environmental-analysis"]').click()
Select(self.sl.find_element_by_id('id_positive_or_negative')).select_by_visible_text('Positive');
Select(self.sl.find_element_by_id('id_positive_or_negative')).select_by_visible_text('There is/was an organising process in favour of the project');
self.sl.find_element_by_css_selector('a[href="#uploads"]').click()
# you can submit the form on any field. Using this one because the submit button sometimes isn't visible
self.sl.find_element_by_id('id_name_of_territory_or_area').submit();