# Path: spec/python/db_connection.py
# TEST_DATABASE_MYSQL = 'samapper_test'
# TEST_DATABASE_SQLITE = '/tmp/sam_test.db'
# class Mocker(object):
# class Session(dict):
# class env(object):
#     def __init__(self, *args, **kwargs):
#     def __getitem__(self, k):
#     def __setitem__(self, k, v):
#     def __getattr__(self, name):
#         def receiver(*args, **kwargs):
#     def __call__(self, *args, **kwargs):
#     def clear(self):
#     def was_called(self, name, *args, **kwargs):
#     def kill(self):
#     def __init__(self, mock_input=False, login_active=None, mock_session=False, mock_render=False, lang='en'):
#     def __enter__(self):
#     def __exit__(self, type, value, traceback):
# def make_timestamp(timestring):
# def unix_timestamp_to_datetime(stamp):
# def get_test_db_connection():
# def setup_datasources(db, sub_id):
# def template_sql(path, *args):
# def setup_network(db, sub_id, ds_id):
# def setup_node_extras(sub_id):


import os
import requests
import cPickle
import threading
import multiprocessing
import time
import signal
from spec.python import db_connection
from sam import server_collector
from sam.importers.import_tcpdump import TCPDumpImporter
from sam.importers.import_paloalto import PaloAltoImporter
            "length 43",
        "1491525947.915376 ARP, Request who-has 192.168.10.106 tell 192.168.10.254, length 46",
        "1491525948.268015 IP 192.168.10.113.33060 > 172.217.3.196.443: Flags [P.], seq 256:730, "
            "ack 116, win 3818, options [nop,nop,TS val 71847613 ecr 4161606244], length 474",
        "1491525737.317942 IP 192.168.10.254.1900 > 239.238.237.236.55943: UDP, length 166, "
            "other info",
        "1491525737.317942 IP 192.168.10.254.55943 > 239.255.255.250.1900: UDP, length 449",
        "",
        "nonsensical entry",
        "",
    ]
    map(buffer.store_data, buffer_data)

    collector = server_collector.Collector()
    collector.importer = TCPDumpImporter()
    assert len(buffer) == 9
    assert collector.transmit_buffer == []
    assert collector.transmit_buffer_size == 0

    collector.import_packets()
    assert len(buffer) == 0
    assert len(collector.transmit_buffer) == 3
    assert collector.transmit_buffer_size == 3


def test_transmit_lines():
    collector = server_collector.Collector()
    collector.transmit_buffer = ['data1', 'data2', 'data3']
    old_request = requests.request
    try:

# Path: spec/python/db_connection.py
# TEST_DATABASE_MYSQL = 'samapper_test'
# TEST_DATABASE_SQLITE = '/tmp/sam_test.db'
# class Mocker(object):
# class Session(dict):
# class env(object):
#     def __init__(self, *args, **kwargs):
#     def __getitem__(self, k):
#     def __setitem__(self, k, v):
#     def __getattr__(self, name):
#         def receiver(*args, **kwargs):
#     def __call__(self, *args, **kwargs):
#     def clear(self):
#     def was_called(self, name, *args, **kwargs):
#     def kill(self):
#     def __init__(self, mock_input=False, login_active=None, mock_session=False, mock_render=False, lang='en'):
#     def __enter__(self):
#     def __exit__(self, type, value, traceback):
# def make_timestamp(timestring):
# def unix_timestamp_to_datetime(stamp):
# def get_test_db_connection():
# def setup_datasources(db, sub_id):
# def template_sql(path, *args):
# def setup_network(db, sub_id, ds_id):
# def setup_node_extras(sub_id):


# Path: spec/python/test_collector.py
import os
import requests
import cPickle
import threading
import multiprocessing
import time
import signal
from spec.python import db_connection
from sam import server_collector
from sam.importers.import_tcpdump import TCPDumpImporter
from sam.importers.import_paloalto import PaloAltoImporter

            "length 43",
        "1491525947.915376 ARP, Request who-has 192.168.10.106 tell 192.168.10.254, length 46",
        "1491525948.268015 IP 192.168.10.113.33060 > 172.217.3.196.443: Flags [P.], seq 256:730, "
            "ack 116, win 3818, options [nop,nop,TS val 71847613 ecr 4161606244], length 474",
        "1491525737.317942 IP 192.168.10.254.1900 > 239.238.237.236.55943: UDP, length 166, "
            "other info",
        "1491525737.317942 IP 192.168.10.254.55943 > 239.255.255.250.1900: UDP, length 449",
        "",
        "nonsensical entry",
        "",
    ]
    map(buffer.store_data, buffer_data)

    collector = server_collector.Collector()
    collector.importer = TCPDumpImporter()
    assert len(buffer) == 9
    assert collector.transmit_buffer == []
    assert collector.transmit_buffer_size == 0

    collector.import_packets()
    assert len(buffer) == 0
    assert len(collector.transmit_buffer) == 3
    assert collector.transmit_buffer_size == 3


def test_transmit_lines():
    collector = server_collector.Collector()
    collector.transmit_buffer = ['data1', 'data2', 'data3']
    old_request = requests.request
    try:

        mocker = db_connection.Mocker()