Beispiel #1
0
    def test_listings_by_account(self):
        row_count = db.create_account('*****@*****.**', 'First', 'Last', 'password')
        self.assertEqual(row_count, 1)

        row_count = db.create_account('*****@*****.**', 'First', 'Last', 'password')
        self.assertEqual(row_count, 1)

        test_account = db.find_account('*****@*****.**')
        self.assertIsNotNone(test_account)

        test_account = db.find_account('*****@*****.**')
        self.assertIsNotNone(test_account)

        listing_id = db.create_listing('Potatoes', 5, 'Some form of description', 5, '*****@*****.**', 'grams')
        self.assertEqual(listing_id, 100)

        listing_id = db.create_listing('Watermelons', 1, 'Some form of description', 5, '*****@*****.**', 'pounds')
        self.assertEqual(listing_id, 101)

        listing_id = db.create_listing('Potatoes', 5, 'Some form of description', 5, '*****@*****.**', 'grams')
        self.assertEqual(listing_id, 102)

        test_listing = db.find_listing(100)
        self.assertIsNotNone(test_listing)

        test_listing = db.find_listing(101)
        self.assertIsNotNone(test_listing)

        test_listing = db.find_listing(102)
        self.assertIsNotNone(test_listing)

        test_listings = db.listings_by_account('*****@*****.**')
        self.assertEqual(test_listings[0][0], 100)
        self.assertEqual(test_listings[1][0], 101)
Beispiel #2
0
    def test_render_feed(self):
        db.create_account('*****@*****.**', 'First', 'Last', 'password')
        db.create_account('*****@*****.**', 'First', 'Last', 'password')

        db.create_listing('Potatoes', 5, 'Some form of description', 5, '*****@*****.**', 'grams')
        db.create_listing('Bananas', 5, 'Some form of description', 5, '*****@*****.**', 'grams')
        db.create_listing('Tomatoes', 5, 'Some form of description', 5, '*****@*****.**', 'grams')
        db.create_listing('Apples', 5, 'Some form of description', 5, '*****@*****.**', 'grams')

        resp = self.client.get(url_for('render_feed'))
        self.assertTrue(b'Potatoes' in resp.data)
        self.assertTrue(b'Tomatoes' in resp.data)
        self.assertTrue(b'Bananas' in resp.data)
        self.assertTrue(b'Apples' in resp.data)
Beispiel #3
0
    def test_all_accounts(self):
        for i in range(1, 11):
            row_count = db.create_account('test{0}@example.com'.format(i), 'First', 'Last', 'password')
            self.assertEqual(row_count, 1)

            test_account = db.find_account('test{0}@example.com'.format(i))
            self.assertIsNotNone(test_account)
Beispiel #4
0
    def test_create_account(self):
        account_form = AccountForm()
        account_form.email.data = '*****@*****.**'
        account_form.first_name.data = 'First'
        account_form.last_name.data = 'Last'
        account_form.password.data = 'password'
        account_form.confirm.data = 'password'
        print(account_form)

        db.create_account(account_form.email.data, account_form.first_name.data, account_form.last_name.data,
                          account_form.password.data)
        account = Account(account_form.email.data)
        self.assertTrue(login_user(account))

        resp = self.client.get(url_for('create_account'))
        self.assertTrue(b'Create a new account' in resp.data)
Beispiel #5
0
    def test_fetch_feed(self):
        test_account = db.create_account('*****@*****.**', 'First', 'Last', 'password')
        self.assertIsNotNone(test_account)

        listing_id = db.create_listing('Potatoes', 0, 'Some form of description', 5, '*****@*****.**', 'grams')
        self.assertEqual(listing_id, 100)

        listing_id = db.create_listing('Watermelons', 5, 'Some form of description', 5, '*****@*****.**', 'pounds')
        self.assertEqual(listing_id, 101)

        listing_id = db.create_listing('Potatoes', 0, 'Some form of description', 5, '*****@*****.**', 'grams')
        self.assertEqual(listing_id, 102)

        test_listing = db.find_listing(100)
        self.assertIsNotNone(test_listing)

        test_listing = db.find_listing(101)
        self.assertIsNotNone(test_listing)

        test_listing = db.find_listing(102)
        self.assertIsNotNone(test_listing)

        test_feed = db.fetch_feed(6)
        self.assertIsNotNone(test_feed)
        self.assertEqual(test_feed[0][0], 101)
Beispiel #6
0
    def test_create_account(self):
        row_count = db.create_account('*****@*****.**', 'First', 'Last', 'password')
        self.assertEqual(row_count, 1)

        test_account = db.find_account('*****@*****.**')
        self.assertIsNotNone(test_account)

        self.assertEqual(test_account['first_name'], 'First')
        self.assertEqual(test_account['last_name'], 'Last')
Beispiel #7
0
def create_account_ui():
    while True:
        name = input("Enter username: "******"Name already taken!")
        else:
            break
    while True:
        password = input("Enter password: "******"Confirm password: "******"Passwords do not match!")
        else:
            break
    db.create_account(name, password)
    print("Account created! Please proceed by logging in.")
    return
Beispiel #8
0
def create(args):
    logging.basicConfig(filename='log.log', level=logging.DEBUG)
    logging.debug('创建')
    username = args['username']
    password = args['password']
    if not re.search('^[a-zA-Z]{1}\w*$', username):
        return {'code': 204, 'err': "username format is not correct!"}
    if not re.search('^[a-zA-Z]{1}\w*$', password):
        return {'code': 205, 'err': "password format is not correct!"}
    if db.load_by_username(username):
        return {'code': 201, 'err': "user already exists!"}
    port = str(13000 + db.calc_count())
    mode = "aes-256-cfb"
    logging.debug('username:%s, password:%s, port:%s, mode:%s', \
            username, password, port, mode)
    os.system("sh startss.sh " + port + " " + password + " " + mode)
    db.create_account(username, password, port, mode)
    return {'code': 200, 'err': "success"}
Beispiel #9
0
    def test_get_id_from_email(self):
        row_count = db.create_account('*****@*****.**', 'First', 'Last', 'password')
        self.assertEqual(row_count, 1)

        test_account = db.find_account('*****@*****.**')
        self.assertIsNotNone(test_account)

        test_id = db.get_id_from_email('*****@*****.**')
        self.assertIsNotNone(test_id)

        self.assertEqual(test_id, 100)
Beispiel #10
0
    def test_find_password(self):
        row_count = db.create_account('*****@*****.**', 'First', 'Last', 'password')
        self.assertEqual(row_count, 1)

        test_account = db.find_account('*****@*****.**')
        self.assertIsNotNone(test_account)

        test_password = db.find_password('*****@*****.**')
        self.assertIsNotNone(test_password)

        self.assertEqual(test_account['password'], 'password')
Beispiel #11
0
    def test_find_listing(self):
        row_count = db.create_account('*****@*****.**', 'First', 'Last', 'password')
        self.assertEqual(row_count, 1)

        test_account = db.find_account('*****@*****.**')
        self.assertIsNotNone(test_account)

        listing_id = db.create_listing('Potatoes', 5, 'Some form of description', 5, '*****@*****.**', 'grams')
        self.assertEqual(listing_id, 100)

        test_listing = db.find_listing(100)
        print(test_listing)
        self.assertIsNotNone(test_listing)
Beispiel #12
0
    def test_all_listings(self):
        for i in range(1, 11):
            row_count = db.create_account('test{0}@example.com'.format(i), 'First', 'Last', 'password')
            self.assertEqual(row_count, 1)

            test_account = db.find_account('test{0}@example.com'.format(i))
            self.assertIsNotNone(test_account)

            listing_id = db.create_listing('Potatoes', 4, 'Basic description', 5,
                                          'test{0}@example.com'.format(i), 'pounds')
            print(listing_id)
            self.assertEqual(listing_id, 99+i)

            test_listing = db.find_listing(99 + i)
            print(test_listing)
            self.assertIsNotNone(test_listing)
Beispiel #13
0
    def test_create_listing(self):
        test_account = db.create_account('*****@*****.**', 'First', 'Last', 'password')
        self.assertIsNotNone(test_account)

        listing_id = db.create_listing('Potatoes', 5, 'Some form of description', 5, '*****@*****.**', 'grams')
        self.assertEqual(listing_id, 100)

        test_listing = db.find_listing(100)
        self.assertIsNotNone(test_listing)

        self.assertEqual(test_listing['name'], 'Potatoes')
        self.assertEqual(test_listing['quantity'], 5)
        self.assertEqual(test_listing['description'], 'Some form of description')
        self.assertEqual(test_listing['price'], 5)
        self.assertEqual(test_listing['account_email'], '*****@*****.**')
        self.assertEqual(test_listing['unit'], 'grams')
Beispiel #14
0
 def post(self):
     username = self.get_argument('username').lower()
     password = self.get_argument('password')
     password_again = self.get_argument('password_rep')
     if password != password_again:
         error = u'?activity=register&error=' + tornado.escape.url_escape("Passwords don't match")
         self.redirect('/' + error)
     if not db.username_available(username):
         error = u'?activity=register&error=' + tornado.escape.url_escape("This username has been taken")
         self.redirect('/' + error)
     else:
         user_id = db.create_account(username, password)
         if user_id is not None:
             json = tornado.escape.json_encode({'userid': user_id})
             self.set_secure_cookie('skillbook_user', str(user_id), expires_days=90)
             self.redirect('/settings')
         else:
             self.redirect('/')
Beispiel #15
0
 def post(self):
     messages = self.messages.copy()
     username = self.get_argument('username').lower()
     password = self.get_argument('password')
     password_again = self.get_argument('password_rep')
     
     if password != password_again:
         messages['register_error'] = 'Passwords don\'t match'
         self.render('auth.html', **messages)
     elif not db.username_available(username):
         messages['register_error'] = 'This username has been taken'
         self.render('auth.html', **messages)
     else:
         user_id = db.create_account(username, password)
         if user_id is not None:
             self.set_current_user(user_id)
             self.redirect('/settings')
         else:
             self.redirect('/')
Beispiel #16
0
 def create(cls, first_name, last_name, email, password):
     new_account = db.create_account({
         'first_name':
         first_name,
         'last_name':
         last_name,
         'email':
         email,
         'password_hash':
         generate_password_hash(password)
     })
     if new_account is not None:
         self = cls()
         self.first_name = new_account['first_name']
         self.last_name = new_account['last_name']
         self.email = new_account['email']
         self.password_hash = new_account['password_hash']
         self.is_superuser = new_account['is_superuser']
         return self
     else:
         return None
def create_account():
    account_form = AccountForm()

    if account_form.validate_on_submit():
        account = db.find_account(account_form.email.data)

        if account is not None:
            flash("Account {} already exists".format(account_form.email.data))
        else:
            rowcount = db.create_account(account_form.email.data,
                                         account_form.first_name.data,
                                         account_form.last_name.data,
                                         account_form.password.data)

            if rowcount == 1:
                flash("Account {} created".format(account_form.email.data))
                account = Account(account_form.email.data)
                login_user(account)
                return redirect(url_for('render_feed'))
            else:
                flash("New member not created")
    return render_template('account-form.html',
                           form=account_form,
                           mode='create')
Beispiel #18
0
def intents(intent, r, ex, score):

    montante = ent(r)[0]
    conta = ent(r)[1]
    dest = ent(r)[2]
    nome = ent(r)[3]
    small_talk = s_talk()

    # Certeza do reconhecimento no intent
    if score > 0.5:

        # Tratamento dos intents regulares
        if intent in small_talk:
            table(intent)

        elif intent in "DizerNome":
            # Se não reconhecer o nome
            if nome == "":
                global nome_
                nome_ = ex
            else:
                nome_ = nome
            print("ChatBanco: Bem-vindo " + nome_.title() +
                  ". Que posso fazer por si?\n")

        elif intent in "AbrirConta":
            if nome_ == "":
                print("ChatBanco: Diga-me o seu nome, por favor.\n")
            elif conta != "":
                create_account(conta, 0, nome_)
                print("ChatBanco: Abri uma conta " + conta + " em nome de " +
                      nome_.title() + " com 0€.\n")
            else:
                print(
                    "ChatBanco: Que tipo de conta deseja abrir (corrente/poupança)?\n"
                )

        elif intent in "TipoConta":
            if nome_ == "":
                print("ChatBanco: Diga-me o seu nome, por favor.\n")
            else:
                create_account(conta, 0, nome_)
                print("ChatBanco: Abri uma conta " + conta + " em nome de " +
                      nome_.title() + " com 0€.\n")

        elif intent in 'SaberSaldo':
            '''
            SELECT DISTINCT conta.id, tipo, montante, utilizador_id
                FROM utilizador, conta
                WHERE utilizador_id =
                    (SELECT utilizador.id
                        FROM utilizador, conta
                        WHERE nome LIKE "Pedro");
            '''
            if nome_ == "":
                print("ChatBanco: Diga-me o seu nome, por favor.\n")
            else:
                sal = saber_saldo(nome_)
                print("ChatBanco: Tem " + str(sal) + "€ na Conta.\n")

        elif intent in 'TransferirDinheiro':
            '''
            UPDATE conta
            SET montante = 50
            WHERE utilizador_id =
            (SELECT utilizador.id
                FROM utilizador, conta
                WHERE nome = "Pedro");

            UPDATE conta
            SET montante = 100
            WHERE utilizador_id =
            (SELECT utilizador.id
                FROM utilizador, conta
                WHERE nome = "Carlos");
            '''

            if nome_ == "":
                print("ChatBanco: Diga-me o seu nome, por favor.\n")
            else:
                sal1 = int(saber_saldo(nome_))
                sal2 = int(saber_saldo(dest))

                if sal1 >= int(montante.split(' ', 1)[0]):
                    sal1 = sal1 - int(montante.split(' ', 1)[0])
                    atualizar_valores(nome, sal1)
                    print("ChatBanco: Tem agora " + str(sal1) +
                          "€ na Conta.\n")

                    sal2 = sal2 + int(montante.split(' ', 1)[0])
                    atualizar_valores(dest, sal2)

                else:
                    print("Não tem dinheiro suficiente na Conta.\n")

        elif intent in 'LevantarDinheiro':
            '''
            UPDATE conta
            SET montante = 50
            WHERE utilizador_id =
            (SELECT utilizador.id
                FROM utilizador, conta
                WHERE nome = "Pedro");
            '''

            if nome_ == "":
                print("ChatBanco: Diga-me o seu nome, por favor.\n")
            else:
                sal = int(saber_saldo(nome_))
                if sal >= int(montante.split(' ', 1)[0]):
                    montante = sal - int(montante.split(' ', 1)[0])
                    atualizar_valores(nome, montante)
                    print("ChatBanco: Tem agora " + str(montante) +
                          "€ na Conta.\n")
                else:
                    print("Não tem dinheiro suficiente na Conta.\n")

        elif intent in 'FazerDepósito':
            '''
            UPDATE conta
            SET montante = 50
            WHERE utilizador_id =
            (SELECT utilizador.id
                FROM utilizador, conta
                WHERE nome = "Pedro");
            '''
            if nome_ == "":
                print("ChatBanco: Diga-me o seu nome, por favor.\n")
            else:
                sal = int(saber_saldo(nome_))
                montante = int(montante.split(' ', 1)[0]) + sal
                atualizar_valores(nome, montante)
                print("ChatBanco: Tem agora " + str(montante) +
                      "€ na Conta.\n")

    else:
        print("ChatBanco: Desculpe, não percebi.\n")
Beispiel #19
0
 def test_find_account(self):
     db.create_account('*****@*****.**', 'First', 'Last', 'password')
     resp = self.client.get(url_for('find_account', email='*****@*****.**'))
     self.assertTrue(b"First's listings" in resp.data, "Could not find profile page")
Beispiel #20
0
def signup():
    form = SignupForm()
    if form.validate_on_submit():
        create_account(form)
        return render_template('success.html')
    return render_template('signup.html', title='Sign Up', form=form)
Beispiel #21
0
def login_test_user():
    db.create_account('*****@*****.**', 'First', 'Last', 'password')
    account = Account('*****@*****.**')
    return login_user(account)