# Path: raspi/scripts/gwf.py
# RANDOM_DELAY_PARAM = 300
# SYNC_TIMEOUT = 5
# ENV_TYPE = "prod"
# GET_SERIAL_FAILURE_WAIT = 60
# NETWORKING_RESTART_WAIT = 30
# def get_process(args):
# def perform_command_and_validate(process, err_msg):
# def check_if_wifi_available():
# def check_if_synced():
# def perform_ntp_sync():
# def execute_get_serial(env_type):
# def main():


import datetime
from mock import Mock, patch
from nose.tools import assert_raises, eq_
from raspi.scripts import gwf
Tests to ensure that gwf works so we avoid all issues we've ran into
in the past.
"""




class MockProcess(object):
    def __init__(self, stdout, stderr, rc):
        self.stdout = stdout
        self.stderr = stderr
        self.returncode = rc

    def communicate(self):
        return self.stdout, self.stderr


def test_perform_command_and_validate_on_success():
    stdout = "foo"
    stderr = ""
    proc = MockProcess(stdout, stderr, 0)
    out, err = gwf.perform_command_and_validate(proc, "Shouldn't happen")
    eq_(out, stdout)
    eq_(err, stderr)


def test_perform_command_and_validate_on_error():
    stdout = "foo"
    stderr = "bar"
    proc = MockProcess(stdout, stderr, 1)

# Path: raspi/scripts/gwf.py
# RANDOM_DELAY_PARAM = 300
# SYNC_TIMEOUT = 5
# ENV_TYPE = "prod"
# GET_SERIAL_FAILURE_WAIT = 60
# NETWORKING_RESTART_WAIT = 30
# def get_process(args):
# def perform_command_and_validate(process, err_msg):
# def check_if_wifi_available():
# def check_if_synced():
# def perform_ntp_sync():
# def execute_get_serial(env_type):
# def main():


# Path: raspi/tests/test_gwf.py
import datetime
from mock import Mock, patch
from nose.tools import assert_raises, eq_
from raspi.scripts import gwf

Tests to ensure that gwf works so we avoid all issues we've ran into
in the past.
"""




class MockProcess(object):
    def __init__(self, stdout, stderr, rc):
        self.stdout = stdout
        self.stderr = stderr
        self.returncode = rc

    def communicate(self):
        return self.stdout, self.stderr


def test_perform_command_and_validate_on_success():
    stdout = "foo"
    stderr = ""
    proc = MockProcess(stdout, stderr, 0)
    out, err = gwf.perform_command_and_validate(proc, "Shouldn't happen")
    eq_(out, stdout)
    eq_(err, stderr)


def test_perform_command_and_validate_on_error():
    stdout = "foo"
    stderr = "bar"
    proc = MockProcess(stdout, stderr, 1)

    assert_raises(Exception, gwf.perform_command_and_validate, proc, "blah")