from sentinels import NOTHING

from .api_object import APIObject
from .lazy_query import LazyQuery
from .metadata_holder import MetadataHolder

class Session(APIObject, MetadataHolder):

    def report_end(self, duration=NOTHING):
        self.client.api.call_function('report_session_end', {'id': self.id, 'duration': duration})

    def report_test_start(self, name=NOTHING, test_logical_id=NOTHING):
        return self.client.api.call_function('report_test_start', {'session_id': self.id,
                                                                   'test_logical_id': test_logical_id, 'name': name})


    def add_subject(self, name, product=NOTHING, version=NOTHING, revision=NOTHING):
        return self.client.api.call_function(
            'add_subject',
            {'session_id': self.id, 'name': name, 'product': product, 'version': version, 'revision': revision})

    def add_error_data(self, exception, exception_type, traceback, timestamp=NOTHING):
        return self.client.api.call_function('add_session_error_data', {'id': self.id,
                                                                        'exception': exception,
                                                                        'exception_type': exception_type,
                                                                        'traceback': traceback,
                                                                        'timestamp': timestamp
                                                                        })

    def edit_status(self, status):
        return self.client.api.call_function('edit_session_status', {'id': self.id, 'status': status})

    def query_tests(self):
        """Queries tests of the current session

        :rtype: A lazy query object
        """
        return LazyQuery(self.client, '/rest/sessions/{0}/tests'.format(self.id))

    def query_errors(self):
        """Queries tests of the current session

        :rtype: A lazy query object
        """
        return LazyQuery(self.client, '/rest/errors', query_params={'session_id': self.id})

@@ -352,24 +352,55 @@
 start(self, 
+name, file_name=NOTHING, class_
 name=NOTHING
@@ -464,32 +464,45 @@
 i.call_function(
+%0A            
 'report_test_sta
@@ -505,16 +505,28 @@
 _start',
+%0A           
  %7B'sessi
@@ -559,49 +559,98 @@
     
-                                         
+'name': name,%0A             'class_name': class_name,%0A             'file_name': file_name,%0A
     
@@ -692,30 +692,16 @@
 gical_id
-, 'name': name
 %7D)%0A%0A%0A   

Work on test information