def test_add_interactions(self, first, last, attributes): # adding multiple interaction # must copy first, otherwise just testing against itself oldinteractions = copy.deepcopy(attributes.get('interaction', [])) p = Person(first, last, attributes) v = ("talked shop over beers and sliders", "grabbed lunch") p.add_interactions(v) newinteractions = p.attributes['interaction'] for i in v: oldinteractions.append(i) assert oldinteractions == newinteractions
def test_add_interaction(self, first, last, attributes): # adding single interaction # must copy first, otherwise just testing against itself # if end object doesn't already make a copy of attributes oldinteractions = copy.deepcopy(attributes.get('interaction', [])) p = Person(first, last, attributes) v = "talked shop over beers and sliders" p.add_interactions(v) newinteractions = p.attributes['interaction'] oldinteractions.append(v) assert oldinteractions == newinteractions
def get_people(self): """ Returns all people in db as a list. Init db if it doesn't exist XXX try making as a generator function in future? """ people = [] try: with open(self.path, newline='') as csvfile: person_reader = reader(csvfile, delimiter="|") for row in person_reader: att = {k: v for k, v in zip(self.header(), row)} person = Person(att['first_name'], att['last_name'], att) # notes and attributes are lists of strings! nts = person.get_notes() person.replace_notes(string_to_list(nts)) intract = person.get_interactions() person.replace_interactions(string_to_list(intract)) # people.append(person) yield person except FileNotFoundError: self.init_db()
def add_person_cli(args, db): """Creating/updating person and adding to db via CLI""" print("Adding/updating person...") first_name = args.first_name last_name = args.last_name p = Person(first_name, last_name, cli_att_to_dict(args.attributes)) db.add_person(p, overwrite=True)
def test_get_interactions(self, first, last, attributes): p = Person(first, last, attributes) # must copy and occur first, otherwise just testing against itself oldinteractions = copy.deepcopy(attributes.get('interaction', [])) # asserting that interations retrieved are right ones assert p.get_interactions() == oldinteractions v = ["talked shop over beers and sliders", "grabbed lunch"] p.add_interactions(v) for i in v: oldinteractions.append(i) assert p.get_interactions() == oldinteractions
import copy import pytest from poundingpave.person import Person from poundingpave.person_db_csv import Person_DB_CSV as DB # XXX this is (semi-)faulty test input because we are not resetting # the test data # all changes are being made inplace.. test_people_inputs = [ Person("james", "dean", {}), # no attributes Person( "billy", "joel", { # full attributes, mult inter & notes 'company': 'piano man co', 'email': '*****@*****.**', 'mobile_phone': '925-414-8282', 'work_phone': '415-777-6942', 'role': 'musician', 'interaction': ["coffee, 5/12", "phone call, 5/14", "phone call, 6/30"], 'notes': [ 'good person to know for music composition', 'starting music production company' ] }),
def test_set_role(self, first, last, attributes): p = Person(first, last, attributes) v = "lazy bum" p.set_role(v) assert p.attributes['role'] == v
def test_set_work_phone(self, first, last, attributes): p = Person(first, last, attributes) v = '777-777-7777' p.set_work_phone(v) assert p.attributes['work_phone'] == v
def test_set_mobile_phone(self, first, last, attributes): p = Person(first, last, attributes) v = "555-555-5555" p.set_mobile_phone(v) assert p.attributes['mobile_phone'] == v
def test_set_email(self, first, last, attributes): p = Person(first, last, attributes) v = "different email" p.set_email(v) assert p.attributes['email'] == v
def test_set_company(self, first, last, attributes): p = Person(first, last, attributes) v = "different company" p.set_company(v) assert p.attributes['company'] == v
def test_name(self, first, last, attributes): # name test cases p = Person(first, last, attributes) n = p.get_name() assert isinstance(n, tuple) assert n == (first, last)
def test_replace_interactions(self, first, last, attributes): p = Person(first, last, attributes) v = ["talked shop over beers and sliders", "grabbed lunch"] p.replace_interactions(v) assert p.attributes["interaction"] == v