def test_skips_empty_cell(self, mocked_setvalue): """If a cell isn't filled in, skip it.""" inputfield = InputFieldF.build(destination_table="Scenario", type=InputField.TYPE_INTEGER) cell = MockCell(value="") header = self.build_header(inputfield) eie.import_scenario_row(header, 66, self.rowstart + [cell], self.allowed_ids) self.assertFalse(mocked_setvalue.called)
def test_skips_ignored_inputfield(self, mocked_setvalue): """Some destination tables, e.g. Project, can't be modified from this import and should be skipped.""" inputfield = InputFieldF.build(destination_table="Project", type=InputField.TYPE_INTEGER) cell = MockCell(value=3) header = self.build_header(inputfield) eie.import_scenario_row(header, 66, self.rowstart + [cell], self.allowed_ids) self.assertFalse(mocked_setvalue.called)
def test_skips_empty_cell(self, mocked_setvalue): """If a cell isn't filled in, skip it.""" inputfield = InputFieldF.build(destination_table='Scenario', type=InputField.TYPE_INTEGER) cell = MockCell(value=u'') header = self.build_header(inputfield) eie.import_scenario_row(header, 66, self.rowstart + [cell], self.allowed_ids) self.assertFalse(mocked_setvalue.called)
def test_skips_ignored_inputfield(self, mocked_setvalue): """Some destination tables, e.g. Project, can't be modified from this import and should be skipped.""" inputfield = InputFieldF.build(destination_table='Project', type=InputField.TYPE_INTEGER) cell = MockCell(value=3) header = self.build_header(inputfield) eie.import_scenario_row(header, 66, self.rowstart + [cell], self.allowed_ids) self.assertFalse(mocked_setvalue.called)
def test_some_inputfield(self, mocked_setvalue): """Test with an integer inputfield and see what happens.""" inputfield = InputFieldF.build(destination_table="scenario", type=InputField.TYPE_INTEGER) cell = MockCell(value=3) header = self.build_header(inputfield) eie.import_scenario_row(header, 66, self.rowstart + [cell], self.allowed_ids) self.assertTrue(mocked_setvalue.called) c_inputfield, c_value = mocked_setvalue.call_args[0] self.assertTrue(c_inputfield is inputfield) self.assertTrue(isinstance(c_value, IntegerValue))
def test_empty_scenario_id(self): """Should give an error message mentioning the row nr""" errors = eie.import_scenario_row(eie.ImportedHeader(), 66, [mock.MagicMock(value="")], set()) self.assertEquals(len(errors), 1) self.assertTrue("66" in errors[0])
def test_unknown_scenario_id(self): """Tests that using a nonexisting scenario id results in an error, and that the error message includes the line number.""" errors = eie.import_scenario_row(eie.ImportedHeader(), 66, [mock.MagicMock(value=42313)], set()) self.assertEquals(len(errors), 1) self.assertTrue("66" in errors[0])
def test_empty_scenario_id(self): """Should give an error message mentioning the row nr""" errors = eie.import_scenario_row( eie.ImportedHeader(), 66, [mock.MagicMock(value="")], set()) self.assertEquals(len(errors), 1) self.assertTrue("66" in errors[0])
def test_bad_scenario_id(self): """Tests that a row with a badly formed scenario id returns an error, and that the error message includes the line number.""" errors = eie.import_scenario_row(eie.ImportedHeader(), 66, [mock.MagicMock(value="scenarioid")], set()) self.assertEquals(len(errors), 1) self.assertTrue("66" in errors[0])
def test_some_inputfield(self, mocked_setvalue): """Test with an integer inputfield and see what happens.""" inputfield = InputFieldF.build(destination_table='scenario', type=InputField.TYPE_INTEGER) cell = MockCell(value=3) header = self.build_header(inputfield) eie.import_scenario_row(header, 66, self.rowstart + [cell], self.allowed_ids) self.assertTrue(mocked_setvalue.called) c_inputfield, c_value = mocked_setvalue.call_args[0] self.assertTrue(c_inputfield is inputfield) self.assertTrue(isinstance(c_value, IntegerValue))
def test_disallowed_scenario_id(self): """Tests that using a scenario id that exists but isn't in allowed scenario id fails.""" scenario = ScenarioF.create() allowed_ids = set((scenario.id + 1,)) errors = eie.import_scenario_row(eie.ImportedHeader(), 66, [mock.MagicMock(value=scenario.id)], allowed_ids) self.assertEquals(len(errors), 1) self.assertTrue("66" in errors[0])
def test_disallowed_scenario_id(self): """Tests that using a scenario id that exists but isn't in allowed scenario id fails.""" scenario = ScenarioF.create() allowed_ids = set((scenario.id + 1, )) errors = eie.import_scenario_row(eie.ImportedHeader(), 66, [mock.MagicMock(value=scenario.id)], allowed_ids) self.assertEquals(len(errors), 1) self.assertTrue("66" in errors[0])
def test_wrong_value_raises_error(self): """A nonsensical value in a cell returns an error message.""" inputfield = InputFieldF.build(destination_table="scenario", type=InputField.TYPE_INTEGER) cell = MockCell(value="whee") header = self.build_header(inputfield) errors = eie.import_scenario_row(header, 66, self.rowstart + [cell], self.allowed_ids) self.assertEquals(len(errors), 1) self.assertTrue("66" in errors[0])
def test_wrong_value_raises_error(self): """A nonsensical value in a cell returns an error message.""" inputfield = InputFieldF.build(destination_table='scenario', type=InputField.TYPE_INTEGER) cell = MockCell(value="whee") header = self.build_header(inputfield) errors = eie.import_scenario_row(header, 66, self.rowstart + [cell], self.allowed_ids) self.assertEquals(len(errors), 1) self.assertTrue("66" in errors[0])
def test_empty_row(self): """Shouldn't really do anything, just return""" errors = eie.import_scenario_row(eie.ImportedHeader(), 5, [], set()) self.assertEquals(errors, [])