def test_get_all(self):
        # Setup
        conn = get_test_connection()
        reset_database(conn)
        cur = conn.cursor()

        states = State.get_all_states(cur)
        assert states is not None  # Ensure something was returned
        assert len(states) > 1  # Ensure multiple types were returned

        conn.commit()
        pass
    def test_get(self):
        # Setup
        conn = get_test_connection()
        reset_database(conn)
        cur = conn.cursor()

        state = State.get_state(cur, 0)
        assert state is None  # Ensure none was returned for bad ID
        state = State.get_state(cur, 1)
        assert state is not None  # Ensure something was returned for valid ID
        assert state.id == 1  # Ensure correct type was returned

        # Ensure we can commit without violating constraints
        conn.commit()

        pass
    def test_crud(self):
        # Setup
        conn = get_test_connection()
        reset_database(conn)
        cur = conn.cursor()

        # Get nonexistent
        user = User.get_user(cur, 0)
        assert user is None  # Get where user doesn't exist returns None

        # Create user
        user_id = User.create_user(
            cur, User(user_id=None, username='******', pin='1234', user_type_id=1,
                      created_at=None, updated_at=None, deleted=None))
        assert user_id is not None  # ID was present
        assert user_id != 0  # ID was something sensible

        # Get user
        user = User.get_user(cur, user_id)
        assert user.id == user_id  # ID was set
        assert user.pin == '1234'  # Pin name was set

        # Update user
        user.pin = '5678'
        User.update_user(cur, user)
        user = User.get_user(cur, user_id)
        assert user.pin == '5678'  # First name was updated

        # Delete user
        User.delete_user(cur, user_id)
        user = User.get_user(cur, user_id)
        assert user is None  # None is returned when deleted is true

        # Double-check that row still exists with manual query
        cur.execute('SELECT * FROM users WHERE id=%s', (user_id,))
        assert cur.rowcount == 1  # Ensure we got a row
        user = User.user_from_tuple(cur.fetchone())
        assert user.deleted  # Make sure row still exists, and deleted is true

        # Ensure we can commit without violating constraints
        conn.commit()

        pass
Ejemplo n.º 4
0
    def test_crud(self):
        # Setup
        conn = get_test_connection()
        reset_database(conn)
        cur = conn.cursor()

        # Get nonexistent
        address = Address.get_address(cur, 0)
        assert address is None  # Get where address doesn't exist returns None

        # Create address
        address_id = Address.create_address(
            cur, Address(address_id=None, street='1st street', city='city', states_id=1, postal_code='55555',
                         country_abbreviation='US', created_at=None, updated_at=None, deleted=None))
        assert address_id is not None  # ID was present
        assert address_id != 0  # ID was something sensible

        # Get address
        address = Address.get_address(cur, address_id)
        assert address.id == address_id  # ID was set
        assert address.street == '1st street'  # Street was set

        # Update address
        address.street = '2nd street'
        Address.update_address(cur, address)
        address = Address.get_address(cur, address_id)
        assert address.street == '2nd street'  # Street was updated

        # Delete address
        Address.delete_address(cur, address_id)
        address = Address.get_address(cur, address_id)
        assert address is None  # None is returned when deleted is true

        # Double-check that row still exists with manual query
        cur.execute('SELECT * FROM addresses WHERE id=%s', (address_id,))
        assert cur.rowcount == 1  # Ensure we got a row
        address = Address.address_from_tuple(cur.fetchone())
        assert address.deleted  # Make sure row still exists, and deleted is true

        # Ensure we can commit without violating constraints
        conn.commit()

        pass
    def test_attempt_login(self):
        # Setup
        conn = get_test_connection()
        reset_database(conn)
        cur = conn.cursor()

        # Create children
        user_id = User.create_user(
            cur, User(user_id=None, username='******', pin='1234', user_type_id=1,
                      created_at=None, updated_at=None, deleted=None))

        user = User.attempt_login(cur, 'bad_username', '1234')  # Test wrong name
        assert user is None

        user = User.attempt_login(cur, 'username', '0000')  # Test wrong pin
        assert user is None

        user = User.attempt_login(cur, 'username', '1234')  # Test correct creds
        assert user is not None

        conn.commit()

        pass
Ejemplo n.º 6
0
    def test_crud(self):
        # Setup
        conn = get_test_connection()
        reset_database(conn)
        cur = conn.cursor()

        # Create children
        address_id = Address.create_address(
            cur,
            Address(address_id=None,
                    street='1st street',
                    city='city',
                    states_id=1,
                    postal_code='55555',
                    country_abbreviation='US',
                    created_at=None,
                    updated_at=None,
                    deleted=None))

        # Get nonexistent
        contact_information = ContactInformation.get_contact_information(
            cur, 0)
        assert contact_information is None  # Get where contact information doesn't exist returns None

        # Create contact information
        contact_information_id = ContactInformation.create_contact_information(
            cur,
            ContactInformation(contact_information_id=None,
                               email='*****@*****.**',
                               phone_number='+15555555555',
                               address_id=address_id,
                               created_at=None,
                               updated_at=None,
                               deleted=None))
        assert contact_information_id is not None  # ID was present
        assert contact_information_id != 0  # ID was something sensible

        # Get contact information
        contact_information = ContactInformation.get_contact_information(
            cur, contact_information_id)
        assert contact_information.id == contact_information_id  # ID was set
        assert contact_information.phone_number == '+15555555555'  # Phone number was set

        # Update contact information
        contact_information.phone_number = '+16085555555'
        ContactInformation.update_contact_information(cur, contact_information)
        contact_information = ContactInformation.get_contact_information(
            cur, contact_information_id)
        assert contact_information.phone_number == '+16085555555'  # Phone number was updated

        # Delete contact information
        ContactInformation.delete_contact_information(cur,
                                                      contact_information_id)
        contact_information = ContactInformation.get_contact_information(
            cur, contact_information_id)
        assert contact_information is None  # None is returned when deleted is true

        # Double-check that row still exists with manual query
        cur.execute('SELECT * FROM contact_information WHERE id=%s',
                    (contact_information_id, ))
        assert cur.rowcount == 1  # Ensure we got a row
        contact_information = ContactInformation.contact_information_from_tuple(
            cur.fetchone())
        assert contact_information.deleted  # Make sure row still exists, and deleted is true

        # Ensure we can commit without violating constraints
        conn.commit()

        pass
Ejemplo n.º 7
0
    def test_crud(self):
        # Setup
        conn = get_test_connection()
        reset_database(conn)
        cur = conn.cursor()

        # Create children
        contact_information_address_id = Address.create_address(
            cur,
            Address(address_id=None,
                    street='1st street',
                    city='city',
                    states_id=1,
                    postal_code='55555',
                    country_abbreviation='US',
                    created_at=None,
                    updated_at=None,
                    deleted=None))
        contact_information_id = ContactInformation.create_contact_information(
            cur,
            ContactInformation(contact_information_id=None,
                               email='*****@*****.**',
                               phone_number='+15555555555',
                               address_id=contact_information_address_id,
                               created_at=None,
                               updated_at=None,
                               deleted=None))
        emergency_contact_address_id = Address.create_address(
            cur,
            Address(address_id=None,
                    street='1st street',
                    city='city',
                    states_id=1,
                    postal_code='55555',
                    country_abbreviation='US',
                    created_at=None,
                    updated_at=None,
                    deleted=None))
        emergency_contact_id = EmergencyContact.create_emergency_contact(
            cur,
            EmergencyContact(emergency_contact_id=None,
                             first_name='First',
                             last_name='Last',
                             contact_relationship_id=1,
                             email='*****@*****.**',
                             phone_number='+15555555555',
                             address_id=emergency_contact_address_id,
                             created_at=None,
                             updated_at=None,
                             deleted=None))

        # Get nonexistent
        user_data = UserData.get_user_data(cur, 0)
        assert user_data is None  # Get where user data doesn't exist returns None

        # Create user data
        user_data_id = UserData.create_user_data(
            cur,
            UserData(user_data_id=None,
                     first_name='first',
                     last_name='last',
                     date_of_birth=Date(1998, 1, 10),
                     contact_information_id=contact_information_id,
                     emergency_contact_id=emergency_contact_id,
                     created_at=None,
                     updated_at=None,
                     deleted=None))
        assert user_data_id is not None  # ID was present
        assert user_data_id != 0  # ID was something sensible

        # Get user data
        user_data = UserData.get_user_data(cur, user_data_id)
        assert user_data.id == user_data_id  # ID was set
        assert user_data.first_name == 'first'  # First name was set

        # Update user data
        user_data.first_name = 'second'
        UserData.update_user_data(cur, user_data)
        user_data = UserData.get_user_data(cur, user_data_id)
        assert user_data.first_name == 'second'  # First name was updated

        # Delete user data
        UserData.delete_user_data(cur, user_data_id)
        user_data = UserData.get_user_data(cur, user_data_id)
        assert user_data is None  # None is returned when deleted is true

        # Double-check that row still exists with manual query
        cur.execute('SELECT * FROM user_data WHERE id=%s', (user_data_id, ))
        assert cur.rowcount == 1  # Ensure we got a row
        user_data = UserData.user_data_from_tuple(cur.fetchone())
        assert user_data.deleted  # Make sure row still exists, and deleted is true

        # Ensure we can commit without violating constraints
        conn.commit()

        pass