示例#1
0
def init_data():
  """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 test_contact(self):
    account = Account(name="John SARL")

    contact = Contact(first_name="John", last_name="Test User", email="*****@*****.**")
    contact.account = account

    self.check_editable(contact)

    eq_([contact], account.contacts)

    d = contact.to_dict()
    j = contact.to_json()
示例#3
0
  def load_contacts(self):
    reader = self.get_reader("Contacts.csv")
    for line in reader:
      d = {}
      d['email'] = line['Email Address']
      d['job_title'] = line['Title']
      for col in ['First Name', 'Last Name', 'Department']:
        d[col.lower().replace(" ", "_")] = line[col]

      for k in ['Street', 'City', 'State', 'Country']:
        d["address_" + k.lower()] = line["Primary Address %s" % k]

      contact = Contact(**d)

      contact.creator_id = choice(self.users).id
      contact.owner_id = choice(self.users).id

      account = self.accounts_map.get(line['Account Name'])
      if account:
        contact.account = account

      db.session.add(contact)
示例#4
0
  def test_contacts_are_indexed(self):
    contact = Contact(first_name="John", last_name="Test User", email="*****@*****.**")
    self.session.add(contact)
    self.session.commit()

    # Check 3 different APIs
    search_result = list(Contact.search_query(u"john").all())
    assert 1 == len(search_result)
    assert contact == search_result[0]

    search_result = list(Contact.search_query.search(u"john"))
    assert 1 == len(search_result)
    assert contact == search_result[0][1]
    assert contact.id, int(search_result[0][0]['id'])

    search_result = list(self.index.search(u"john"))
    assert 1 == len(search_result)
    assert contact == search_result[0][1]
    assert contact.id == int(search_result[0][0]['id'])