def test_work(self): # create new address = AddressBuilder().set_city('Moscow').build() mapper = AddressMapper(self.connect) mapper.insert(address) # find by id self.assertEqual(mapper.id_address, 2) address = mapper.find_by_id(2) self.assertEqual(address.city, 'Moscow') self.assertEqual(address.country, '')
def save_teacher(self, name, surname, email, phone, country, city, languages, courses_id, diplomas): UnitOfWork.new_current() update = UnitOfWork.get_current() update.set_mapper_registry(MapperRegistry(self.connection)) address = AddressBuilder().set_country(country). \ set_city(city).build() person_factory = PersonFactory() teacher = person_factory.create_person( 'teacher', None, name=name, surname=surname, email=email, phone=phone, address=address, languages=languages, diplomas=diplomas, courses_id=courses_id, id_teacher=None) teacher.mark_new() UnitOfWork.get_current().commit()
def setUp(self): self.address = AddressBuilder().set_city('Rom').build() self.course_1 = CreateCourse().set_price(500).build() self.course_2 = CreateCourse().set_price(400).build() self.customer = PersonFactory.create_person( 'student', 1, 'Mama', 'Li', 'mama@h', '9009', self.address, id_student=1, language_level=['Italian A2', 'English B2'], courses_id=[56]) self.order = Order(self.customer) self.number = self.order.order_number self.order.add_item(self.course_1) self.order.add_item(self.course_2)
def test_work(self): # insert address = AddressBuilder().set_city('London').set_street( 'Putina').build() person_factory = PersonFactory() new_teacher = person_factory.create_person( 'teacher', None, 'TestTest 1', 'Test 1', '*****@*****.**', 9009, address, id_teacher=None, languages='Italian, English', courses_id='1', diplomas='Test diploma 1') self.teacher_mapper.insert(new_teacher) # count count = self.teacher_mapper.count() self.assertEqual(count, 2) # find teacher = self.teacher_mapper.find_by_id(2) self.assertEqual(teacher.surname, 'Test 1') self.assertEqual(teacher.id_teacher, 2) # update address = teacher.address address.street = 'Lenon' address.postcode = 456248 address.house_number = 5 address.apartment_number = 23 teacher.phone = 98956421 teacher.address = address self.teacher_mapper.update(teacher) # find updated teacher = self.teacher_mapper.find_by_id(2) self.assertEqual(teacher.phone, 98956421) # delete self.teacher_mapper.delete(teacher) # count count = self.teacher_mapper.count() self.assertEqual(count, 1)
def test_add_new(self): UnitOfWork.new_current() self.update = UnitOfWork.get_current() self.update.set_mapper_registry(MapperRegistry(self.connect)) person_factory = PersonFactory() address = AddressBuilder().set_country('Germany').set_city('Berlin').\ set_street('Lenina').set_house_number(6).set_apartment_number(34).\ set_postcode(456234).build() new_teacher = person_factory.create_person( 'teacher', None, 'TestTest new', 'Test new', '*****@*****.**', 9009, address, id_teacher=None, languages='Italian, English', courses_id='1', diplomas='Test diploma new') new_teacher.mark_new() UnitOfWork.get_current().commit() # get teacher mapper = TeacherMapper(self.connect) self.assertLessEqual(mapper.count(), 2) teacher = mapper.find_by_id(2) self.assertEqual(teacher.name, 'TestTest new') # update teacher.name = 'Anna Test' teacher.mark_update() UnitOfWork.get_current().commit() teacher = mapper.find_by_id(2) self.assertEqual(teacher.name, 'Anna Test') # delete teacher.mark_removed() UnitOfWork.get_current().commit() self.assertLessEqual(mapper.count(), 1)
class TestAddressBuilder(unittest.TestCase): def setUp(self): self.address_builder = AddressBuilder() def test_set_country(self): self.assertEqual(self.address_builder.set_country('Germany'), self.address_builder) self.assertEqual(self.address_builder.address.country, 'Germany') def test_set_region(self): self.assertEqual(self.address_builder.set_region('Bayern'), self.address_builder) self.assertEqual(self.address_builder.address.region, 'Bayern') def test_set_city(self): self.assertEqual(self.address_builder.set_city('Munich'), self.address_builder) self.assertEqual(self.address_builder.address.city, 'Munich') def test_set_street(self): self.assertEqual(self.address_builder.set_street('Rahel'), self.address_builder) self.assertEqual(self.address_builder.address.street, 'Rahel') def test_set_house_number(self): self.assertEqual(self.address_builder.set_house_number(5), self.address_builder) self.assertEqual(self.address_builder.address.house_number, 5) def test_set_apartment_number(self): self.assertEqual(self.address_builder.set_apartment_number(52), self.address_builder) self.assertEqual(self.address_builder.address.apartment_number, 52) def test_set_postcode(self): self.assertEqual(self.address_builder.set_postcode(85642), self.address_builder) self.assertEqual(self.address_builder.address.postcode, 85642)
def setUp(self): self.address = AddressBuilder().set_city('Rom').build() self.school = LanguageSchool('Lingoda', 'Berlin', 800, '*****@*****.**')
def setUp(self): self.address = AddressBuilder().set_country('Russia').build() self.student = Student(2, 'Ivan', 'Ivanov', 'ivan@ivan', 895642, self.address, 2, ['English B1'], [112])
def setUp(self): self.address = AddressBuilder().set_country('Russia').build() self.person = Person(1, 'Maria', 'Afanaseva', '*****@*****.**', 891678523, self.address)
def setUp(self): self.address_builder = AddressBuilder()
def setUp(self): self.course_builder = CreateCourse() self.address = AddressBuilder().set_city('Munich').build()
def setUp(self): self.address = AddressBuilder().set_city('Rom').build() self.person_factory = PersonFactory()
def setUp(self): self.address = AddressBuilder().set_city('Moscow').build() self.teacher = Teacher(3, 'Lala', 'Fafa', '*****@*****.**', 78956, self.address, 1, ['English', 'german'], [13], ['Manchester diploma'])
self.id_person = self.cursor.fetchone()[0] def update(self, updated_person): update_script = f"UPDATE PERSONS SET name=?, surname=?, " \ f"email=?, phone=?, id_address=? WHERE id_person=?" self.cursor.execute( update_script, (updated_person.name, updated_person.surname, updated_person.email, updated_person.phone, updated_person.address.id_address, updated_person.id_person)) self.connection.commit() if __name__ == '__main__': connect = sqlite3.connect('school_db.sqlite') address = AddressBuilder().set_city('Berlin').set_street('Lenina').build() addr_mapper = AddressMapper(connect) addr_mapper.insert(address) id_address = addr_mapper.id_address person_factory = PersonFactory() person = person_factory.create_person('teacher', 5, 'Nana', 'Li', '*****@*****.**', 9009, id_address, id_teacher=2, salary=2000, languages=['Italian', 'English'],