Пример #1
0
def init_data(db):
  """Initializes DB with some dummy data."""

  account1 = Account(name="Fermi Corp", website="http://fermigier.com/")
  db.session.add(account1)

  contact1 = Contact(first_name="Stefane", last_name="Fermigier", email="*****@*****.**")
  contact1.account = account1
  contact2 = Contact(first_name="Paul", last_name="Dupont", email="*****@*****.**")
  contact2.account = account1

  user1 = User(first_name="Stefane", last_name="Fermigier", email="*****@*****.**", password="******")
  photo_path = join(dirname(__file__), "..", "dummy_files", "mugshot.jpg")
  user1.photo = open(photo_path).read()

  group1 = Group(name="Group 1")
  group1.photo = open(photo_path).read()

  user1.join(group1)

  #db.session.add(contact1)
  #db.session.add(contact2)
  db.session.add(user1)

  db.session.commit()

  assert len(Contact.query.all()) == 2
  assert len(Account.query.all()) == 1
  assert len(User.query.all()) == 1
  assert len(Group.query.all()) == 1
Пример #2
0
  def load_users(self):
    reader = self.get_reader("Users.csv")
    for line in reader:
      d = {}
      for col in ['first_name', 'last_name', 'email', 'password', 'job_title']:
        d[col] = line[col]

      user = User(**d)
      photo_path = join(dirname(__file__),
                        "..", "user_photos",
                        d['last_name'].lower() + ".jpg")
      user.photo = open(photo_path).read()
      self.db.session.add(user)
      self.users.append(user)