def test_get_monthly_rejects__density_returns_none_if_no_result(self): self.setup_test_data() municipality = Municipality.get(Municipality.name == "Mukono") rejects_landfilled = DailyRejectsLandfilled( date=date(2012, 1, 1), municipality_submission=MunicipalitySubmission( municipality=municipality ) ) self.assertIsNone(rejects_landfilled.get_monthly_rejects_density())
def test_volume(self): leachete_register = LeacheteMonthlyRegister( json_data={ 'before_pumping/fbHeight_be4_pumping': '12.3', 'after_pumping/fbHeight_after_pumping': '5.6' }) municipality = Municipality( leachete_tank_length=4.0, leachete_tank_width=3.0) self.assertAlmostEqual( leachete_register.volume(municipality), 80.4)
def test_weight_calculation_returns_bagged_weight_if_bagged(self): self.setup_test_data() municipality = Municipality.get(Municipality.name == "Mukono") compost_sale = CompostSalesRegister( date=datetime.datetime(2013, 01, 01), json_data={ 'bagged_compost': 'yes', 'bagged_compost_weight': '1.5' }, municipality_submission=MunicipalitySubmission( municipality=municipality)) weight = compost_sale.weight() self.assertEqual(weight, 1.5)
def test_get_compost_density_returns_none_if_no_density_record(self): self.setup_test_data() municipality = Municipality.get(Municipality.name == "Mukono") compost_sale = CompostSalesRegister(date=datetime.datetime( 2013, 01, 01), json_data={ 'bagged_compost': 'no', 'compost_length': '3.0', 'compost_width': '4.0', 'compost_height': '5.0' }) compost_density = compost_sale.get_compost_density(municipality) self.assertIsNone(compost_density)
def test_weight_calculation_returns_none_if_density_is_none(self): self.setup_test_data() municipality = Municipality.get(Municipality.name == "Mukono") compost_sale = CompostSalesRegister( date=datetime.datetime(2013, 01, 01), json_data={ 'bagged_compost': 'no', 'compost_length': '3.0', 'compost_width': '4.0', 'compost_height': '5.0' }, municipality_submission=MunicipalitySubmission( municipality=municipality)) weight = compost_sale.weight() self.assertIsNone(weight)
def test_get_compost_density_returns_only_if_approved(self): self.setup_test_data() municipality = Municipality.get(Municipality.name == "Mukono") compost_density = CompostDensityRegister.get( CompostDensityRegister.date == datetime.date(2014, 5, 1)) compost_density.status = Submission.APPROVED compost_sale = CompostSalesRegister(date=datetime.datetime( 2014, 05, 01), json_data={ 'bagged_compost': 'no', 'compost_length': '3.0', 'compost_width': '4.0', 'compost_height': '5.0' }) compost_density = compost_sale.get_compost_density(municipality) self.assertIsInstance(compost_density, CompostDensityRegister)
def setUp(self): super(TestHelpersIntegration, self).setUp() self.setup_test_data() municipality_id = Municipality.get(Municipality.name == "Mukono").id self.context = DailyWaste( xform_id=DailyWaste.XFORM_ID, status=Submission.PENDING, # add dummy json data for volume calculation date=date(2014, 6, 13), json_data={ 'compressor_truck': 'yes', 'volume': '20' }, municipality_submission=MunicipalitySubmission( municipality_id=municipality_id)) self.request = testing.DummyRequest()
def test_renderer_output(self): self.setup_test_data() request = testing.DummyRequest() renderer = TablibXLSXRenderer({}) municipality = Municipality.all()[0] data = { 'municipality': municipality, 'start': datetime.date(2014, 6, 1), 'end': datetime.date(2014, 6, 30) } renderer(data, {'request': request}) self.assertEqual( request.response.content_type, 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet' ) # noqa
def test_volume_calculation(self): self.setup_test_data() with transaction.manager: DBSession.query(MonthlyRejectsDensity).update({ 'status': Submission.APPROVED }) municipality = Municipality.get(Municipality.name == "Mukono") rejects_landfilled = DailyRejectsLandfilled( date=date(2014, 6, 13), json_data={ 'barrows_number_frm_sieving': '10' }, municipality_submission=MunicipalitySubmission( municipality=municipality ) ) self.assertEqual(rejects_landfilled.volume(), 6.25)
def test_get_monthly_rejects_density_returns_none_if_exists(self): self.setup_test_data() with transaction.manager: DBSession.query(MonthlyRejectsDensity).update({ 'status': Submission.APPROVED }) municipality = Municipality.get(Municipality.name == "Mukono") rejects_landfilled = DailyRejectsLandfilled( date=date(2014, 6, 13), municipality_submission=MunicipalitySubmission( municipality=municipality ) ) monthly_rejects_landfilled = rejects_landfilled\ .get_monthly_rejects_density() self.assertIsInstance(monthly_rejects_landfilled, MonthlyRejectsDensity)
def test_create_or_update_report(self): self.setup_test_data() with transaction.manager: DBSession.query(MonthlyRejectsDensity).update({ 'status': Submission.APPROVED }) municipality = Municipality.get(Municipality.name == "Mukono") rejects_landfilled = DailyRejectsLandfilled( date=date(2014, 6, 13), json_data={ 'barrows_number_frm_sieving': '10' }, municipality_submission=MunicipalitySubmission( municipality=municipality ) ) report = rejects_landfilled.create_or_update_report() self.assertEqual(report.report_json, { 'volume': 6.25, 'tonnage': 1.7999999999999998 })
def test_weight_calculation(self): self.setup_test_data() municipality = Municipality.get(Municipality.name == "Mukono") compost_density = CompostDensityRegister.get( CompostDensityRegister.date >= datetime.date(2014, 5, 1), CompostDensityRegister.date <= datetime.date(2014, 5, 31)) compost_density.status = Submission.APPROVED with transaction.manager: DBSession.add(compost_density) compost_sale = CompostSalesRegister( date=datetime.datetime(2014, 05, 01), json_data={ 'bagged_compost': 'no', 'compost_length': '3.0', 'compost_width': '4.0', 'compost_height': '5.0' }, municipality_submission=MunicipalitySubmission( municipality=municipality)) weight = compost_sale.weight() self.assertAlmostEqual(weight, 864.0 / 1000) # div to convert to tonnes
def setUp(self): super(TestMunicipalitySubmission, self).setUp() self.setup_test_data() self.municipality = Municipality.get(Municipality.name == "Mukono")
def setUp(self): super(TestElectricityRegister, self).setUp() self.setup_test_data() self.municipality = Municipality.get(Municipality.name == "Mukono")
def setUp(self): super(TestWindrowMonitoringsFunctional, self).setUp() self.setup_test_data() self.municipality = Municipality.get(Municipality.name == "Mukono")
def municipality_widget(node, kw): # start with a blank municipalities = [('', '')] municipalities.extend([(m.id, m.name) for m in Municipality.all()]) return SelectWidget(values=municipalities)
def setUp(self): super(TestMonthlyRejectsComposition, self).setUp() self.setup_test_data() self.municipality = Municipality.get(Municipality.name == "Mukono")
def setUp(self): super(TestCompostDensityRegisterWithTestData, self).setUp() self.setup_test_data() self.municipality = Municipality.get(Municipality.name == "Mukono")
def setUp(self): super(TestMonthlyDensity, self).setUp() self.setup_test_data() self.municipality = Municipality.get(Municipality.name == "Mukono")