def test_understanding(self): """ Tests that SMS messages can be properly understood """ from apps.admin.models.account import Account account = Account(password="******") account.save() from apps.seller.models.seller import Seller seller = Seller(account=account) seller.save() from apps.seller.models.product import Product product = Product(seller=seller) product.save() tracking_test_cases = ["CP123456789012MA", "RR123456MA"]#, "CP 12345678 MA" for tracking_num in tracking_test_cases: message_tests = [ "%d %s" % (product.id, tracking_num), " %d %s " % (product.id, tracking_num), "%d something %s random" % (product.id, tracking_num), #"%s %d" % (tracking_num, product.id), ] for message in message_tests: result = sms.understandMessage(message) self.assertIsNot(result, False, "SMS message \"%s\" not understood" % message) (found_product_id, actions) = result self.assertEqual(product.id, int(found_product_id), "SMS product id not identified") self.assertEqual(actions['tracking_number'], tracking_num, "SMS tracking \"%s\" not found in \"%s\"" % (tracking_num, message))
def createAdmin(request): from apps.admin.views.forms import AccountCreateForm from django.db import IntegrityError if request.method == 'POST': name = request.POST.get('name') phone = request.POST.get('phone') password = request.POST.get('password') password = processPassword(password) if password else None admin_type = request.POST.get('admin_type') if not phone: context = {'incorrect': "bad phone"} elif not password: context = {'incorrect': "bad password"} elif not admin_type: context = {'incorrect': "bad admin_type"} else: try: account = Account(phone=phone, password=password, admin_type=admin_type) account.name = name if name else None account.save() return redirect('admin:edit account', account.id) except IntegrityError: messages.warning(request, 'An account with this phone already exists.') context = {'incorrect': "bad phone"} except Exception as e: ExceptionHandler(e, "in account.createAdmin") messages.error(request, e) else: context = {} context['form'] = AccountCreateForm() return render(request, 'account/create_admin.html', context)
def createSeller(request): from apps.admin.views.forms import AccountCreateForm from django.db import IntegrityError from apps.seller.views.account import create as createSeller context = {} if request.method == 'POST': name = request.POST.get('name') phone = request.POST.get('phone') password = request.POST.get('password') password = processPassword(password) if password else None if not phone and phone.isdigit(): context = {'incorrect': "bad phone"} elif not password: context = {'incorrect': "bad password"} else: try: account = Account(phone=phone, password=password) account.name = name if name else None account.save() if createSeller(account): login(request) return redirect('seller:edit') else: e = Exception("createSeller() returned False") ExceptionHandler(e, 'in account.createSeller') messages.error(request, 'Error creating seller account.') account.delete() except IntegrityError: messages.warning(request, 'An account with this phone already exists.') context = {'incorrect': "bad phone"} except Exception as e: ExceptionHandler(e, "in account.createSeller") messages.error(request, e) context['form'] = AccountCreateForm() return render(request, 'account/create_seller.html', context)