def post(self): post_data = request.get_json() name = post_data.get('name') # MaterialCommunityIcons from https://oblador.github.io/react-native-vector-icons/ icon = post_data.get('icon') priority = post_data.get('priority') translations = post_data.get('translations') # EG {'fr': 'fromage'} if name is None or icon is None: return make_response( jsonify({'message': 'Name and Icon must not be None'})), 400 try: usage = TransferUsage(name=name, icon=icon, translations=translations, priority=priority, default=False) except (IconNotSupportedException, TransferUsageNameDuplicateException) as e: return make_response(jsonify({'message': str(e)})), 400 db.session.add(usage) db.session.commit() response_object = {'message': 'Created Transfer Usage'} return make_response(jsonify(response_object)), 201
def create_transfer_usage(test_client, init_database): from server.models.transfer_usage import TransferUsage instance = TransferUsage.query.filter_by(name='Food').first() if instance: return instance transfer_usage = TransferUsage(name='Food', icon='food-apple', translations=dict(en='Food', fr='aliments')) db.session.add(transfer_usage) db.session.commit() return transfer_usage
def test_get_directory_listing_users(test_client, init_database, dl_processor): token1 = Token.query.filter_by(symbol="SM1").first() category = dl_processor.selected_business_category user = dl_processor.recipient def create_user(cat, token, is_market_enabled): _user = UserFactory(phone=phone(), business_usage_id=cat.id, is_market_enabled=is_market_enabled) create_transfer_account_for_user(_user, token, 200) return _user market_disabled_user = create_user(category, token1, False) # different token user token2 = Token.query.filter_by(symbol="SM2").first() create_user(category, token2, True) # different category user category2 = TransferUsage(name='Test', icon='message') different_business_category_user = create_user(category2, token1, True) shown_user = create_user(category, token1, True) # user did more transactions more_transactions_user = create_user(category, token1, True) make_payment_transfer(100, token=token1, send_user=different_business_category_user, receive_user=more_transactions_user, transfer_use=str(int(category.id)), is_ghost_transfer=False, require_sender_approved=False, require_recipient_approved=False) make_payment_transfer(100, token=token1, send_user=different_business_category_user, receive_user=more_transactions_user, transfer_use=str(int(category.id)), is_ghost_transfer=False, require_sender_approved=False, require_recipient_approved=False) users = dl_processor.get_directory_listing_users() assert len(users) == 2 assert users[0].id == more_transactions_user.id assert users[1].id == shown_user.id
def create_business_categories(only_if_none_exist=True): if only_if_none_exist: usages = db.session.query(TransferUsage).all() if len(usages) > 0: print("Business Categories already exist! Skipping.") return print_section_title('Creating Business Categories') business_categories = [ {'name': 'Fresh Food', 'icon': 'food-apple', 'translations': { 'en': 'Fresh Food'}}, {'name': 'Long Life Food', 'icon': 'food-variant', 'translations': { 'en': 'Long Life Food'}}, {'name': 'Water/Sanitation/Hygiene', 'icon': 'water', 'translations': { 'en': 'Water/Sanitation/Hygiene'}}, {'name': 'Health/Medicine', 'icon': 'medical-bag', 'translations': { 'en': 'Health/Medicine'}}, {'name': 'Clothing', 'icon': 'tshirt-crew', 'translations': { 'en': 'Clothing'}}, {'name': 'Household Items', 'icon': 'home', 'translations': { 'en': 'Household Items'}}, {'name': 'Other', 'icon': 'star', 'translations': { 'en': 'Other'}} ] for index, business_category in enumerate(business_categories): name = business_category['name'] usage = db.session.query(TransferUsage).filter( func.lower(TransferUsage.name) == func.lower(name)).first() if usage is None: usage = TransferUsage(name=name) db.session.add(usage) usage.priority = index + 1 usage.default = True usage.icon = business_category['icon'] usage.translations = business_category['translations'] db.session.commit() print_section_conclusion('Done creating Business Categories')
def create_business_categories(): print_section_title('Creating Business Categories') business_categories = [ {'name': 'Food/Water', 'icon': 'message', 'translations': { 'en': 'Food/Water', 'sw': 'Chakula/Maji'}}, {'name': 'Fuel/Energy', 'icon': 'message', 'translations': { 'en': 'Fuel/Energy', 'sw': 'Kuni/Makaa/Mafuta'}}, {'name': 'Education', 'icon': 'message', 'translations': { 'en': 'Education', 'sw': 'Elimu'}}, {'name': 'Health', 'icon': 'message', 'translations': { 'en': 'Health', 'sw': 'Afya'}}, {'name': 'Shop', 'icon': 'message', 'translations': { 'en': 'Shop', 'sw': 'Duka'}}, {'name': 'Environment', 'icon': 'message', 'translations': { 'en': 'Environment', 'sw': 'Mazingira'}}, {'name': 'Transport', 'icon': 'message', 'translations': { 'en': 'Transport', 'sw': 'Usafiri'}}, {'name': 'Farming/Labour', 'icon': 'message', 'translations': { 'en': 'Farming/Labour', 'sw': 'Mkulima/Mfanyikazi'}}, {'name': 'Savings Group', 'icon': 'message', 'translations': { 'en': 'Savings Group', 'sw': 'Chama'}} ] for index, business_category in enumerate(business_categories): name = business_category['name'] usage = db.session.query(TransferUsage).filter( func.lower(TransferUsage.name) == func.lower(name)).first() if usage is None: usage = TransferUsage(name=name) db.session.add(usage) usage.priority = index + 1 usage.default = True usage.icon = business_category['icon'] usage.translations = business_category['translations'] db.session.commit() print_section_conclusion('Done creating Business Categories')