# Path: tenable_io/api/exclusions.py
# class ExclusionEditRequest(ExclusionSaveBaseRequest):
# 
#     def __init__(
#             self,
#             name=None,
#             members=None,
#             description=None,
#             schedule=None
#     ):
#         super(ExclusionEditRequest, self).__init__(name, members, description, schedule)
# 
# Path: tenable_io/api/models.py
# class Exclusion(BaseModel):
#     def __init__(
#             self,
#             id=None,
#             name=None,
#             description=None,
#             schedule=None,
#             creation_date=None,
#             last_modification_date=None,
#             members=None,
#     ):
#         self._schedule = None
# 
#         self.id = id
#         self.name = name
#         self.description = description
#         self.schedule = schedule
#         self.creation_date = creation_date
#         self.last_modification_date = last_modification_date
#         self.members = members
# 
#     @property
#     def schedule(self):
#         return self._schedule
# 
#     @schedule.setter
#     @BaseModel._model(ExclusionSchedule)
#     def schedule(self, schedule):
#         self._schedule = schedule
# 
# class ExclusionList(BaseModel):
#     def __init__(
#             self,
#             exclusions=None
#     ):
#         self._exclusions = None
#         self.exclusions = exclusions
# 
#     @property
#     def exclusions(self):
#         return self._exclusions
# 
#     @exclusions.setter
#     @BaseModel._model_list(Exclusion)
#     def exclusions(self, exclusions):
#         self._exclusions = exclusions


import pytest
import os
from tenable_io.api.exclusions import ExclusionEditRequest
from tenable_io.api.models import Exclusion, ExclusionList
    edited_exclusion_name = 'test_exclusion_name_edited'
    edit_request = ExclusionEditRequest(
        edited_exclusion_name,
        exclusion.members
    )
    edited_exclusion = client.exclusions_api.edit(exclusion.id, edit_request)
    assert isinstance(edited_exclusion, Exclusion), u'The `edit` method did not return type `Exclusion`.'
    assert edited_exclusion.name == edited_exclusion_name, u'Expected name to be updated.'

@pytest.mark.vcr()
def test_exclusions_delete(client, new_exclusion):
    assert client.exclusions_api.delete(new_exclusion.id), u'Exclusion was not deleted.'

@pytest.mark.vcr()
def test_exclusions_import(client):
    import_exclusion_name = 'test_exclusion_name_imported'
    path = u'test_exclusions_import'
    with open(path, 'w') as f:
        f.write('id,name,description,members,creation_date,last_modification_date\n3,"{}","11","test.host.com",1562002566,1562002566'.format(import_exclusion_name))
    assert os.path.getsize(path) > 0, u'The exclusion file is not empty.'

    with open(path, 'rb') as fu:
        upload_file_name = client.file_api.upload(fu)
    assert upload_file_name, u'File `upload` method returns valid file name.'

    client.exclusions_api.import_exclusion(upload_file_name)
    exclusion_list = client.exclusions_api.list()
    assert len(exclusion_list.exclusions) > 0, u'Expected exclusions to be returned.'
    exlcusion_names = [ex.name for ex in exclusion_list.exclusions]
    assert import_exclusion_name in exlcusion_names, u'Expected imported exclusion to be returned.'

# Path: tenable_io/api/exclusions.py
# class ExclusionEditRequest(ExclusionSaveBaseRequest):
# 
#     def __init__(
#             self,
#             name=None,
#             members=None,
#             description=None,
#             schedule=None
#     ):
#         super(ExclusionEditRequest, self).__init__(name, members, description, schedule)
# 
# Path: tenable_io/api/models.py
# class Exclusion(BaseModel):
#     def __init__(
#             self,
#             id=None,
#             name=None,
#             description=None,
#             schedule=None,
#             creation_date=None,
#             last_modification_date=None,
#             members=None,
#     ):
#         self._schedule = None
# 
#         self.id = id
#         self.name = name
#         self.description = description
#         self.schedule = schedule
#         self.creation_date = creation_date
#         self.last_modification_date = last_modification_date
#         self.members = members
# 
#     @property
#     def schedule(self):
#         return self._schedule
# 
#     @schedule.setter
#     @BaseModel._model(ExclusionSchedule)
#     def schedule(self, schedule):
#         self._schedule = schedule
# 
# class ExclusionList(BaseModel):
#     def __init__(
#             self,
#             exclusions=None
#     ):
#         self._exclusions = None
#         self.exclusions = exclusions
# 
#     @property
#     def exclusions(self):
#         return self._exclusions
# 
#     @exclusions.setter
#     @BaseModel._model_list(Exclusion)
#     def exclusions(self, exclusions):
#         self._exclusions = exclusions


# Path: tests/integration/api/test_exclusions.py
import pytest
import os
from tenable_io.api.exclusions import ExclusionEditRequest
from tenable_io.api.models import Exclusion, ExclusionList

    edited_exclusion_name = 'test_exclusion_name_edited'
    edit_request = ExclusionEditRequest(
        edited_exclusion_name,
        exclusion.members
    )
    edited_exclusion = client.exclusions_api.edit(exclusion.id, edit_request)
    assert isinstance(edited_exclusion, Exclusion), u'The `edit` method did not return type `Exclusion`.'
    assert edited_exclusion.name == edited_exclusion_name, u'Expected name to be updated.'

@pytest.mark.vcr()
def test_exclusions_delete(client, new_exclusion):
    assert client.exclusions_api.delete(new_exclusion.id), u'Exclusion was not deleted.'

@pytest.mark.vcr()
def test_exclusions_import(client):
    import_exclusion_name = 'test_exclusion_name_imported'
    path = u'test_exclusions_import'
    with open(path, 'w') as f:
        f.write('id,name,description,members,creation_date,last_modification_date\n3,"{}","11","test.host.com",1562002566,1562002566'.format(import_exclusion_name))
    assert os.path.getsize(path) > 0, u'The exclusion file is not empty.'

    with open(path, 'rb') as fu:
        upload_file_name = client.file_api.upload(fu)
    assert upload_file_name, u'File `upload` method returns valid file name.'

    client.exclusions_api.import_exclusion(upload_file_name)
    exclusion_list = client.exclusions_api.list()
    assert len(exclusion_list.exclusions) > 0, u'Expected exclusions to be returned.'
    exlcusion_names = [ex.name for ex in exclusion_list.exclusions]
    assert import_exclusion_name in exlcusion_names, u'Expected imported exclusion to be returned.'

    os.remove(path)