# Path: tenable_io/api/scans.py
# class ScanExportRequest(BaseRequest):
# 
#     CHAPTER_COMPLIANCE = u'compliance'
#     CHAPTER_COMPLIANCE_EXEC = u'compliance_exec'
#     CHAPTER_CUSTOM_VULN_BY_HOST = u'vuln_by_host'
#     CHAPTER_CUSTOM_VULN_BY_PLUGIN = u'vuln_by_plugin'
#     CHAPTER_EXECUTIVE_SUMMARY = u'vuln_hosts_summary'
#     CHAPTER_REMEDIATIONS = u'remediations'
# 
#     FORMAT_CSV = u'csv'
#     FORMAT_DB = u'db'
#     FORMAT_HTML = u'html'
#     FORMAT_NESSUS = u'nessus'
#     FORMAT_PDF = u'pdf'
# 
#     WAS_EXPORT_TYPE = u'web-app'
# 
#     def __init__(
#             self,
#             format,
#             password=None,
#             chapters=None,
#     ):
#         assert format in [
#             ScanExportRequest.FORMAT_CSV,
#             ScanExportRequest.FORMAT_DB,
#             ScanExportRequest.FORMAT_HTML,
#             ScanExportRequest.FORMAT_NESSUS,
#             ScanExportRequest.FORMAT_PDF,
#         ]
#         assert chapters in [
#             None,
#             ScanExportRequest.CHAPTER_COMPLIANCE,
#             ScanExportRequest.CHAPTER_COMPLIANCE_EXEC,
#             ScanExportRequest.CHAPTER_CUSTOM_VULN_BY_HOST,
#             ScanExportRequest.CHAPTER_CUSTOM_VULN_BY_PLUGIN,
#             ScanExportRequest.CHAPTER_EXECUTIVE_SUMMARY,
#             ScanExportRequest.CHAPTER_REMEDIATIONS,
#         ]
#         self.format = format
#         self.password = password
#         self.chapters = chapters
# 
#     def as_payload(self, filter_=None):
#         return super(ScanExportRequest, self).as_payload(True)
# 
# Path: tests/config.py
# class TenableIOTestConfig(object):
# 
#     @staticmethod
#     def get(key):
#         return config.get('tenable_io-test', key)


import os
import pytest
from time import time
from random import randint
from tenable_io.api.scans import ScanExportRequest
from tests.config import TenableIOTestConfig


def create_scan(client):
    """
    Create a scan for testing.
    """
    return client.scan_helper.create(
        'test_scan_{}'.format(randint(0, 1000)),
        TenableIOTestConfig.get('scan_text_targets'),
        TenableIOTestConfig.get('scan_template_name')
    )


@pytest.mark.vcr()
def test_scan_helper_details(client):
    scan = create_scan(client)
    scan_detail = scan.details()
    assert scan_detail.info.object_id == scan.id, u'ScanRef `id` should match ID in ScanDetail.'


@pytest.mark.skip(reason="CI-16072 & CI-15053")
@pytest.mark.vcr()
def test_scan_helper_alt_target_launch_stop_download_import(client):
    scan = create_scan(client)
    download_path = 'test_scan_launch_download'

    assert not os.path.isfile(download_path), u'Scan report does not yet exist.'

    alt_targets = [TenableIOTestConfig.get('scan_alt_targets')]
    histories = scan.launch(wait=True, alt_targets=alt_targets).stop()\

# Path: tenable_io/api/scans.py
# class ScanExportRequest(BaseRequest):
# 
#     CHAPTER_COMPLIANCE = u'compliance'
#     CHAPTER_COMPLIANCE_EXEC = u'compliance_exec'
#     CHAPTER_CUSTOM_VULN_BY_HOST = u'vuln_by_host'
#     CHAPTER_CUSTOM_VULN_BY_PLUGIN = u'vuln_by_plugin'
#     CHAPTER_EXECUTIVE_SUMMARY = u'vuln_hosts_summary'
#     CHAPTER_REMEDIATIONS = u'remediations'
# 
#     FORMAT_CSV = u'csv'
#     FORMAT_DB = u'db'
#     FORMAT_HTML = u'html'
#     FORMAT_NESSUS = u'nessus'
#     FORMAT_PDF = u'pdf'
# 
#     WAS_EXPORT_TYPE = u'web-app'
# 
#     def __init__(
#             self,
#             format,
#             password=None,
#             chapters=None,
#     ):
#         assert format in [
#             ScanExportRequest.FORMAT_CSV,
#             ScanExportRequest.FORMAT_DB,
#             ScanExportRequest.FORMAT_HTML,
#             ScanExportRequest.FORMAT_NESSUS,
#             ScanExportRequest.FORMAT_PDF,
#         ]
#         assert chapters in [
#             None,
#             ScanExportRequest.CHAPTER_COMPLIANCE,
#             ScanExportRequest.CHAPTER_COMPLIANCE_EXEC,
#             ScanExportRequest.CHAPTER_CUSTOM_VULN_BY_HOST,
#             ScanExportRequest.CHAPTER_CUSTOM_VULN_BY_PLUGIN,
#             ScanExportRequest.CHAPTER_EXECUTIVE_SUMMARY,
#             ScanExportRequest.CHAPTER_REMEDIATIONS,
#         ]
#         self.format = format
#         self.password = password
#         self.chapters = chapters
# 
#     def as_payload(self, filter_=None):
#         return super(ScanExportRequest, self).as_payload(True)
# 
# Path: tests/config.py
# class TenableIOTestConfig(object):
# 
#     @staticmethod
#     def get(key):
#         return config.get('tenable_io-test', key)


# Path: tests/integration/helpers/test_scan.py
import os
import pytest
from time import time
from random import randint
from tenable_io.api.scans import ScanExportRequest
from tests.config import TenableIOTestConfig



def create_scan(client):
    """
    Create a scan for testing.
    """
    return client.scan_helper.create(
        'test_scan_{}'.format(randint(0, 1000)),
        TenableIOTestConfig.get('scan_text_targets'),
        TenableIOTestConfig.get('scan_template_name')
    )


@pytest.mark.vcr()
def test_scan_helper_details(client):
    scan = create_scan(client)
    scan_detail = scan.details()
    assert scan_detail.info.object_id == scan.id, u'ScanRef `id` should match ID in ScanDetail.'


@pytest.mark.skip(reason="CI-16072 & CI-15053")
@pytest.mark.vcr()
def test_scan_helper_alt_target_launch_stop_download_import(client):
    scan = create_scan(client)
    download_path = 'test_scan_launch_download'

    assert not os.path.isfile(download_path), u'Scan report does not yet exist.'

    alt_targets = [TenableIOTestConfig.get('scan_alt_targets')]
    histories = scan.launch(wait=True, alt_targets=alt_targets).stop()\

        .download(download_path, format=ScanExportRequest.FORMAT_NESSUS).histories()