def test_read_person_file_returns_person_list(self): file_management = FileManagement() person_list = file_management.read_person_file() self.assertEqual([ person_database.Person("oba", "male", "Obama"), person_database.Person("twins", "female", "Twins") ], person_list)
def test_write_person_file(self): file_management = FileManagement() write_person = [ person_database.Person("oba", "male", "Obama"), person_database.Person("twins", "female", "Twins") ] file_management.write_person_file(write_person) person_list = file_management.read_person_file() self.assertEqual(write_person, person_list)
def read_person_file(self): with open(self.filename, 'r', newline='') as filereader: header = filereader.readline() person_list = [] for row in filereader: row = row.strip() row_list = row.split(',') new_person = person_database.Person(row_list[0], row_list[1], row_list[2]) person_list.append(new_person) return person_list
def do_PUT(self): self.send_response(200) self.send_header('Content-Type', 'text/html') self.end_headers() content_len = int(self.headers.get('content-length', 0)) put_body = self.rfile.read(content_len) json_body = json.loads(put_body) amend_person = person_database.Person(json_body['nickname'], json_body['gender'], json_body['name']) db.update(amend_person) file_manager.write_person_file(db.list)
def do_POST(self): self.send_response(200) self.send_header('Content-Type', 'text/html') self.end_headers() content_len = int(self.headers.get('content-length', 0)) post_body = self.rfile.read(content_len) parsed_body = urllib.request.unquote( post_body.decode("utf-8")).split('&') person_dict = {} for element in parsed_body: parsed_element = element.split('=') person_dict[parsed_element[0]] = parsed_element[1] new_person = person_database.Person(person_dict['nickname'], person_dict['gender'], person_dict['name']) db.create(new_person) file_manager.write_person_file(db.list)
def test_render_person_details(self): writer = MockWriter() person = person_database.Person("nickname", "gender", "name") render_person_details(writer, person) self.assertEqual(bytes("<h1> nickname's details: </h1>\n<dl><dt>gender: </dt> <dd>female</dd>\n<dt>Name: " "</dt> <dd>name</dd></dl>", 'UTF-8'), writer.content)