Пример #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="[email protected]")
  contact1.account = account1
  contact2 = Contact(first_name="Paul", last_name="Dupont", email="[email protected]")
  contact2.account = account1

  user1 = User(first_name="Stefane", last_name="Fermigier", email="[email protected]", password="admin")
  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 test_non_ascii_password(self):
    """Ensure we can store and test non ascii password without
    any UnicodeEncodeError
    """
    user = User()

    try:
      user.set_password(u'Hé')
    except UnicodeEncodeError, e:
      self.fail(e)
Пример #3
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)
Пример #4
0
  def test_user_follow(self):
    user1 = User(first_name="John", last_name="Test User 1", email="[email protected]", password="toto")
    user2 = User(first_name="Joe", last_name="Test User 2", email="[email protected]", password="toto")

    self.assertEquals(0, len(user1.followers))
    self.assertEquals(0, len(user1.followees))
    self.assertEquals(0, len(user2.followers))
    self.assertEquals(0, len(user2.followees))

    user1.follow(user2)

    self.assert_(user1.is_following(user2))
    self.assertEquals(1, len(user2.followers))
    self.assertEquals(1, len(user1.followees))
    self.assertEquals(0, len(user2.followees))
    self.assertEquals(0, len(user1.followers))
    self.assert_(user2 in user1.followees)

    user1.unfollow(user2)

    self.assert_(not user1.is_following(user2))
    self.assertEquals(0, len(user1.followers))
    self.assertEquals(0, len(user1.followees))
    self.assertEquals(0, len(user2.followers))
    self.assertEquals(0, len(user2.followees))
    self.assert_(user2 not in user1.followers)
Пример #5
0
  def test_group(self):
    user = User(first_name="John", last_name="Test User", email="[email protected]", password="toto")
    group = Group(name="Group 1")

    user.join(group)

    self.assert_(user.is_member_of(group))
    self.assertEquals(1, len(group.members))
    self.assertEquals(1, len(user.groups))
    self.assertEqual([user], group.members)
    self.assertEqual([group], user.groups)

    user.leave(group)

    self.assert_(not user.is_member_of(group))
    self.assertEquals(0, len(group.members))
    self.assertEquals(0, len(user.groups))
Пример #6
0
def search_users():
  q = request.args.get("q")
  if not q:
    return make_json_response([])
  users = list(User.search_query(q).all())
  return make_json_response(users)