def test_load_data_missing_attribute(sample_data, jm, mock_post_json_data, initial_data):
    """
    Test that no objects is inserted in the object store if there is a missing attribute
    """
    tpda = TreeherderPulseDataAdapter(
        loaddata=True,
        durable=False,
        logdir='logs',
        rawdata=False,
        outfile=None
    )

    msg = Message()

    for data in sample_data.raw_pulse_data[:1]:
        # change the branch (aka project) name on the raw data,
        # so that we can use the dataset created by jm

        # delete the buildid attribute
        data['payload']['build']['properties'][4][0] = ""
        data['payload']['build']['properties'][1][1] = jm.project
        tpda.process_data(data, msg)

    stored_obj = jm.get_os_dhub().execute(
        proc="objectstore_test.selects.all")

    jm.disconnect()

    assert len(stored_obj) == 0
def test_load_data(sample_data, jm, mock_post_json_data,
                   initial_data, mock_get_resultset):
    """
    Test the ability of TreeherderPulseDataAdapter to load its transformed
    data through the restful api
    """
    tpda = TreeherderPulseDataAdapter(
        loaddata=True,
        durable=False,
        logdir='logs',
        rawdata=False,
        outfile=None
    )

    msg = Message()

    for data in sample_data.raw_pulse_data[:1]:
        # change the branch (aka project) name on the raw data,
        # so that we can use the dataset created by jm
        data['payload']['build']['properties'][1][1] = jm.project
        data = tpda.process_data(data, msg)

    stored_obj = jm.get_os_dhub().execute(
        proc="objectstore_test.selects.all")

    jm.disconnect()

    assert len(stored_obj) == 1
    def handle(self, *args, **options):

        start = options.get("start")
        restart = options.get("restart")
        stop = options.get("stop")
        daemon = options.get("daemon")
        pidfile = options.get("pidfile")
        durable = options.get("durable")
        logdir = options.get("logdir")
        rawdata = options.get("rawdata")
        outfile = options.get("outfile")

        tda = TreeherderPulseDataAdapter(
            durable=durable,
            logdir=logdir,
            rawdata=rawdata,
            outfile=outfile,
            loaddata=True
        )

        if start:

            if daemon:

                th_daemon = TreeherderPulseDaemon(
                    pidfile, treeherder_data_adapter=tda, stdin='/dev/null',
                    stdout='/dev/null', stderr='/dev/null'
                )

                th_daemon.start()

            else:
                #Run the pulse consumer without becoming
                #a daemon
                tda.start()

        else:

            th_daemon = TreeherderPulseDaemon(
                pidfile, treeherder_data_adapter=tda, stdin='/dev/null',
                stdout='/dev/null', stderr='/dev/null'
            )

            if restart:
                th_daemon.restart()
            elif stop:
                th_daemon.stop()
    def handle(self, *args, **options):

        start = options.get("start")
        restart = options.get("restart")
        stop = options.get("stop")
        daemon = options.get("daemon")
        pidfile = options.get("pidfile")
        durable = options.get("durable")
        logdir = options.get("logdir")
        rawdata = options.get("rawdata")
        outfile = options.get("outfile")

        tda = TreeherderPulseDataAdapter(durable=durable,
                                         logdir=logdir,
                                         rawdata=rawdata,
                                         outfile=outfile,
                                         loaddata=True)

        if start:

            if daemon:

                th_daemon = TreeherderPulseDaemon(pidfile,
                                                  treeherder_data_adapter=tda,
                                                  stdin='/dev/null',
                                                  stdout='/dev/null',
                                                  stderr='/dev/null')

                th_daemon.start()

            else:
                #Run the pulse consumer without becoming
                #a daemon
                tda.start()

        else:

            th_daemon = TreeherderPulseDaemon(pidfile,
                                              treeherder_data_adapter=tda,
                                              stdin='/dev/null',
                                              stdout='/dev/null',
                                              stderr='/dev/null')

            if restart:
                th_daemon.restart()
            elif stop:
                th_daemon.stop()