Ejemplo n.º 1
0
 def test_update(self):
     m = Municipality(name="Test Municipal",
                      box_volume=0.125,
                      wheelbarrow_volume=0.625,
                      leachete_tank_length=5.0,
                      leachete_tank_width=5.0)
     m.update(name="Another Test Municipal",
              box_volume=0.3,
              wheelbarrow_volume=0.15,
              leachete_tank_length=8.0,
              leachete_tank_width=6.0)
     self.assertEqual(m.name, "Another Test Municipal")
     self.assertEqual(m.box_volume, 0.3)
     self.assertEqual(m.wheelbarrow_volume, 0.15)
     self.assertEqual(m.leachete_tank_length, 8.0)
     self.assertEqual(m.leachete_tank_width, 6.0)
Ejemplo n.º 2
0
    def test_create_profile_post(self):
        initial_count = Municipality.count()
        self.request.method = 'POST'
        self.request.user = User()
        self.request.POST = MultiDict([
            ('name', 'Arua Compost Plant'),
            ('wheelbarrow_volume', '0.15'),
            ('box_volume', '0.3'),
            ('leachete_tank_length', '8.0'),
            ('leachete_tank_width', '8.0')
        ])
        result = self.views.create_profile()

        self.assertIsInstance(result, HTTPFound)

        final_count = Municipality.count()
        self.assertEqual(final_count, initial_count + 1)
Ejemplo n.º 3
0
    def test_quantity_of_compost_sold(self):
        self.populate_compost_density()
        self.populate_compost_sales_register()

        self.municipality = Municipality.get(Municipality.name == "Mukono")
        start = datetime.date(2014, 5, 1)
        end = datetime.date(2014, 6, 30)
        self.assertAlmostEqual(
            self.municipality.quantity_of_compost_sold(start, end), 1.38576)
Ejemplo n.º 4
0
 def test_raises_invalid_for_existing_if_skip_type_already_exists(self):
     """
     If the skip type exists in the municipality and its not the skip
     type we're trying to edit, raise
     """
     municipality = Municipality.get(Municipality.name == "Mukono")
     # use zero as the other skip id
     validator = UniqueSkipTypeValidator(municipality.id, 0)
     self.assertRaises(colander.Invalid, validator.__call__, {}, 'A')
Ejemplo n.º 5
0
    def setup_test_data(self):

        admin = User(id=1,
                     username='******',
                     password='******',
                     active=True,
                     group='nema')
        municipality = Municipality(name="Mukono")
        other_municipality = Municipality(name="Jinja")
        manager = User(id=2,
                       username='******',
                       password='******',
                       active=True,
                       group='sm',
                       municipality=municipality)
        other_manager = User(id=3,
                             username='******',
                             password='******',
                             active=True,
                             group='sm',
                             municipality=other_municipality)
        skip_a = Skip(municipality=municipality,
                      skip_type='A',
                      small_length=20,
                      large_length=30,
                      small_breadth=10,
                      large_breadth=16)
        skip_b = Skip(municipality=municipality,
                      skip_type='B',
                      small_length=20,
                      large_length=30,
                      small_breadth=10,
                      large_breadth=16)
        submission_handler_manager.clear()
        hook_submission_handlers()
        with transaction.manager:
            DBSession.add_all(
                [admin, manager, municipality, skip_a, skip_b, other_manager])
            for status, raw_json in self.submissions:
                json_payload = json.loads(raw_json)
                handler_class = submission_handler_manager.find_handler(
                    json_payload)
                handler_class().__call__(json_payload, status=status)
Ejemplo n.º 6
0
    def test_count_of_vehicles_transporting_compost(self):
        start = datetime.date(2014, 5, 1)
        end = datetime.date(2014, 6, 30)

        vehicle_count = self.municipality.vehicle_count(start, end)
        self.assertEqual(vehicle_count, 0)
        self.populate_compost_density()
        self.populate_compost_sales_register()

        self.municipality = Municipality.get(Municipality.name == "Mukono")
        vehicle_count = self.municipality.vehicle_count(start, end)
        self.assertEqual(vehicle_count, 2)
Ejemplo n.º 7
0
 def list(self):
     # if doest have list permissions, determine the user's municipality and
     # redirect, if we cant determine, their municipality, throw a 403
     if not self.request.has_permission('manage', self.request.context):
         municipality = self.request.user.municipality
         if municipality:
             return HTTPFound(
                 self.request.route_url('municipalities',
                                        traverse=(municipality.id, )))
         else:
             return HTTPForbidden(
                 "You don't have permissions to access this page and you do"
                 " not belong to any Municipality")
     municipalities = Municipality.all()
     return {'municipalities': municipalities}
Ejemplo n.º 8
0
    def create_profile(self):
        user = self.request.user

        form = Form(SiteProfileForm().bind(request=self.request),
                    buttons=('Save', Button(name='cancel', type='button')))

        if self.request.method == "POST":
            data = self.request.POST.items()
            try:
                values = form.validate(data)
            except ValidationFailure:
                self.request.session.flash(
                    u"Please fix the errors indicated below.", "error")
            else:
                municipality = Municipality(**values)
                municipality.save()
                user.municipality = municipality
                self.request.session.flash(u"Your changes have been saved.",
                                           "success")
                return HTTPFound(
                    self.request.route_url('municipalities',
                                           traverse=(municipality.id,
                                                     'profile')))
        return {'form': form}
Ejemplo n.º 9
0
 def test_edit_profile_post(self):
     municipality_id = self.municipality.id
     self.request.context = self.municipality
     self.request.method = 'POST'
     self.request.POST = MultiDict([
         ('name', 'Mukono Municipality'),
         ('wheelbarrow_volume', '0.15'),
         ('box_volume', '0.3'),
         ('leachete_tank_length', '8.0'),
         ('leachete_tank_width', '8.0')
     ])
     result = self.views.edit_profile()
     self.assertIsInstance(result, HTTPFound)
     self.assertEqual(
         result.location,
         self.request.route_url(
             'municipalities', traverse=(municipality_id, 'profile')))
     municipality = Municipality.get(Municipality.id == municipality_id)
     self.assertEqual(municipality.name, "Mukono Municipality")
Ejemplo n.º 10
0
 def test_create_skip_post(self):
     self.request.context = self.municipality
     self.request.method = 'POST'
     self.request.POST = MultiDict([
         ('skip_type', 'Z'),
         ('small_length', '20'),
         ('large_length', '30'),
         ('small_breadth', '16'),
         ('large_breadth', '20')
     ])
     num_skips = Skip.count()
     result = self.views.create_skip()
     self.assertIsInstance(result, HTTPFound)
     self.assertEqual(Skip.count(), num_skips + 1)
     skip = Skip.newest()
     self.assertEqual(
         result.location,
         self.request.route_url('skips', traverse=(skip.id, 'edit')))
     municipality = Municipality.get(Municipality.name == "Mukono")
     self.assertEqual(skip.municipality, municipality)
Ejemplo n.º 11
0
 def setUp(self):
     super(TestMunicipalities, self).setUp()
     self.setup_test_data()
     self.request = testing.DummyRequest()
     self.views = Municipalities(self.request)
     self.municipality = Municipality.get(Municipality.name == "Mukono")
Ejemplo n.º 12
0
 def setUp(self):
     super(TestDailyWaste, self).setUp()
     self.setup_test_data()
     self.municipality = Municipality.get(Municipality.name == "Mukono")
Ejemplo n.º 13
0
 def test_passes_for_new_if_skip_type_doesnt_exist(self):
     municipality = Municipality.get(Municipality.name == "Mukono")
     validator = UniqueSkipTypeValidator(municipality.id, None)
     validator.__call__({}, 'Z')
Ejemplo n.º 14
0
 def test_raises_invalid_for_new_if_skip_type_already_exists(self):
     municipality = Municipality.get(Municipality.name == "Mukono")
     validator = UniqueSkipTypeValidator(municipality.id, None)
     self.assertRaises(colander.Invalid, validator.__call__, {}, 'A')
Ejemplo n.º 15
0
 def test_passes_for_existing_if_skip_type_doesnt_exist(self):
     municipality = Municipality.get(Municipality.name == "Mukono")
     skip_a = Skip.get(Skip.municipality == municipality,
                       Skip.skip_type == 'A')
     validator = UniqueSkipTypeValidator(municipality.id, skip_a.id)
     validator.__call__({}, 'Z')
Ejemplo n.º 16
0
 def setUp(self):
     super(TestMunicipalitiesFunctional, self).setUp()
     self.setup_test_data()
     self.municipality = Municipality.get(Municipality.name == "Mukono")
Ejemplo n.º 17
0
 def test_list_when_has_not_list_permission_and_has_municipality(self):
     self.request.user = User(municipality=Municipality(id=1))
     self.config.testing_securitypolicy(userid='manager', permissive=False)
     result = self.views.list()
     self.assertIsInstance(result, HTTPFound)
Ejemplo n.º 18
0
 def setUp(self):
     super(TestMunicipalityIntegration, self).setUp()
     self.setup_test_data()
     self.municipality = Municipality.get(Municipality.name == "Mukono")
Ejemplo n.º 19
0
def main(argv=sys.argv):
    if len(argv) != 2:
        usage(argv)
    config_uri = argv[1]
    setup_logging(config_uri)

    settings = get_appsettings(config_uri)
    engine = engine_from_config(settings, 'sqlalchemy.')
    DBSession.configure(bind=engine)

    Base.metadata.create_all(engine)

    setup_logging(config_uri)

    pwd_context.load_path(config_uri)

    # create models here
    admin = User(username='******', password='******', active=True,
                 group='nema')
    municipality = Municipality(name="Mukono")
    manager = User(username='******', password='******',
                   active=True, group='sm', municipality=municipality)
    skip_a = Skip(municipality=municipality, skip_type='A', small_length=20,
                  large_length=30, small_breadth=10, large_breadth=16)

    # add dummy site reports
    site_report_1 = SiteReport(
        report_date=datetime.date(2014, 6, 1),
        municipality=municipality,
        report_json={
            'volume_of_msw_processed': 400,
            'density_of_msw': 0.5,
            'quantity_of_msw_processed': 550,
            'num_trucks_delivered_msw': 20,
            'volume_of_mature_compost': 500,
            'density_of_mature_compost': 3.5,
            'conversion_factor_mature_to_sieved': 0.145,
            'quantity_of_compost_produced': 351,
            'quantity_of_compost_sold': 405,
            'vehicle_count': 15,
            'average_distance': 20,
            'volume_of_rejects_from_sieving': 500,
            'density_of_rejects_from_sieving': 450,
            'quantity_of_rejects_from_sieving_landfilled': 2.4,
            'total_windrow_samples': 14,
            'low_windrow_sample_count': 5,
            'fuel_consumption': 40,
            'electricity_consumption': 150,
            'leachete_volume_accumulated': 200})

    site_report_2 = SiteReport(
        report_date=datetime.date(2014, 4, 1),
        municipality=municipality,
        report_json={
            'volume_of_msw_processed': 300,
            'density_of_msw': 0.7,
            'quantity_of_msw_processed': 500,
            'num_trucks_delivered_msw': 15,
            'volume_of_mature_compost': 470,
            'density_of_mature_compost': 2.5,
            'conversion_factor_mature_to_sieved': 0.13,
            'quantity_of_compost_produced': 300,
            'quantity_of_compost_sold': 285,
            'vehicle_count': 12,
            'average_distance': 17,
            'volume_of_rejects_from_sieving': 130,
            'density_of_rejects_from_sieving': 150,
            'quantity_of_rejects_from_sieving_landfilled': 1.4,
            'total_windrow_samples': 14,
            'low_windrow_sample_count': 3,
            'fuel_consumption': 28,
            'electricity_consumption': 140,
            'leachete_volume_accumulated': 170})

    site_report_3 = SiteReport(
        report_date=datetime.date(2014, 5, 1),
        municipality=municipality,
        report_json={
            'volume_of_msw_processed': 200,
            'density_of_msw': 3,
            'quantity_of_msw_processed': 250,
            'num_trucks_delivered_msw': 10,
            'volume_of_mature_compost': 300,
            'density_of_mature_compost': 1.5,
            'conversion_factor_mature_to_sieved': 0.125,
            'quantity_of_compost_produced': 251,
            'quantity_of_compost_sold': 200,
            'vehicle_count': 9,
            'average_distance': 17,
            'volume_of_rejects_from_sieving': 300,
            'density_of_rejects_from_sieving': 175,
            'quantity_of_rejects_from_sieving_landfilled': 2,
            'total_windrow_samples': 10,
            'low_windrow_sample_count': 3,
            'fuel_consumption': 18,
            'electricity_consumption': 110,
            'leachete_volume_accumulated': 140})

    submission_handler_manager.clear()
    hook_submission_handlers()

    with transaction.manager:
        admin.save()
        municipality.save()
        manager.save()
        skip_a.save()
        site_report_1.save()
        site_report_2.save()
        site_report_3.save()

        for status, raw_json in TestBase.submissions:
            json_payload = json.loads(raw_json)
            handler_class = submission_handler_manager.find_handler(
                json_payload)
            handler_class().__call__(json_payload, status=status)
Ejemplo n.º 20
0
 def setUp(self):
     super(TestSubmissions, self).setUp()
     self.setup_test_data()
     self.municipality = Municipality.get(Municipality.name == "Mukono")
     self.municipality.request = self.request
     self.views = Submissions(self.request)