def test_update(self):
     user = db.User.query().get()
     role = db.Role(parent=user.key)
     role.type_index = RoleType.COMMITTEE_ADMIN
     role.committee = 'EDU'
     role.put()
     supplier = db.Supplier(id=6)
     supplier.name = 'S1'
     supplier.put()
     self.assertEquals(db.create_key('Supplier-6'), supplier.key)
     fund = db.Fund(id=11)
     fund.committee = 'EDU'
     fund.name = 'myFund'
     fund.put()
     purchase = db.Purchase(id=12, parent=fund.key)
     purchase.description = 'a'
     purchase.put()
     with app.test_request_context('/p',
                                   method='POST',
                                   data={
                                       '_action': 'update',
                                       'supplier': 'Supplier-6',
                                       'quote_amount-value': '11',
                                       'description': 'b'
                                   }):
         purchases.view_purchase('Purchase-12')
     self.assertEqual('b', purchase.description)
Beispiel #2
0
 def create_role_if_not_exist(self, role: discord.Role):
     # Stage 1: Create guild
     self.create_guild_if_not_exist(role.guild)
     # Stage 2: Store role
     with session_scope(self.sessionmaker) as session:
         if not session.query(exists().where(db.Role.id == role.id)).scalar():
             session.add(db.Role(id=role.id,
                         guild_id=role.guild.id,
                         name=role.name,
                         created_at=role.created_at))
Beispiel #3
0
def view_role_list(db_id):
    user = data_models.lookup_entity(db_id)
    new_role = db.Role(parent=user.key)
    model = data_models.Model(new_role)
    form = RoleForm(request.form, new_role)
    model.add_form(ACTION_CREATE.name, form)
    property_list = map(properties.create_readonly_field, form._fields.keys(),
                        form._fields.values())
    role_query = db.Role.query(ancestor=user.key)
    return views.view_std_entity_list(model, 'Role List', ACTION_CREATE,
                                      property_list, role_query, user)
 def test_checked(self):
     user = db.User.query().get()
     role = db.Role(parent=user.key)
     role.type_index = RoleType.FUND_ADMIN
     role.put()
     fund = db.Fund(id=11)
     fund.put()
     purchase = db.Purchase(id=12, parent=fund.key)
     purchase.put()
     with app.test_request_context('/p',
                                   method='POST',
                                   data={'_action': 'checked'}):
         purchases.view_purchase('Purchase-12')
     self.assertEqual("MB0001", purchase.po_number)
 def test_create_payment(self):
     user = db.User.query().get()
     role = db.Role(parent=user.key)
     role.type_index = RoleType.PAYMENT_ADMIN
     role.put()
     supplier = db.Supplier(id=6)
     supplier.paid_in_sterling = False
     supplier.name = "Sup-6"
     supplier.put()
     grant = db.Grant()
     grant.put()
     with app.test_request_context('/supplier/123',
                                   method='POST',
                                   data={'_action': 'startTransfer'}):
         url = suppliers.view_supplier('Supplier-6')
     self.assertEquals('/foreigntransfer/ForeignTransfer-5', url)
Beispiel #6
0
    def create_role(self, role: discord.Role):
        session = self.session_manager()

        LOGGER.info("Creating new role %s (%d)", role.name, role.id)
        if not session.query(
                exists().where(db.Guild.id == role.guild.id)).scalar():
            self.create_guild(role.guild)
        new_role = db.Role(id=role.id,
                           guild_id=role.guild.id,
                           name=role.name,
                           created_at=role.created_at)
        session.merge(new_role)
        LOGGER.info("Role creation succesfull!")

        session.commit()
        session.close()
 def test_create_payment_no_grants(self):
     user = db.User.query().get()
     role = db.Role(parent=user.key)
     role.type_index = RoleType.PAYMENT_ADMIN
     role.put()
     supplier = db.Supplier(id=6)
     supplier.paid_in_sterling = False
     supplier.name = "Sup-6"
     supplier.put()
     with app.test_request_context('/supplier/123',
                                   method='POST',
                                   data={'_action': 'startTransfer'}):
         args = suppliers.view_supplier('Supplier-6')
     expected = html.div(
         html.div('No grants are pending - nothing to transfer',
                  class_='error'))
     self.assertEquals(expected, args.get('errors'))
 def test_create_purchase(self):
     user = db.User.query().get()
     role = db.Role(parent=user.key)
     role.type_index = RoleType.COMMITTEE_ADMIN
     role.committee = 'EDU'
     role.put()
     fund = db.Fund(id=11)
     fund.committee = 'EDU'
     fund.name = 'myFund'
     fund.put()
     supplier = db.Supplier(id=6)
     supplier.name = 'S1'
     supplier.put()
     with app.test_request_context('/',
                                   method='POST',
                                   data={
                                       '_action': 'create',
                                       'supplier': 'Supplier-6',
                                       'quote_amount-value': '11',
                                       'description': 'b'
                                   }):
         purchases.view_purchase_list('Fund-11')
logger = logging.getLogger('model')

workbench = db.WorkBench.get_or_insert('main')
committee_labels = [('AMB', 'Ambulance'), ('PHC', 'PrimaryHealth'),
                    ('SEC', 'SecondaryHealth'), ('LIV', 'Livelihoods'),
                    ('ENG', 'Engineering'), ('EDU', 'Education'),
                    ('CHU', 'Churches'), ('WEC', 'Wildlife Centre'),
                    ('GEN', 'General')]

if db.User.query().count() == 0:
    user = db.User()
    user.name = 'Keith'
    user.email = '*****@*****.**'
    key = user.put()

    role = db.Role(parent=key)
    role.type_index = RoleType.USER_ADMIN
    role.committee = ''
    role.put()


class Committee:
    def __init__(self, id, name):
        self.id = id
        self.name = name
        self.key = self

    def kind(self):
        return 'Committee'

    def urlsafe(self):