'Ensures groups assignments are created and deleted idempotently.'

@ddt.data(*itertools.product(('', 'a', 'ab', 'abc'), repeat=2))
@ddt.unpack
def test_groups(self, initial_groups, expected_groups):

    groups = {}
    for group_name in 'abc':
        groups[group_name] = Group.objects.create(name=group_name)
    user = User.objects.create(username=TEST_USERNAME, email=TEST_EMAIL)
    for group_name in initial_groups:
        user.groups.add(groups[group_name])
    call_command('manage_user', TEST_USERNAME, TEST_EMAIL, '-g', *expected_groups)
    actual_groups = [group.name for group in user.groups.all()]
    self.assertEqual(actual_groups, list(expected_groups))
