def test_get_all_profiles(app_context) -> NoReturn: with app_context: # Arrange save( CoffeeRoom(id='e3383c48-9b89-472f-9086-9cb21feaad7f', name='CafeClub', capacity=23)) save( Convention(id='6b6ce977-1339-4461-9e7c-1a930a57dbdb', name='Hall', capacity=23)) save( Profile(id='d74052ac-cf9f-4baa-a49a-3993cdf0e50f', name='Jon', last_name='Snow', conventions_id='6b6ce977-1339-4461-9e7c-1a930a57dbdb', coffee_room_id='e3383c48-9b89-472f-9086-9cb21feaad7f')) # Action profile = get() # Assert assert isinstance(profile, list) assert len(profile) == 1 assert isinstance(profile[0], Profile)
def test_get_all_profile_with_same_id_convention_room(app_context) -> NoReturn: with app_context: # Arrange save(CoffeeRoom( id='e3383c48-9b89-472f-9086-9cb21feaad7f', name='CafeClub', capacity=23)) save(Convention( id='6b6ce977-1339-4461-9e7c-1a930a57dbdb', name='Hall', capacity=23)) save(Profile( id='d74052ac-cf9f-4baa-a49a-3993cdf0e50f', name='Jon', last_name='Snow', conventions_id='6b6ce977-1339-4461-9e7c-1a930a57dbdb', coffee_room_id='e3383c48-9b89-472f-9086-9cb21feaad7f')) profile = get_by_id_all_profile_in_the_same_convention_room('6b6ce977-1339-4461-9e7c-1a930a57dbdb') assert len(profile) == 1 assert profile[0].name == 'Jon' assert profile[0].last_name == 'Snow' assert profile[0].id == 'd74052ac-cf9f-4baa-a49a-3993cdf0e50f'
def test_get_by_id_profile(app_context) -> NoReturn: with app_context: # Arrange save( CoffeeRoom(id='e3383c48-9b89-472f-9086-9cb21feaad7f', name='CafeClub', capacity=23)) save( Convention(id='6b6ce977-1339-4461-9e7c-1a930a57dbdb', name='Hall', capacity=23)) save( Profile(id='d74052ac-cf9f-4baa-a49a-3993cdf0e50f', name='Jon', last_name='Snow', conventions_id='6b6ce977-1339-4461-9e7c-1a930a57dbdb', coffee_room_id='e3383c48-9b89-472f-9086-9cb21feaad7f')) # Actions profile = get_by_id('d74052ac-cf9f-4baa-a49a-3993cdf0e50f') # Asserts assert profile.id == 'd74052ac-cf9f-4baa-a49a-3993cdf0e50f' assert profile.name == 'Jon' assert profile.last_name == 'Snow' assert profile.conventions_id == '6b6ce977-1339-4461-9e7c-1a930a57dbdb' assert profile.coffee_room_id == 'e3383c48-9b89-472f-9086-9cb21feaad7f'
def test_validate_delete_room(app_context) -> NoReturn: with app_context: # Arrange save( CoffeeRoom(id='e3383c48-9b89-472f-9086-9cb21feaad7f', name='CafeClub', capacity=23)) save( Convention(id='6b6ce977-1339-4461-9e7c-1a930a57dbdb', name='Hall', capacity=23)) save( Profile(id='d74052ac-cf9f-4baa-a49a-3993cdf0e50f', name='Jon', last_name='Snow', conventions_id='6b6ce977-1339-4461-9e7c-1a930a57dbdb', coffee_room_id='e3383c48-9b89-472f-9086-9cb21feaad7f')) with pytest.raises(BadRequestException) as ex: validate_delete_coffee_room('e3383c48-9b89-472f-9086-9cb21feaad7f') assert ( str(ex.value) == '400 Bad Request: Convention table cannot be deleted, there are data in it.' )
def test_model_profile_return_dict(app_context) -> NoReturn: with app_context: # Action save( CoffeeRoom(id='e3383c48-9b89-472f-9086-9cb21feaad7f', name='CafeClub', capacity=23)) save( Convention(id='6b6ce977-1339-4461-9e7c-1a930a57dbdb', name='Hall', capacity=23)) profile = save( Profile(id='d74052ac-cf9f-4baa-a49a-3993cdf0e50f', name='Jon', last_name='Snow', conventions_id='6b6ce977-1339-4461-9e7c-1a930a57dbdb', coffee_room_id='e3383c48-9b89-472f-9086-9cb21feaad7f')) # Assert assert isinstance(profile, Profile) assert profile.name == 'Jon' assert profile.last_name == 'Snow' assert profile.coffee_room_id == 'e3383c48-9b89-472f-9086-9cb21feaad7f' assert profile.conventions_id == '6b6ce977-1339-4461-9e7c-1a930a57dbdb'
def test_update_profile(app_context) -> NoReturn: with app_context: # Arrange save( CoffeeRoom(id='e3383c48-9b89-472f-9086-9cb21feaad7f', name='CafeClub', capacity=23)) save( Convention(id='6b6ce977-1339-4461-9e7c-1a930a57dbdb', name='Hall', capacity=23)) save( Profile(id='d74052ac-cf9f-4baa-a49a-3993cdf0e50f', name='Jon', last_name='Snow', conventions_id='6b6ce977-1339-4461-9e7c-1a930a57dbdb', coffee_room_id='e3383c48-9b89-472f-9086-9cb21feaad7f')) # Action profile = update( 'd74052ac-cf9f-4baa-a49a-3993cdf0e50f', { 'name': 'João', 'last_name': 'Neves', 'conventions_id': '6b6ce977-1339-4461-9e7c-1a930a57dbdb', 'coffee_room_id': 'e3383c48-9b89-472f-9086-9cb21feaad7f' }) # Assert assert profile.name == 'João' assert profile.last_name == 'Neves' assert profile.conventions_id == '6b6ce977-1339-4461-9e7c-1a930a57dbdb' assert profile.coffee_room_id == 'e3383c48-9b89-472f-9086-9cb21feaad7f'
def test_create_profile(app_context, mocker) -> NoReturn: with app_context: # Arrange save( CoffeeRoom(id='e3383c48-9b89-472f-9086-9cb21feaad7f', name='CafeClub', capacity=23)) save( Convention(id='6b6ce977-1339-4461-9e7c-1a930a57dbdb', name='Hall', capacity=23)) mock_uuid = mocker.patch('app.profiles.actions.uuid4') mock_uuid.return_value = 'd74052ac-cf9f-4baa-a49a-3993cdf0e50f' # Action profile = create({ "name": "Paul", "last_name": "Anka", "conventions_id": "6b6ce977-1339-4461-9e7c-1a930a57dbdb", "coffee_room_id": "e3383c48-9b89-472f-9086-9cb21feaad7f" }) # Assert assert profile.id == 'd74052ac-cf9f-4baa-a49a-3993cdf0e50f' assert profile.name == 'Paul' assert profile.last_name == "Anka" assert profile.coffee_room_id == 'e3383c48-9b89-472f-9086-9cb21feaad7f' assert profile.conventions_id == '6b6ce977-1339-4461-9e7c-1a930a57dbdb'
def test_validate_maximum_profiles_in_same_coffee_room( app_context) -> NoReturn: with app_context: save( CoffeeRoom(id='e3383c48-9b89-472f-9086-9cb21feaad7f', name='CafeClub', capacity=23)) save( Convention(id='6b6ce977-1339-4461-9e7c-1a930a57dbdb', name='Hall', capacity=23)) save( Profile(id='d74052ac-cf9f-4baa-a49a-3993cdf0e50f', name='Jon', last_name='Snow', conventions_id='6b6ce977-1339-4461-9e7c-1a930a57dbdb', coffee_room_id='e3383c48-9b89-472f-9086-9cb21feaad7f')) save( Profile(id='A74052ac-cf9f-4baa-a49a-3993cdf0e50t', name='Hanna', last_name='Barbara', conventions_id='6b6ce977-1339-4461-9e7c-1a930a57dbdb', coffee_room_id='e3383c48-9b89-472f-9086-9cb21feaad7f')) with pytest.raises(BadRequestException) as ex: validate_maximum_profiles_in_same_coffee_room( 'e3383c48-9b89-472f-9086-9cb21feaad7f', 1) assert ( str(ex.value) == '400 Bad Request: Maximum number of profiles in same coffee room.')
def test_delete_profile_with_id(app_context) -> NoReturn: with app_context: # Arrange id_profile = "d74052ac-cf9f-4baa-a49a-3993cdf0e50f" # Arrange save( CoffeeRoom(id='e3383c48-9b89-472f-9086-9cb21feaad7f', name='CafeClub', capacity=23)) save( Convention(id='6b6ce977-1339-4461-9e7c-1a930a57dbdb', name='Hall', capacity=23)) save( Profile(id='d74052ac-cf9f-4baa-a49a-3993cdf0e50f', name='Jon', last_name='Snow', conventions_id='6b6ce977-1339-4461-9e7c-1a930a57dbdb', coffee_room_id='e3383c48-9b89-472f-9086-9cb21feaad7f')) test_client = app_context.app.test_client() # Action request = test_client.delete(f'/profiles/{id_profile}') # Asserts assert request.status_code == 204
def test_get_all_profiles_with_id_convention(app_context) -> NoReturn: with app_context: # Arrange save( CoffeeRoom(id='e3383c48-9b89-472f-9086-9cb21feaad7f', name='CafeClub', capacity=23)) save( Convention(id='6b6ce977-1339-4461-9e7c-1a930a57dbdb', name='Hall', capacity=23)) save( Profile(id='d74052ac-cf9f-4baa-a49a-3993cdf0e50f', name='Jon', last_name='Snow', conventions_id='6b6ce977-1339-4461-9e7c-1a930a57dbdb', coffee_room_id='e3383c48-9b89-472f-9086-9cb21feaad7f')) test_client = app_context.app.test_client() request = test_client.get( '/convention/6b6ce977-1339-4461-9e7c-1a930a57dbdb/profiles') response = request.get_json() # Assert assert len(response) == 1
def create(data: dict) -> List[Profile]: validate_name(data['name']) validate_capacity(data['capacity']) return save( CoffeeRoom(id=str(uuid4()), name=data['name'], capacity=data['capacity']))
def test_profile_serialize(app_context) -> NoReturn: with app_context: save( CoffeeRoom(id='e3383c48-9b89-472f-9086-9cb21feaad7f', name='CafeClub', capacity=23)) save( Convention(id='6b6ce977-1339-4461-9e7c-1a930a57dbdb', name='Hall', capacity=23)) profile = save( Profile(id='d74052ac-cf9f-4baa-a49a-3993cdf0e50f', name='Jon', last_name='Snow', conventions_id='6b6ce977-1339-4461-9e7c-1a930a57dbdb', coffee_room_id='e3383c48-9b89-472f-9086-9cb21feaad7f')) profile_serialize = profile.serialize() assert profile_serialize == { 'coffee_room_id': 'e3383c48-9b89-472f-9086-9cb21feaad7f', 'conventions_id': '6b6ce977-1339-4461-9e7c-1a930a57dbdb', 'id': 'd74052ac-cf9f-4baa-a49a-3993cdf0e50f', 'last_name': 'Snow', 'name': 'Jon' }
def test_model_coffe_room_return_dict(app_context) -> NoReturn: with app_context: # Action coffe_room = save( CoffeeRoom(id='6b6ce977-1339-4461-9e7c-1a930a57dbdb', name='CafeClub', capacity=23)) # Assert assert isinstance(coffe_room, CoffeeRoom) assert coffe_room.name == 'CafeClub' assert coffe_room.capacity == 23
def test_get_by_id_coffee_room(app_context) -> NoReturn: with app_context: # Arrange id_coffee_room = "6b6ce977-1339-4461-9e7c-1a930a57dbdb" save( CoffeeRoom(id='6b6ce977-1339-4461-9e7c-1a930a57dbdb', name='CafeClub', capacity=23)) test_client = app_context.app.test_client() request = test_client.get(f'/coffee-room/{id_coffee_room}') response = request.get_json() assert len(response) == 3
def test_delete_coffee_room(app_context) -> NoReturn: with app_context: # Arrange save( CoffeeRoom(id='6b6ce977-1339-4461-9e7c-1a930a57dbdb', name='CafeClub', capacity=23)) # Action delete_coffee_room('6b6ce977-1339-4461-9e7c-1a930a57dbdb') # Assert coffee_room = get() assert len(coffee_room) == 0
def test_coffe_room_serialize(app_context) -> NoReturn: with app_context: coffe_room = save( CoffeeRoom(id='6b6ce977-1339-4461-9e7c-1a930a57dbdb', name='CafeClub', capacity=23)) coffe_room_serialize = coffe_room.serialize() assert coffe_room_serialize == { 'capacity': 23, 'id': '6b6ce977-1339-4461-9e7c-1a930a57dbdb', 'name': 'CafeClub' }
def test_get_by_id_coffee_room(app_context) -> NoReturn: with app_context: # Arrange save( CoffeeRoom(id='6b6ce977-1339-4461-9e7c-1a930a57dbdb', name='CafeClub', capacity=23)) # Action coffee_room = get_by_id('6b6ce977-1339-4461-9e7c-1a930a57dbdb') # Assert assert coffee_room.id == '6b6ce977-1339-4461-9e7c-1a930a57dbdb' assert coffee_room.name == 'CafeClub' assert coffee_room.capacity == 23
def test_get_all_coffee_room(app_context) -> NoReturn: with app_context: # Arrange save( CoffeeRoom(id='6b6ce977-1339-4461-9e7c-1a930a57dbdb', name='CafeClub', capacity=23)) test_client = app_context.app.test_client() # Actions request = test_client.get('/coffee-room') response = request.get_json() # Assert assert len(response) == 1
def test_delete_coffee_room_with_id(app_context) -> NoReturn: with app_context: # Arrange id_coffee_room = "6b6ce977-1339-4461-9e7c-1a930a57dbdb" save( CoffeeRoom(id='6b6ce977-1339-4461-9e7c-1a930a57dbdb', name='CafeClub', capacity=23)) test_client = app_context.app.test_client() # Action request = test_client.delete(f'/coffee-room/{id_coffee_room}') # Asserts assert request.status_code == 204
def test_get_all_coffee_room(app_context) -> NoReturn: with app_context: # Arrange save( CoffeeRoom(id='6b6ce977-1339-4461-9e7c-1a930a57dbdb', name='CafeClub', capacity=23)) # Action coffee_room = get() # Assert assert isinstance(coffee_room, list) assert len(coffee_room) == 1 assert isinstance(coffee_room[0], CoffeeRoom)
def test_validates_update_coffee_room(app_context) -> NoReturn: with app_context: # Arrange save( CoffeeRoom(id='6b6ce977-1339-4461-9e7c-1a930a57dbdb', name='CafeClub', capacity=23)) # Action coffee_room = update('6b6ce977-1339-4461-9e7c-1a930a57dbdb', { 'name': 'Best Coffee', 'capacity': '50' }) # Asserts assert coffee_room.name == 'Best Coffee' assert coffee_room.capacity == 50
def test_update_profile(app_context) -> NoReturn: with app_context: # Arrange # Arrange save( CoffeeRoom(id='e3383c48-9b89-472f-9086-9cb21feaad7f', name='CafeClub', capacity=23)) save( Convention(id='6b6ce977-1339-4461-9e7c-1a930a57dbdb', name='Hall', capacity=23)) save( Profile(id='d74052ac-cf9f-4baa-a49a-3993cdf0e50f', name='Jon', last_name='Snow', conventions_id='6b6ce977-1339-4461-9e7c-1a930a57dbdb', coffee_room_id='e3383c48-9b89-472f-9086-9cb21feaad7f')) payload = { 'name': 'James', 'last_name': 'Junior', 'conventions_id': '6b6ce977-1339-4461-9e7c-1a930a57dbdb', 'coffee_room_id': 'e3383c48-9b89-472f-9086-9cb21feaad7f' } test_client = app_context.app.test_client() request = test_client.patch( '/profiles/d74052ac-cf9f-4baa-a49a-3993cdf0e50f', json=payload) response = request.get_json() assert len(response) == 5 assert response == { 'coffee_room_id': 'e3383c48-9b89-472f-9086-9cb21feaad7f', 'conventions_id': '6b6ce977-1339-4461-9e7c-1a930a57dbdb', 'id': 'd74052ac-cf9f-4baa-a49a-3993cdf0e50f', 'last_name': 'Junior', 'name': 'James' }
def test_update_coffee_room(app_context) -> NoReturn: with app_context: # Arrange save( CoffeeRoom(id='6b6ce977-1339-4461-9e7c-1a930a57dbdb', name='CafeClub', capacity=23)) payload = {'name': 'Greatest Hall', 'capacity': 70} test_client = app_context.app.test_client() request = test_client.patch( '/coffee-room/6b6ce977-1339-4461-9e7c-1a930a57dbdb', json=payload) response = request.get_json() assert len(response) == 3 assert response == { 'capacity': 70, 'id': '6b6ce977-1339-4461-9e7c-1a930a57dbdb', 'name': 'Greatest Hall' }
def test_create_profiles(app_context) -> NoReturn: with app_context: # Arrange save( CoffeeRoom(id='e3383c48-9b89-472f-9086-9cb21feaad7f', name='CafeClub', capacity=23)) save( Convention(id='6b6ce977-1339-4461-9e7c-1a930a57dbdb', name='Hall', capacity=23)) payload = { 'id': '07e7eced-e56b-47fe-94e4-d4c24fb4d191', 'name': 'aycon', 'last_name': 'Jack', 'conventions_id': '6b6ce977-1339-4461-9e7c-1a930a57dbdb', 'coffee_room_id': 'e3383c48-9b89-472f-9086-9cb21feaad7f' } test_client = app_context.app.test_client() request = test_client.post('/profiles', json=payload) response = request.get_json() assert len(response) == 5