import pytest

general_permissions = {}

ncircc_permissions = {'can_view_company_card', 'can_edit_company_card', 'can_view_message_list',
                      'can_view_message_card', 'can_edit_message_card'}

DEFAULT_GROUPS_TEST = (

    ('Оператор', 10,
     {'can_view_incidents_list', 'can_view_incidents', 'can_add_widgets', 'can_view_storage', 'can_view_network',
      'can_edit_message_card', 'can_view_message_card', 'can_view_message_list', 'can_edit_company_card',
      'can_view_company_card'}),
    ('Офицер безопасности 1 уровня', 15,
     {'can_view_incidents_list', 'can_view_incidents', 'can_work_with_incidents', 'can_view_events',
      'can_view_asset', 'can_view_events_list', 'can_view_assets_list', 'can_add_widgets', 'can_view_storage',
      'can_view_network', 'can_edit_message_card', 'can_view_message_card', 'can_view_message_list', 'can_edit_company_card',
      'can_view_company_card'})

)


@pytest.mark.skipif(reason="Skipped before the rights model is recycled")
@pytest.mark.unit
@pytest.mark.django_db
@pytest.mark.parametrize('group_name, permissions_count, expected_permissions', DEFAULT_GROUPS_TEST)
def test_migrations_0006_add_default_groups(group_name: str, permissions_count: int, expected_permissions: set,
                                            migrator):
    migrator.apply_initial_migration(('perms', '0005_auto_20210124_1727'))
    new_state = migrator.apply_tested_migration(('perms', '0006_add_default_groups'))
    Group = new_state.apps.get_model('auth', 'Group')

    groups = Group.objects.filter(name=group_name)
    assert len(groups) == 1
    permissions = set(groups[0].permissions.values_list('codename', flat=True))
    assert len(permissions) == permissions_count
    assert permissions == expected_permissions
