import sys sys.path.insert(0, '../agents/host_master/') from host_master import HostMaster from agents.util import create_session, create_agent_fixture # fixtures agent = create_agent_fixture(HostMaster) def test_host_master_update_not_running(agent): session = create_session('update') res = agent.update(session, params=None) assert res[0] is False
create_agent_fixture, create_session, generate_data_for_queue ) try: # depends on spt3g from aggregator_agent import AggregatorAgent args = mock.MagicMock() args.time_per_file = 3 args.data_dir = '/tmp/data' # start idle so we can use a tmpdir for data_dir args.initial_state = 'idle' agent = create_agent_fixture(AggregatorAgent, {'args': args}) except ModuleNotFoundError as e: print(f"Unable to import: {e}") @pytest.mark.spt3g @pytest.mark.dependency(depends=['so3g'], scope='session') class TestRecord: def test_aggregator_agent_record_no_data(self, agent, tmpdir): # repoint data_dir to tmpdir fixture agent.data_dir = tmpdir session = create_session('record') params = {'test_mode': True} res = agent.record(session, params)
create_agent_fixture, create_session, generate_data_for_queue ) # fixtures args = mock.MagicMock() args.initial_state = 'idle' # start idle so we can use a tmpdir for data_dir args.host = 'localhost' args.port = 8086 args.database = 'ocs_feeds' args.protocol = 'line' args.gzip = False agent = create_agent_fixture(InfluxDBAgent, {'args': args}) class TestRecord: @mock.patch('ocs.agent.influxdb_publisher.InfluxDBClient', mock.MagicMock()) def test_influxdb_publisher_record(self, agent): session = create_session('record') params = {'test_mode': True} res = agent.record(session, params) assert res[0] is True @mock.patch('ocs.agent.influxdb_publisher.InfluxDBClient', mock.MagicMock())
import sys sys.path.insert(0, '../agents/registry/') import time import pytest import pytest_twisted from agents.util import create_session, create_agent_fixture from registry import Registry agent = create_agent_fixture(Registry) class TestMain: @pytest_twisted.inlineCallbacks def test_registry_main(self, agent): session = create_session('main') # Fake a heartbeat by directly registering an Agent # op_codes, feed op_codes = {'operation1': 5, 'operation2': 1} heartbeat_example = [ op_codes, { "agent_address": "observatory.test_agent", "agg_params": {}, "feed_name": "heartbeat", "address": "observatory.test_agent.feeds.heartbeat", "record": False, "session_id": str(time.time()) }
import sys sys.path.insert(0, '../agents/fake_data/') from fake_data_agent import FakeDataAgent import pytest_twisted from agents.util import create_session, create_agent_fixture # fixtures agent = create_agent_fixture(FakeDataAgent) def test_fake_data_set_heartbeat(agent): session = create_session('set_heartbeat') res = agent.set_heartbeat(session, {'heartbeat': True}) print(res) print(session.encoded()) assert res[0] is True def test_fake_data_acq(agent): session = create_session('acq') params = {'test_mode': True} res = agent.acq(session, params=params) assert res[0] is True assert 'fields' in session.data assert 'timestamp' in session.data channels = ['channel_00', 'channel_01'] assert all([ch in channels for ch in session.data['fields']])