Exemplo n.º 1
0
def add_user(username, email, quiet=False):
    """ Adds a User to the database with a random password and prints
        the random password.
    """
    from models import User
    if User.query.get(username):
        print("User %s already exists!" % username)
        return
    u = User(username=username, 
             email=email.strip())
    pw = new_pw()
    u.set_password(pw)
    if not quiet:
        print("Password for %s set to: %s" % (username, pw))
    db.session.add(u)
    db.session.commit()
Exemplo n.º 2
0
def add_some_data(username):
    # add testuser
    u1 = models.User(username=username)
    u1.set_password(utils.new_pw())
    db.session.add(u1)
    db.session.flush()
    db.session.commit()

    xdata = StringIO.StringIO(u"<w>"
                              "<scales><item id=\"sid1\">"
                              "<owner>o1</owner>"
                              "<model>m1</model>"
                              "</item></scales>"
                              "<days><day date=\"2012-06-03\">"
                              "<weight scale=\"sid1\">50.1</weight>"
                              "</day></days>"
                              "</w>")
    utils.import_weight_from_xml(xdata, username)
Exemplo n.º 3
0
 def test_new_pw(self):
     from utils import new_pw
     pw = new_pw()
     self.assertEqual(len(pw), 8)
     self.assertTrue(pw.isalnum())