def generate_ticket_handler(text, state): return generate_ticket( first_name=state.first_name, last_name=state.last_name, city_from=state.context["destination_cities_of_user_to_write"], city_to=state.context["destination_city"], data=state.context["data_flights"])
def test_image_generation(self): ticket_file = generate_ticket('departure', 'arrival', '23-02-2021 18:00', '*****@*****.**') with open('files/ticket_example.png', 'rb') as expected_file: expected_bytes = expected_file.read() assert ticket_file.read() == expected_bytes
def generate_ticket_handler(text, context): return generate_ticket(name=context['name'], mail=context['email'], date=context['date'], departure=context['departure'], destination=context['destination'], passengers=context['passengers'])
def test_generation_ticket(self): avatar_mock = Mock() with open('files/[email protected]', mode='rb') as avatar_file: avatar_mock.content = avatar_file.read() with patch('requests.get', return_value=avatar_mock): ticket = generate_ticket('Name', '*****@*****.**') with open('files/ticket_example.png', mode='rb') as expected_file: assert ticket.read() == expected_file.read()
def generate_ticket_handler(text, context): return generate_ticket(first_name=context['first_name'], last_name=context['last_name'], departure_city=context['departure_city_to_print'], departure_date=context['date_flight_to_print'], departure_time=context['time_flight_to_print'], arrival_city=context['arrival_city_to_print'], flight=context['flight_to_print'])
def generate_img_coffee(text, context): """ Вывод изображения напитка :). Для сценария "coffee (кофейный автомат) :param text: сообщение от пользователя (not used) :param context: контекст текущего события :return: IOBytes изображения """ return generate_ticket(context, flag='drink')
def generate_ticket_air(text, context): """ Создание изображения билета на самолёт. Для сценария "airplane (билет на самолёт) :param text: сообщение от пользователя (not used) :param context: контекст текущего события :return: IOBytes изображения """ return generate_ticket(context, flag='airplane')
def generate_menu_coffee(text, context): """ Создание изображения меню кофе. Для сценария "coffee (кофейный автомат) :param text: сообщение от пользователя (not used) :param context: контекст текущего события :return: IOBytes изображения """ return generate_ticket(context, flag='coffee_menu')
def generate_ticket_handle(text, context): """ Создание изображения билета на конференцию. Для сценария "conference (билет на конференцию) :param text: сообщение от пользователя (not used) :param context: контекст текущего события :return: IOBytes изображения """ return generate_ticket(context)
def test_image_generation(self): with open('files/89088918290.png', 'rb') as avatar: avatar_mock = Mock() avatar_mock.content = avatar.read() with patch('requests.get', return_value=avatar_mock): ticket_file = generate_ticket(self.CONTEXT) with open('files/ticket_example.png', 'rb') as example: image_bytes = example.read() assert ticket_file.read() == image_bytes
def generate_ticket_handler(text, context): """ Generating the ticket :param text: :param context: dict with parameters for creating the ticket :return: ticket file """ return generate_ticket(name=context['name'], email=context['email'])
def test_image_generation(self): with open('files/test_avatar.png', 'rb') as test_avatar: avatar_mock = Mock() avatar_mock.content = test_avatar.read() with patch('requests.get', return_value=avatar_mock): ticket_file = generate_ticket('Москва', 'Лондон', 'test', '22-06-2020', 'Василий') with open('files/ticket_example.png', 'rb') as expected_file: expected_bytes = expected_file.read() assert ticket_file.read() == expected_bytes
def continue_scenario(self, text, state, user_id): steps = settings.SCENARIOS[state.scenario_name]['steps'] step = settings.SCENARIOS[state.scenario_name]['steps'][ state.step_name] handler = getattr(handlers, step['handler']) if handler(text=text, context=state.context): next_step = steps[step['next_step']] self.send_step(next_step, user_id, text, state.context) if next_step['next_step']: state.step_name = step['next_step'] else: log.info('Registered: {name}- {email}'.format(**state.context)) RegistrationDB(name=state.context['name'], email=state.context['email']) generate_ticket(name=state.context['name'], email=state.context['email']) state.delete() else: text_to_send = step['failure_text'].format(**state.context) self.send_text(text_to_send, user_id)
def test_image_generation(self): with open('files/avatar-example.png', 'rb') as avatar_file: avatar_mock = Mock() avatar_mock.content = avatar_file.read() with patch('requests.get', return_value=avatar_mock): ticket_file = generate_ticket('Moscow', 'London', '07-07-2020 Tue 18:00', 'Лев Лещенко', '*****@*****.**') with open('files/ticket-example.png', 'rb') as expected_file: expected_bytes = expected_file.read() assert ticket_file.read() == expected_bytes
def test_generate_ticket(mock_response_requests_get): root_dir = sys.path.pop() sys.path.append(root_dir) abs_path_for_ticket_test_file = os.path.join(root_dir, 'files/ticket-test.png') with open(abs_path_for_ticket_test_file, 'rb') as expected_file: expected_bytes = expected_file.read() ticked_file = generate_ticket(name=REG_CONF_SCENARIO_LST_INPUT[2][0], email=REG_CONF_SCENARIO_LST_INPUT[4][0]) ticked_file_bytes = ticked_file.read() assert expected_bytes == ticked_file_bytes
def test_image(self): result_image = generate_ticket(departure='Москва', arrival='Лондон', date='2021-12-12 10:00', quantity='2', number='+79099671212') test_image = Image.open('files/test_image.png') test = _io.BytesIO() test_image.save(test, 'png') print(type(result_image), type(test)) self.assertEqual(type(result_image), type(test))
def handle_generate_ticket(text, context): """ Запуск функции рисования билета :return: .png в байтах """ return generate_ticket(phone=context['phone'], email=context['email'], name=context['name'], departure=context['departure'], arrival=context['arrival'], date=context['flight_date_to_database'], spaces=context['spaces'])
def test_image_generation(self): with open('files/[email protected]', 'rb') as avatar_file: avatar_mock = Mock() avatar_mock.content = avatar_file.read() with patch('requests.get', return_value=avatar_mock): ticket_file = generate_ticket('Дмитрий', '*****@*****.**', '27-09-2020', 'Москва', 'Берлин', '5') with open('files/ticket_example.png', 'rb') as expected_file: expected_bytes = expected_file.read() ticket_bytes = ticket_file.read() assert isinstance(ticket_bytes, bytes) and len(ticket_bytes) > len(expected_bytes) * 0.2
def test_image_generation(self): with open("files/avatar.png", "rb") as avatar_file: avatar_mock = Mock() avatar_mock.content = avatar_file.read() with patch('requests.get', return_value=avatar_mock): ticket_file = generate_ticket('Vasily', '*****@*****.**') with open('files/ticket_example.png', 'rb') as expected_file: expected_bytes = expected_file.read() assert ticket_file.read() == expected_bytes
def test_image_generation(self): with open('files/ssss.png', 'rb') as avatar_file: avatar_mock = Mock() avatar_mock.content = avatar_file.read() with patch('requests.get', return_value=avatar_mock): ticket_file = generate_ticket('dddd', 'ssss') with open('files/ticket_example.png', 'rb') as expected_file: expected_bytes = expected_file.read() assert ticket_file.read() == expected_bytes
def test_image_generation(self): with open('files/[email protected]', 'rb') as avatar_file: avatar_mock = Mock() avatar_mock.content = avatar_file.read() with patch('requests.get', return_value=avatar_mock): ticket_file = generate_ticket(**TEST_ARGUMENTS) with open('files/ticket_for_tests.png', 'rb') as expected_file: expected_bytes = expected_file.read() assert ticket_file.read() == expected_bytes
def test_generate_image(self): context = { "city_from": "Москва", "city_to": "Лондон", "date": "31-08-2020", "flight": "Москва-Лондон 10:05 11-09-2020", "seats": "1", } ticket_file = generate_ticket(context=context) with open("files/ticket-example.png", "rb") as f: ticket_example = f.read() assert ticket_file.read() == ticket_example
def test_image_generation(self): with open('files/greg.png', 'rb') as avatar_file: avatar_mock = Mock() avatar_mock.content = avatar_file.read() with patch('requests.get', return_value=avatar_mock): ticket_file = generate_ticket({ 'name': 'rge', 'email': 'greg' }, flag='conference') with open('files/ticket_example.png', 'rb') as expected_file: expected_bytes = expected_file.read() assert ticket_file.read() == expected_bytes
def test_image_generation(self): with open('images/test_avatar.png', 'rb') as avatar_file: avatar_mock = Mock() avatar_mock.content = avatar_file.read() with patch('requests.get', return_value=avatar_mock): ticket_file = generate_ticket(name='Иван Иванов', email='*****@*****.**') with open('images/test_invitation.png', 'rb') as expected_file: expected_bytes = expected_file.read() assert ticket_file.read() == expected_bytes
def test_image_generation(self): with open("sourсes/avatar.png", "rb") as avatar_file: avatar_mock = Mock() avatar_mock.content = avatar_file.read() with patch('requests.get', return_value=avatar_mock): ticket_file = generate_ticket('Виталий', 'Гальперин', 'Нижний Новгород (GOJ)', '01-12-2020', '14:55+03:00', 'Москва (MOW)', 'S7 1096') with open('sourсes/ticket_to_test.png', 'rb') as expected_file: expected_bytes = expected_file.read() assert ticket_file.read() == expected_bytes
def test_image_airline_gen(self): with open('files/airplane_ticket_example.png', 'rb') as airplane_ticket: ticket_file = generate_ticket( { 'name': 'крук', 'landing': 'Бельгия, Гент', 'direction': 'Россия, Рязань', 'date_reg': '05.11.2020', 'date_landing': '05.11.2020 04:00:00', 'date_direction': '05.11.2020 11:30:00' }, flag='airplane') airplane_ticket_bytes = airplane_ticket.read() assert ticket_file.read() == airplane_ticket_bytes
def test_image_generation(self): path_dir = os.path.dirname(__file__) path_file = '/files/ticket_example.png' path_file = os.path.normpath(path_dir + path_file) avatar_file = '/files/admin.png' avatar_file = os.path.normpath(path_dir + avatar_file) with open(avatar_file, 'rb') as avatar_f: avatar_mock = Mock() avatar_mock.content = avatar_f.read() with patch('requests.get', return_value=avatar_mock): ticket_file = generate_ticket('Admin', '*****@*****.**') with open(path_file, 'rb') \ as expected_file: expected_bytes = expected_file.read() assert ticket_file.read() == expected_bytes
def test_image_generation(self): with open('files/123.png', 'rb') as avatar_photo: avatar_mock = Mock() avatar_mock.content = avatar_photo.read() with patch('requests.get', return_value=avatar_mock): ticket_file = generate_ticket(name='максим', city_out='москва', city_in='париж', date_flight='21-05-2020', email='*****@*****.**') with open('files/temp.png', 'rb') as expected_file: expected_bytes = expected_file.read() assert ticket_file.read() == expected_bytes
def test_image_generation(self): with open('files/avatar.png', 'rb') as avatar_file: avatar_mock = Mock() avatar_mock.content = avatar_file.read() with patch('requests.get', return_value=avatar_mock): ticket_file = generate_ticket(town_departure='Москва', town_arrival='Лондон', date='Monday, 25-05-2020 15:45', quantity_places='2', comment='комментарий', telephone='8-(888)-888-88 88') with open('files/ticket_example.png', 'rb') as expected_file: expected_bytes = expected_file.read() assert ticket_file.read() == expected_bytes
def test_image_generaton(self): with open('files/avatar.svg', 'rb') as avatar_file: avatar_mock = Mock() avatar_mock.content = avatar_file.read() with patch('requests.get', return_value = avatar_mock): ticket_file = generate_ticket('name', 'email') with open('files/ticket-example.png', 'rb') as expected_file: expected_bytes = expected_file.read() assert ticket_file.read() == expected_bytes # if __name__ == '__main__': # unittest.main()