# Copyright 2014 DreamHost, LLC
#
# Author: DreamHost, LLC
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
#      http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.


import mock
import unittest2 as unittest

from akanda.rug import debug


class TestDebug(unittest.TestCase):

    @mock.patch('akanda.rug.worker.WorkerContext')
    @mock.patch('akanda.rug.state.Automaton')
    @mock.patch('pdb.set_trace')
    def test_debug_one_router(self, set_trace, automaton, ctx):
        ctx.return_value.neutron.get_router_detail.return_value = mock.Mock(
            tenant_id='123'
        )
        debug.debug_one_router(['--router-id', 'X'])

        ctx.return_value.neutron.get_router_detail.assert_called_once_with('X')
        assert set_trace.called
        automaton.assert_called_once_with(
            'X',
            '123',
            debug.delete_callback,
            debug.bandwidth_callback,
            ctx.return_value,
            100
        )

        class CrudMatch(object):

            def __init__(self, crud):
                self.crud = crud

            def __eq__(self, other):
                return self.crud == other.crud

        automaton.return_value.send_message.assert_called_once_with(
            CrudMatch('update')
        )
        automaton.return_value.update.assert_called

@@ -1241,16 +1241,26 @@
         
+router_id=
 'X',%0A   
@@ -1268,16 +1268,26 @@
         
+tenant_id=
 '123',%0A 
@@ -1289,32 +1289,48 @@
 3',%0A            
+delete_callback=
 debug.delete_cal
@@ -1344,24 +1344,43 @@
             
+bandwidth_callback=
 debug.bandwi
@@ -1397,32 +1397,47 @@
 ck,%0A            
+worker_context=
 ctx.return_value
@@ -1454,11 +1454,74 @@
     
-100
+queue_warning_threshold=100,%0A            reboot_error_threshold=1,
 %0A   

update debug test