예제 #1
0
 def test_createFeed(self, config):
     options = None
     cs = COSMSend(options)
     device = 'device 1'
     port = 'port 1'
     config.assert_called_once_with()
     cs.config = self.config_data
     data = {
         'device':
         device,
         'port':
         port,
         Constants.DataPacket.arrival_time:
         datetime.datetime(2012, 1, 2, 3, 4, 5),
         Constants.DataPacket.current_value:
         10
     }
     cs.createDataStream(device, port, data)
     feed = cs.createFeed(data, device, port)
     pprint.pprint(feed)
     self.assertEqual(feed[Constants.Cosm.title], Constants.Cosm.title)
     self.assertEqual(feed[Constants.Cosm.status], Constants.Cosm.status)
     self.assertEqual(feed[Constants.Cosm.creator], Constants.Cosm.creator)
     self.assertEqual(feed[Constants.Cosm.created], Constants.Cosm.created)
     self.assertEqual(feed[Constants.Cosm.feed], 'url')
     self.assertEqual(feed[Constants.Cosm.email], Constants.Cosm.email)
     self.assertEqual(feed[Constants.Cosm.id], Constants.Cosm.id)
     self.assertEqual(feed[Constants.Cosm.auto_feed_url], ('url', ))
     self.assertEqual(feed[Constants.Cosm.version], Constants.Cosm.version)
     cs.empty_datastream_list()
     cs = None
예제 #2
0
 def test_createFeed( self, config ):
     options = None
     cs = COSMSend( options )
     device = 'device 1'
     port = 'port 1'
     config.assert_called_once_with()
     cs.config = self.config_data
     data = {'device': device,
             'port': port,
             Constants.DataPacket.arrival_time: datetime.datetime( 2012, 1, 2, 3, 4, 5 ),
             Constants.DataPacket.current_value: 10}
     cs.createDataStream( device, port, data )
     feed = cs.createFeed( data, device, port )
     pprint.pprint( feed )
     self.assertEqual( feed[Constants.Cosm.title], Constants.Cosm.title )
     self.assertEqual( feed[Constants.Cosm.status], Constants.Cosm.status )
     self.assertEqual( feed[Constants.Cosm.creator], Constants.Cosm.creator )
     self.assertEqual( feed[Constants.Cosm.created], Constants.Cosm.created )
     self.assertEqual( feed[Constants.Cosm.feed], 'url' )
     self.assertEqual( feed[Constants.Cosm.email], Constants.Cosm.email )
     self.assertEqual( feed[Constants.Cosm.id], Constants.Cosm.id )
     self.assertEqual( feed[Constants.Cosm.auto_feed_url], ( 'url', ) )
     self.assertEqual( feed[Constants.Cosm.version], Constants.Cosm.version )
     cs.empty_datastream_list()
     cs = None
예제 #3
0
 def test_createDataStream(self, config):
     options = None
     cs = COSMSend(options)
     config.assert_called_once_with()
     cs.config = self.config_data
     device = 'device 1'
     port = 'port 1'
     current_value = 10
     data = {
         'device':
         device,
         'port':
         port,
         Constants.DataPacket.units:
         'X',
         Constants.DataPacket.arrival_time:
         datetime.datetime(2012, 1, 2, 3, 4, 5),
         Constants.DataPacket.current_value:
         current_value
     }
     cs.createDataStream(device, port, data)
     item = cs.datastreams.pop()
     self.assertEqual(item[Constants.Cosm.datastream.min_value], 0)
     self.assertEqual(item[Constants.Cosm.datastream.max_value], 100)
     self.assertEqual(item[Constants.Cosm.datastream.tags], 'tags')
     self.assertEqual(item[Constants.DataPacket.current_value],
                      current_value)
     self.assertEqual(item['id'], '1')
예제 #4
0
    def test_createJSONReport( self, config ):
        options = None
        cs = COSMSend( options )
        device = 'device 1'
        port = 'port 1'
        config.assert_called_once_with()
        cs.config = config_data = \
                {'device 1': \
                    {'port 1': \
                        {
                                Constants.Cosm.datastream.tags: 'tag',
                                Constants.Cosm.datastream.cosm_channel: '1',
                                Constants.Cosm.datastream.max_value: 100,
                                Constants.Cosm.datastream.min_value: 0,
                                Constants.Cosm.location.created: 'created',
                                Constants.Cosm.location.disposition: "fixed",
                                Constants.Cosm.location.domain: 'domain',
                                Constants.Cosm.location.exposure: 'exposure',
                                Constants.Cosm.location.latitude: 30.3351807498968,
                                Constants.Cosm.location.longitude: 97.7104604244232 * -1.0,    # Eclipse save causes error
                                Constants.Cosm.location.private: 'private',
                                Constants.Cosm.apikey: 'apikey',
                                Constants.Cosm.auto_feed_url: "https://api.cosm.com/v2/feeds/64451.json",
                                Constants.Cosm.creator: "https://cosm.com/users/gary_pickens",
                                Constants.Cosm.created: 'created',
                                Constants.Cosm.email: "*****@*****.**",
                                Constants.Cosm.feed: "https://api.cosm.com/v2/feeds/64451.json",
                                Constants.Cosm.id: 64451,
                                Constants.Cosm.private: "false",
                                Constants.Cosm.status: "frozen",
                                Constants.Cosm.tags: ["Door", "Temperature"],
                                Constants.Cosm.title: "Garage",
                                Constants.Cosm.updated: 'updated',
                                Constants.Cosm.url: 'url',
                                Constants.Cosm.version: "1.0.0",
                                Constants.Cosm.location_str: 'location',
                                Constants.Cosm.datastreams: 'datastreams',
                            }
                        }
                    }

        data = {'device': device,
                'port': port,
                Constants.DataPacket.arrival_time: datetime.datetime( 2012, 1, 2, 3, 4, 5 ),
                Constants.DataPacket.current_value: 10}
        cs.createDataStream( device, port, data )

        data[Constants.DataPacket.current_value] = 545454
        cs.createDataStream( device, port, data )

        json = cs.createJSONReport( device, port, data )

        pprint.pprint( json )
        cs.empty_datastream_list()
        cs = None
예제 #5
0
    def test_createDataStream_with_bad_no_arrival_time( self, config ):
        options = None
        cs = COSMSend( options )
        config.assert_called_once_with()
        cs.config = self.config_data
        device = 'device 1'
        port = 'port 1'
        data = {'device': device,
                'port': port,
#                Constants.DataPacket.arrival_time: '12:12:12 12/12/13',
                Constants.DataPacket.current_value: 10}
        with self.assertRaisesRegexp( KeyError, 'at is not in data' ):
            cs.createDataStream( device, port, data )
예제 #6
0
 def test_createDataStream_with_bad_no_current_value(self, config):
     options = None
     cs = COSMSend(options)
     config.assert_called_once_with()
     cs.config = self.config_data
     device = 'device 1'
     port = 'port 1'
     data = {
         'device': device,
         'port': port,
         Constants.DataPacket.arrival_time: '12:12:12 12/12/14',
         #                Constants.DataPacket.current_value: 10
     }
     with self.assertRaisesRegexp(KeyError, 'current_value is not in data'):
         cs.createDataStream(device, port, data)
예제 #7
0
 def test_empty_datastream_list( self, config ):
     options = None
     cs = COSMSend( options )
     cs.empty_datastream_list()
     device = 'device 1'
     port = 'port 1'
     config.assert_called_once_with()
     cs.config = self.config_data
     data = {'device': device,
             'port': port,
             Constants.DataPacket.arrival_time: datetime.datetime( 2012, 1, 2, 3, 4, 5 ),
             Constants.DataPacket.current_value: 10}
     self.assertEqual( len( cs.datastreams ), 0 )
     cs.createDataStream( device, port, data )
     cs.createDataStream( device, port, data )
     cs.empty_datastream_list()
예제 #8
0
 def test_createDataStream( self, config ):
     options = None
     cs = COSMSend( options )
     config.assert_called_once_with()
     cs.config = self.config_data
     device = 'device 1'
     port = 'port 1'
     current_value = 10
     data = {'device': device,
             'port': port,
             Constants.DataPacket.units: 'X',
             Constants.DataPacket.arrival_time: datetime.datetime( 2012, 1, 2, 3, 4, 5 ),
             Constants.DataPacket.current_value: current_value}
     cs.createDataStream( device, port, data )
     item = cs.datastreams.pop()
     self.assertEqual( item[Constants.Cosm.datastream.min_value], 0 )
     self.assertEqual( item[Constants.Cosm.datastream.max_value], 100 )
     self.assertEqual( item[Constants.Cosm.datastream.tags], 'tags' )
     self.assertEqual( item[Constants.DataPacket.current_value], current_value )
     self.assertEqual( item['id'], '1' )
예제 #9
0
    def test_createDataStream_with_two_datapoints( self, config ):
        options = None
        cs = COSMSend( options )
        config.assert_called_once_with()
        cs.config = self.config_data
        device = 'device 1'
        port = 'port 1'
        current_value = 10
        data = {'device': device,
                'port': port,
                Constants.DataPacket.units: 'X',
                Constants.DataPacket.action: Constants.DataPacket.accumulate,
                Constants.DataPacket.arrival_time: datetime.datetime( 2012, 1, 2, 3, 4, 5 ),
                Constants.DataPacket.current_value: current_value}
        cs.createDataStream( device, port, data )
#        self.assertListEqual( cs.datapoints['1'], [{'at':'2012-01-02T03:04:05', 'value': 10}] )
        cs.createDataStream( device, port, data )
#        self.assertListEqual( cs.datapoints['1'], [{'at':'2012-01-02T03:04:05', 'value': 10}, {'at':'2012-01-02T03:04:05', 'value': 10}] )

        data = {'device': device,
                'port': port,
                Constants.DataPacket.units: 'X',
                Constants.DataPacket.action: Constants.DataPacket.accumulate,
                Constants.DataPacket.action: Constants.DataPacket.send,
                Constants.DataPacket.arrival_time: datetime.datetime( 2012, 1, 2, 3, 4, 6 ),
                Constants.DataPacket.current_value: 11}

        cs.createDataStream( device, port, data )
        self.assertListEqual( cs.datapoints['1'], [] )
예제 #10
0
 def test_empty_datastream_list(self, config):
     options = None
     cs = COSMSend(options)
     cs.empty_datastream_list()
     device = 'device 1'
     port = 'port 1'
     config.assert_called_once_with()
     cs.config = self.config_data
     data = {
         'device':
         device,
         'port':
         port,
         Constants.DataPacket.arrival_time:
         datetime.datetime(2012, 1, 2, 3, 4, 5),
         Constants.DataPacket.current_value:
         10
     }
     self.assertEqual(len(cs.datastreams), 0)
     cs.createDataStream(device, port, data)
     cs.createDataStream(device, port, data)
     cs.empty_datastream_list()
예제 #11
0
 def test_output_with_exception( self, c ):
     options = MagicMock( in_test_mode=False )
     device = 'device'
     port = 'port'
     data = {Constants.DataPacket.device: device,
             Constants.DataPacket.port: port}
     cs = COSMSend( options )
     cs.createDataStream = Mock()
     cs.createJSONReport = Mock()
     cs.report_data = Mock( side_effect=Exception( 'Test' ) )
     cs.output( data )
     cs.createDataStream.called_once_with( device, port, data )
     cs.createJSONReport.called_once_with( device, port, data )
     cs.report_data.called_once_with( device, port, data )
예제 #12
0
 def test_output_with_exception(self, c):
     options = MagicMock(in_test_mode=False)
     device = 'device'
     port = 'port'
     data = {
         Constants.DataPacket.device: device,
         Constants.DataPacket.port: port
     }
     cs = COSMSend(options)
     cs.createDataStream = Mock()
     cs.createJSONReport = Mock()
     cs.report_data = Mock(side_effect=Exception('Test'))
     cs.output(data)
     cs.createDataStream.called_once_with(device, port, data)
     cs.createJSONReport.called_once_with(device, port, data)
     cs.report_data.called_once_with(device, port, data)
예제 #13
0
    def test_createDataStream_with_two_datapoints(self, config):
        options = None
        cs = COSMSend(options)
        config.assert_called_once_with()
        cs.config = self.config_data
        device = 'device 1'
        port = 'port 1'
        current_value = 10
        data = {
            'device':
            device,
            'port':
            port,
            Constants.DataPacket.units:
            'X',
            Constants.DataPacket.action:
            Constants.DataPacket.accumulate,
            Constants.DataPacket.arrival_time:
            datetime.datetime(2012, 1, 2, 3, 4, 5),
            Constants.DataPacket.current_value:
            current_value
        }
        cs.createDataStream(device, port, data)
        #        self.assertListEqual( cs.datapoints['1'], [{'at':'2012-01-02T03:04:05', 'value': 10}] )
        cs.createDataStream(device, port, data)
        #        self.assertListEqual( cs.datapoints['1'], [{'at':'2012-01-02T03:04:05', 'value': 10}, {'at':'2012-01-02T03:04:05', 'value': 10}] )

        data = {
            'device':
            device,
            'port':
            port,
            Constants.DataPacket.units:
            'X',
            Constants.DataPacket.action:
            Constants.DataPacket.accumulate,
            Constants.DataPacket.action:
            Constants.DataPacket.send,
            Constants.DataPacket.arrival_time:
            datetime.datetime(2012, 1, 2, 3, 4, 6),
            Constants.DataPacket.current_value:
            11
        }

        cs.createDataStream(device, port, data)
        self.assertListEqual(cs.datapoints['1'], [])
예제 #14
0
    def test_createFeed_with_two_datestreams(self, config):
        options = None
        cs = COSMSend(options)
        device = 'device 1'
        port = 'port 1'
        config.assert_called_once_with()
        cs.config = self.config_data
        data = {
            'device':
            device,
            'port':
            port,
            Constants.DataPacket.action:
            Constants.DataPacket.accumulate,
            Constants.DataPacket.arrival_time:
            datetime.datetime(2012, 1, 2, 3, 4, 5),
            Constants.DataPacket.current_value:
            10
        }
        cs.createDataStream(device, port, data)

        data[Constants.DataPacket.current_value] = 545454
        cs.createDataStream(device, port, data)

        data['device'] = device = 'device 2'
        data[Constants.DataPacket.current_value] = 999
        cs.createDataStream(device, port, data)

        data['device'] = device = 'device 1'
        data[Constants.DataPacket.action] = Constants.DataPacket.send
        cs.report_data = MagicMock()
        cs.output(data)
        pprint.pprint(cs.json)
        pprint.pprint(cs.datapoints)
        #         self.assertEqual( cs.[Constants.Cosm.title], Constants.Cosm.title )
        #         self.assertEqual( cs.json[Constants.Cosm.status], Constants.Cosm.status )
        #         self.assertEqual( cs.json[Constants.Cosm.creator], Constants.Cosm.creator )
        #         self.assertEqual( cs.json[Constants.Cosm.created], Constants.Cosm.created )
        #         self.assertEqual( cs.json[Constants.Cosm.feed], 'url' )
        #         self.assertEqual( cs.json[Constants.Cosm.email], Constants.Cosm.email )
        #         self.assertEqual( cs.json[Constants.Cosm.id], Constants.Cosm.id )
        #         self.assertEqual( cs.json[Constants.Cosm.auto_feed_url], ( 'url', ) )
        #         self.assertEqual( cs.json[Constants.Cosm.version], Constants.Cosm.version )
        cs = None
예제 #15
0
    def test_createFeed_with_two_datestreams( self, config ):
        options = None
        cs = COSMSend( options )
        device = 'device 1'
        port = 'port 1'
        config.assert_called_once_with()
        cs.config = self.config_data
        data = {'device': device,
                'port': port,
                Constants.DataPacket.action: Constants.DataPacket.accumulate,
                Constants.DataPacket.arrival_time: datetime.datetime( 2012, 1, 2, 3, 4, 5 ),
                Constants.DataPacket.current_value: 10}
        cs.createDataStream( device, port, data )

        data[Constants.DataPacket.current_value] = 545454
        cs.createDataStream( device, port, data )

        data['device'] = device = 'device 2'
        data[Constants.DataPacket.current_value] = 999
        cs.createDataStream( device, port, data )

        data['device'] = device = 'device 1'
        data[Constants.DataPacket.action] = Constants.DataPacket.send
        cs.report_data = MagicMock()
        cs.output( data )
        pprint.pprint( cs.json )
        pprint.pprint( cs.datapoints )
#         self.assertEqual( cs.[Constants.Cosm.title], Constants.Cosm.title )
#         self.assertEqual( cs.json[Constants.Cosm.status], Constants.Cosm.status )
#         self.assertEqual( cs.json[Constants.Cosm.creator], Constants.Cosm.creator )
#         self.assertEqual( cs.json[Constants.Cosm.created], Constants.Cosm.created )
#         self.assertEqual( cs.json[Constants.Cosm.feed], 'url' )
#         self.assertEqual( cs.json[Constants.Cosm.email], Constants.Cosm.email )
#         self.assertEqual( cs.json[Constants.Cosm.id], Constants.Cosm.id )
#         self.assertEqual( cs.json[Constants.Cosm.auto_feed_url], ( 'url', ) )
#         self.assertEqual( cs.json[Constants.Cosm.version], Constants.Cosm.version )
        cs = None
예제 #16
0
    def test_createJSONReport(self, config):
        options = None
        cs = COSMSend(options)
        device = 'device 1'
        port = 'port 1'
        config.assert_called_once_with()
        cs.config = config_data = \
                {'device 1': \
                    {'port 1': \
                        {
                                Constants.Cosm.datastream.tags: 'tag',
                                Constants.Cosm.datastream.cosm_channel: '1',
                                Constants.Cosm.datastream.max_value: 100,
                                Constants.Cosm.datastream.min_value: 0,
                                Constants.Cosm.location.created: 'created',
                                Constants.Cosm.location.disposition: "fixed",
                                Constants.Cosm.location.domain: 'domain',
                                Constants.Cosm.location.exposure: 'exposure',
                                Constants.Cosm.location.latitude: 30.3351807498968,
                                Constants.Cosm.location.longitude: 97.7104604244232 * -1.0,    # Eclipse save causes error
                                Constants.Cosm.location.private: 'private',
                                Constants.Cosm.apikey: 'apikey',
                                Constants.Cosm.auto_feed_url: "https://api.cosm.com/v2/feeds/64451.json",
                                Constants.Cosm.creator: "https://cosm.com/users/gary_pickens",
                                Constants.Cosm.created: 'created',
                                Constants.Cosm.email: "*****@*****.**",
                                Constants.Cosm.feed: "https://api.cosm.com/v2/feeds/64451.json",
                                Constants.Cosm.id: 64451,
                                Constants.Cosm.private: "false",
                                Constants.Cosm.status: "frozen",
                                Constants.Cosm.tags: ["Door", "Temperature"],
                                Constants.Cosm.title: "Garage",
                                Constants.Cosm.updated: 'updated',
                                Constants.Cosm.url: 'url',
                                Constants.Cosm.version: "1.0.0",
                                Constants.Cosm.location_str: 'location',
                                Constants.Cosm.datastreams: 'datastreams',
                            }
                        }
                    }

        data = {
            'device':
            device,
            'port':
            port,
            Constants.DataPacket.arrival_time:
            datetime.datetime(2012, 1, 2, 3, 4, 5),
            Constants.DataPacket.current_value:
            10
        }
        cs.createDataStream(device, port, data)

        data[Constants.DataPacket.current_value] = 545454
        cs.createDataStream(device, port, data)

        json = cs.createJSONReport(device, port, data)

        pprint.pprint(json)
        cs.empty_datastream_list()
        cs = None