def test_headers_from_inputfields_first_empty(self): with mock.patch( 'flooding_lib.excel_import_export.FieldInfo.headers_from_inputfields', return_value=()): fields = list(eie.FieldInfo([]).headers()) self.assertEquals(fields[0]['headername'], '') self.assertEquals(fields[0]['fieldname'], '') self.assertEquals(fields[0]['fieldtype'], '')
def test_add_extra_header_fields_name(self): """header['fieldname'] should be equal to the field's name.""" inputfield = InputFieldF(name='test 123') fieldinfo = eie.FieldInfo([]) header = fieldinfo.add_extra_header_fields({'inputfield': inputfield}) self.assertEquals(header['fieldname'], 'test 123')
def test_add_extra_header_fields_hint(self): """header['fieldhint'] should be equal to the field's excel hint.""" inputfield = InputFieldF(excel_hint='test 123') fieldinfo = eie.FieldInfo([]) header = fieldinfo.add_extra_header_fields({'inputfield': inputfield}) self.assertEquals(header['fieldhint'], 'test 123')
def test_add_extra_header_fields_type_date(self): """header['fieldtype'] should be equal to a specific string in case the inputfield's type is TYPE_DATE.""" inputfield = InputFieldF(type=InputField.TYPE_DATE, destination_table='Scenario') fieldinfo = eie.FieldInfo([]) header = fieldinfo.add_extra_header_fields({'inputfield': inputfield}) self.assertEquals(header['fieldtype'], u'Datum (DD/MM/JJJJ)')
def test_add_extra_header_fields_type_ignored(self): """If an inputfield is ignored, we place a notice in the type field""" inputfield = InputFieldF(type=InputField.TYPE_DATE, destination_table='Project') fieldinfo = eie.FieldInfo([]) header = fieldinfo.add_extra_header_fields({'inputfield': inputfield}) # Field type contains a text within ( ) self.assertTrue(header['fieldtype'].startswith('(') and header['fieldtype'].endswith(')'))
def test_add_extra_header_fields_type(self): """header['fieldtype'] should be equal to the translated version of the choice's description.""" activate('nl') inputfield = InputFieldF(type=InputField.TYPE_STRING, destination_table='Scenario') fieldinfo = eie.FieldInfo([]) header = fieldinfo.add_extra_header_fields({'inputfield': inputfield}) self.assertEquals(header['fieldtype'], u'Tekst') deactivate()
def test_headers_calls_methods(self): header = object() mock_add_extra_header_fields = mock.MagicMock(return_value="whee") with mock.patch( 'flooding_lib.excel_import_export.FieldInfo.headers_from_inputfields', return_value=iter((header, ))): with mock.patch( 'flooding_lib.excel_import_export.FieldInfo.add_extra_header_fields', new=mock_add_extra_header_fields): fields = list(eie.FieldInfo([]).headers()) # Check fields[1], because fields[0] is the empty header self.assertEquals(fields[1], "whee") mock_add_extra_header_fields.assert_called_with(header)
def test_headers_from_inputfields(self): """Test that it uses the headers from grouped_input_fields().""" inputfield = InputFieldF.build(name="testfield") grouped_input_fields = [{ 'id': 1, 'title': 'testheader', 'fields': [inputfield] }] with mock.patch( 'flooding_lib.tools.importtool.models.InputField.grouped_input_fields', return_value=grouped_input_fields): fieldinfo = eie.FieldInfo([]) headers = list(fieldinfo.headers_from_inputfields()) self.assertEquals(len(headers), 1) self.assertEquals(headers[0]['headername'], 'testheader') self.assertEquals(headers[0]['inputfield'], inputfield)
def test_rows(self): mockscenariorow = mock.MagicMock(return_value="whee") with mock.patch('flooding_lib.excel_import_export.FieldInfo.headers', return_value=()): with mock.patch('flooding_lib.excel_import_export.ScenarioRow', new=mockscenariorow): fieldinfo = eie.FieldInfo([]) fieldinfo.scenariolist = ["scenario"] rows = list(fieldinfo.rows()) # Rows[0] is equal to a ScenarioRow (turned into the # string "whee" by us) self.assertEquals(rows[0], "whee") # The ScenarioRow was constructed with the first # scenario in scenariolist, again set to use a string # by us, and the value of headers, an empty tuple: mockscenariorow.assert_called_with("scenario", ())
def test_scenarios(self): scenario = ScenarioF.build() fieldinfo = eie.FieldInfo([scenario]) for s in fieldinfo.scenarios(): self.assertTrue(s is scenario)