import time, datetime

from twisted.trial import unittest
from twisted.internet import defer

from dateutil.tz import tzutc

from opennsa import nsa
from opennsa.backends import dud




class DUDBackendTest(unittest.TestCase):

    def setUp(self):
        self.backend = dud.DUDNSIBackend('TestDUD')

        source_stp  = nsa.STP('Aruba', 'A1' )
        dest_stp    = nsa.STP('Aruba', 'A3' )
        start_time = datetime.datetime.fromtimestamp(time.time() + 0.1, tzutc() )
        end_time   = datetime.datetime.fromtimestamp(time.time() + 10,  tzutc() )
        bandwidth = 200

        self.service_params  = nsa.ServiceParameters(start_time, end_time, source_stp, dest_stp, bandwidth)


    @defer.inlineCallbacks
    def testBasicUsage(self):

        conn = self.backend.createConnection('A1', 'A3', self.service_params)

        yield conn.reserve()

        da, dp = conn.provision()
        yield da # provision acknowledged
        yield dp # provision performed

        yield conn.release()

        yield conn.terminate()


@@ -743,17 +743,16 @@
 (self):%0A
-%0A
         
@@ -821,17 +821,16 @@
 params)%0A
-%0A
         
@@ -850,25 +850,24 @@
 serve()%0A
-%0A
         
 da, dp =
@@ -862,16 +862,13 @@
     
-da, dp =
+yield
  con
@@ -885,90 +885,8 @@
 n()%0A
-        yield da # provision acknowledged%0A        yield dp # provision performed%0A%0A
     
@@ -910,17 +910,16 @@
 lease()%0A
-%0A
         

update dud backend test to new interface