Exemple #1
0
    def test_disable(self):
        user_id = create_user(enabled=True).id

        user_before = user_command_service._get_user(user_id)
        assert user_before.enabled

        events_before = event_service.get_events_for_user(user_before.id)
        assert len(events_before) == 0

        # -------------------------------- #

        user_command_service.disable_user(user_id, ADMIN_ID)

        # -------------------------------- #

        user_after = user_command_service._get_user(user_id)
        assert not user_after.enabled

        events_after = event_service.get_events_for_user(user_after.id)
        assert len(events_after) == 1

        user_disabled_event = events_after[0]
        assert user_disabled_event.event_type == 'user-disabled'
        assert user_disabled_event.data == {
            'initiator_id': str(ADMIN_ID),
        }
Exemple #2
0
    def test_change_screen_name_with_reason(self):
        old_screen_name = 'Zero_Cool'
        new_screen_name = 'Crash_Override'
        reason = 'Do not reveal to Acid Burn.'

        user_id = create_user(old_screen_name).id

        user_before = user_command_service._get_user(user_id)
        assert user_before.screen_name == old_screen_name

        events_before = event_service.get_events_for_user(user_before.id)
        assert len(events_before) == 0

        # -------------------------------- #

        user_command_service.change_screen_name(user_id, new_screen_name,
                                                ADMIN_ID, reason=reason)

        # -------------------------------- #

        user_after = user_command_service._get_user(user_id)
        assert user_after.screen_name == new_screen_name

        events_after = event_service.get_events_for_user(user_after.id)
        assert len(events_after) == 1

        user_enabled_event = events_after[0]
        assert user_enabled_event.event_type == 'user-screen-name-changed'
        assert user_enabled_event.data == {
            'old_screen_name': old_screen_name,
            'new_screen_name': new_screen_name,
            'initiator_id': str(ADMIN_ID),
            'reason': reason,
        }
def test_change_screen_name_without_reason(app):
    admin_id = app.admin_id

    old_screen_name = 'NameWithTyop'
    new_screen_name = 'NameWithoutTypo'

    user_id = create_user(old_screen_name).id

    # -------------------------------- #

    user_command_service.change_screen_name(user_id, new_screen_name, admin_id)

    # -------------------------------- #

    user_after = user_command_service._get_user(user_id)

    events_after = event_service.get_events_for_user(user_after.id)

    user_enabled_event = events_after[0]
    assert user_enabled_event.event_type == 'user-screen-name-changed'
    assert user_enabled_event.data == {
        'old_screen_name': old_screen_name,
        'new_screen_name': new_screen_name,
        'initiator_id': str(admin_id),
    }
    def test_change_email_address_without_reason(self):
        old_email_address = '*****@*****.**'
        new_email_address = '*****@*****.**'

        user_id = create_user('Propellerhead',
                              email_address=old_email_address).id

        # -------------------------------- #

        user_command_service.change_email_address(user_id, new_email_address,
                                                  ADMIN_ID)

        # -------------------------------- #

        user_after = user_command_service._get_user(user_id)

        events_after = event_service.get_events_for_user(user_after.id)

        user_enabled_event = events_after[0]
        assert user_enabled_event.event_type == 'user-email-address-changed'
        assert user_enabled_event.data == {
            'old_email_address': old_email_address,
            'new_email_address': new_email_address,
            'initiator_id': str(ADMIN_ID),
        }
def test_change_screen_name_with_reason(app):
    admin_id = app.admin_id

    old_screen_name = 'Zero_Cool'
    new_screen_name = 'Crash_Override'
    reason = 'Do not reveal to Acid Burn.'

    user_id = create_user(old_screen_name).id

    user_before = user_command_service._get_user(user_id)
    assert user_before.screen_name == old_screen_name

    events_before = event_service.get_events_for_user(user_before.id)
    assert len(events_before) == 0

    # -------------------------------- #

    event = user_command_service.change_screen_name(user_id,
                                                    new_screen_name,
                                                    admin_id,
                                                    reason=reason)

    # -------------------------------- #

    assert isinstance(event, UserScreenNameChanged)
    assert event.user_id == user_id
    assert event.initiator_id == admin_id
    assert event.old_screen_name == old_screen_name
    assert event.new_screen_name == new_screen_name

    user_after = user_command_service._get_user(user_id)
    assert user_after.screen_name == new_screen_name

    events_after = event_service.get_events_for_user(user_after.id)
    assert len(events_after) == 1

    user_enabled_event = events_after[0]
    assert user_enabled_event.event_type == 'user-screen-name-changed'
    assert user_enabled_event.data == {
        'old_screen_name': old_screen_name,
        'new_screen_name': new_screen_name,
        'initiator_id': str(admin_id),
        'reason': reason,
    }
    def test_change_email_address_with_reason(self):
        old_email_address = '*****@*****.**'
        new_email_address = '*****@*****.**'
        reason = 'Switched providers.'

        user_id = create_user('McCool', email_address=old_email_address).id

        user_before = user_command_service._get_user(user_id)
        assert user_before.email_address == old_email_address

        events_before = event_service.get_events_for_user(user_before.id)
        assert len(events_before) == 0

        # -------------------------------- #

        user_command_service.change_email_address(user_id,
                                                  new_email_address,
                                                  ADMIN_ID,
                                                  reason=reason)

        # -------------------------------- #

        user_after = user_command_service._get_user(user_id)
        assert user_after.email_address == new_email_address

        events_after = event_service.get_events_for_user(user_after.id)
        assert len(events_after) == 1

        user_enabled_event = events_after[0]
        assert user_enabled_event.event_type == 'user-email-address-changed'
        assert user_enabled_event.data == {
            'old_email_address': old_email_address,
            'new_email_address': new_email_address,
            'initiator_id': str(ADMIN_ID),
            'reason': reason,
        }
Exemple #7
0
    def test_change_screen_name_without_reason(self):
        old_screen_name = 'Zero_Cool'
        new_screen_name = 'Crash_Override'

        user_id = create_user(old_screen_name).id

        # -------------------------------- #

        user_command_service.change_screen_name(user_id, new_screen_name,
                                                ADMIN_ID)

        # -------------------------------- #

        user_after = user_command_service._get_user(user_id)

        events_after = event_service.get_events_for_user(user_after.id)

        user_enabled_event = events_after[0]
        assert user_enabled_event.event_type == 'user-screen-name-changed'
        assert user_enabled_event.data == {
            'old_screen_name': old_screen_name,
            'new_screen_name': new_screen_name,
            'initiator_id': str(ADMIN_ID),
        }
Exemple #8
0
def test_delete_account(app, db, permission, role):
    admin_id = app.admin_id

    user_id = UUID('20868b15-b935-40fc-8054-38854ef8509a')
    screen_name = 'GetRidOfMe'
    email_address = '*****@*****.**'
    legacy_id = 22299

    user = create_user_with_detail(screen_name,
                                   user_id=user_id,
                                   email_address=email_address)

    user.legacy_id = legacy_id
    db.session.commit()

    authorization_service.assign_role_to_user(role.id, user_id)

    reason = 'duplicate'

    user_before = user_command_service._get_user(user_id)

    assert user_before.screen_name == screen_name
    assert user_before.email_address == email_address
    assert user_before.deleted == False
    assert user_before.legacy_id == legacy_id

    # details
    assert user_before.detail.first_names is not None
    assert user_before.detail.last_name is not None
    assert user_before.detail.date_of_birth is not None
    assert user_before.detail.country is not None
    assert user_before.detail.zip_code is not None
    assert user_before.detail.city is not None
    assert user_before.detail.street is not None
    assert user_before.detail.phone_number is not None

    # events
    events_before = event_service.get_events_for_user(user_before.id)
    assert len(events_before) == 1
    assert events_before[0].event_type == 'role-assigned'

    # authorization
    assert authorization_service.find_role_ids_for_user(user_id) == {
        'board_moderator'
    }
    assert authorization_service.get_permission_ids_for_user(user_id) == {
        'board_topic_hide'
    }

    # -------------------------------- #

    user_command_service.delete_account(user_id, admin_id, reason=reason)

    # -------------------------------- #

    user_after = user_command_service._get_user(user_id)

    assert user_after.screen_name == 'deleted-20868b15b93540fc805438854ef8509a'
    assert user_after.email_address == '*****@*****.**'
    assert user_after.deleted == True
    assert user_after.legacy_id is None

    # details
    assert user_after.detail.first_names is None
    assert user_after.detail.last_name is None
    assert user_after.detail.date_of_birth is None
    assert user_after.detail.country is None
    assert user_after.detail.zip_code is None
    assert user_after.detail.city is None
    assert user_after.detail.street is None
    assert user_after.detail.phone_number is None

    # avatar
    assert user_after.avatar_selection is None

    # events
    events_after = event_service.get_events_for_user(user_after.id)
    assert len(events_after) == 2

    user_enabled_event = events_after[1]
    assert user_enabled_event.event_type == 'user-deleted'
    assert user_enabled_event.data == {
        'initiator_id': str(admin_id),
        'reason': reason,
    }

    # authorization
    assert authorization_service.find_role_ids_for_user(user_id) == set()
    assert authorization_service.get_permission_ids_for_user(user_id) == set()