Example #1
0
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'
Example #2
0
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'
Example #3
0
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'
        }
Example #4
0
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'
Example #5
0
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)
Example #6
0
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'
Example #7
0
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.')
Example #8
0
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
Example #9
0
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
Example #10
0
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'
Example #11
0
def create(data: dict) -> List[Convention]:
    validate_name(data['name'])
    validate_capacity(data['capacity'])
    return save(
        Convention(id=str(uuid4()),
                   name=data['name'],
                   capacity=data['capacity']))
Example #12
0
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.'
        )
Example #13
0
def test_model_conventions_return_dict(app_context) -> NoReturn:
    with app_context:
        # Action
        conventions = save(
            Convention(id='6b6ce977-1339-4461-9e7c-1a930a57dbdb',
                       name='Conventions Hall',
                       capacity=23))
        # Assert
        assert isinstance(conventions, Convention)
        assert conventions.name == 'Conventions Hall'
        assert conventions.capacity == 23
Example #14
0
def test_get_by_id_conventions(app_context) -> NoReturn:
    with app_context:
        # Arrange
        id_conventions = "6b6ce977-1339-4461-9e7c-1a930a57dbdb"
        save(Convention(
            id='6b6ce977-1339-4461-9e7c-1a930a57dbdb',
            name='Great Hall',
            capacity=23))
        test_client = app_context.app.test_client()

        request = test_client.get(f'/conventions/{id_conventions}')
        response = request.get_json()
        assert len(response) == 3
Example #15
0
def test_delete_conventions(app_context) -> NoReturn:
    with app_context:
        # Arrange
        save(Convention(
            id='6b6ce977-1339-4461-9e7c-1a930a57dbdb',
            name='Clubest',
            capacity=23))
        # Action
        delete_conventions('6b6ce977-1339-4461-9e7c-1a930a57dbdb')

        # Assert
        conventions = get()
        assert len(conventions) == 0
Example #16
0
def test_conventions_serialize(app_context) -> NoReturn:
    with app_context:
        conventions = save(
            Convention(id='6b6ce977-1339-4461-9e7c-1a930a57dbdb',
                       name='Conventions Hall',
                       capacity=23))
        conventions_serialize = conventions.serialize()

        assert conventions_serialize == {
            'capacity': 23,
            'id': '6b6ce977-1339-4461-9e7c-1a930a57dbdb',
            'name': 'Conventions Hall'
        }
Example #17
0
def test_validates_update_conventions(app_context) -> NoReturn:
    with app_context:
        # Arrange
        save(Convention(
            id='6b6ce977-1339-4461-9e7c-1a930a57dbdb',
            name='Hall',
            capacity=23))
        # Action
        conventions = update('6b6ce977-1339-4461-9e7c-1a930a57dbdb', {'name': 'Best Hall', 'capacity': '50'})

        # Asserts

        assert conventions.name == 'Best Hall'
        assert conventions.capacity == 50
Example #18
0
def test_get_all_conventions(app_context) -> NoReturn:
    with app_context:
        # Arrange
        save(Convention(
            id='6b6ce977-1339-4461-9e7c-1a930a57dbdb',
            name='Hall',
            capacity=23))
        # Action
        conventions = get()

        # Assert
        assert isinstance(conventions, list)
        assert len(conventions) == 1
        assert isinstance(conventions[0], Convention)
Example #19
0
def test_get_by_id_conventions(app_context) -> NoReturn:
    with app_context:
        # Arrange
        save(Convention(
            id='6b6ce977-1339-4461-9e7c-1a930a57dbdb',
            name='Great Hall',
            capacity=23))
        # Action
        conventions = get_by_id('6b6ce977-1339-4461-9e7c-1a930a57dbdb')

        # Assert
        assert conventions.id == '6b6ce977-1339-4461-9e7c-1a930a57dbdb'
        assert conventions.name == 'Great Hall'
        assert conventions.capacity == 23
Example #20
0
def test_get_all_conventions(app_context) -> NoReturn:
    with app_context:
        # Arrange
        save(Convention(
            id='6b6ce977-1339-4461-9e7c-1a930a57dbdb',
            name='Great Hall',
            capacity=23))
        test_client = app_context.app.test_client()
        # Actions
        request = test_client.get('/conventions')

        response = request.get_json()
        # Assert
        assert len(response) == 1
Example #21
0
def test_delete_conventions_room_with_id(app_context) -> NoReturn:
    with app_context:
        # Arrange
        id_conventions = "6b6ce977-1339-4461-9e7c-1a930a57dbdb"
        save(Convention(
            id='6b6ce977-1339-4461-9e7c-1a930a57dbdb',
            name='Big Master Hall',
            capacity=100))
        test_client = app_context.app.test_client()
        # Action
        request = test_client.delete(f'/conventions/{id_conventions}')

        # Asserts
        assert request.status_code == 204
Example #22
0
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'
        }
Example #23
0
def test_update_conventions_room(app_context) -> NoReturn:
    with app_context:
        # Arrange

        save(Convention(
            id='6b6ce977-1339-4461-9e7c-1a930a57dbdb',
            name='Hyper Hall',
            capacity=23))

        payload = {'name': 'Greatest Hall', 'capacity': 70}

        test_client = app_context.app.test_client()

        request = test_client.patch('/conventions/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'}
Example #24
0
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