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
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()
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).uid contact.owner_id = choice(self.users).uid account = self.accounts_map.get(line['Account Name']) if account: contact.account = account self.db.session.add(contact)