Example #1
0
    def test_claimSensor_no_uuid(self):
        '''
            Test that we get back an error should we not send a uuid 
        '''

        data = {"stream_data": {'name': "Claimed Sensor One"}} 
        owner = PortcullisUser.objects.get(email="*****@*****.**")
        self.assertTrue(isinstance(claimSensor(data, owner), str))
Example #2
0
    def test_claimSensor_no_owner(self):
        '''
            Test that we get back the claimed sensor we give even when not giving an owner
        '''

        data = {"uuid": "sensor_one_id", "name": "Claimed Sensor One"} 
        sensor = Sensor.objects.get(uuid="sensor_one_id")
        self.assertEqual(claimSensor(data, None), sensor)
Example #3
0
    def test_claimSensor_no_name(self):
        '''
            Test that we get back the sensor we send when we don't give a name
        '''

        data = {"uuid": "sensor_one_id"} 
        owner = PortcullisUser.objects.get(email="*****@*****.**")
        sensor = Sensor.objects.get(uuid="sensor_one_id")
        self.assertEqual(claimSensor(data, owner), sensor)
Example #4
0
    def test_claimSensor_no_owner(self):
        '''
            Test that we get an error message if given no owner
        '''

        sensor = Sensor.objects.get(uuid="sensor_one_id")
        name = "Claimed Sensor One"
        cs = claimSensor(sensor, name, None)
        self.assertTrue(isinstance(cs, str))
Example #5
0
    def test_claimSensor_no_name(self):
        '''
            Test that we get an error message if given no name
        '''

        owner = PortcullisUser.objects.get(email="*****@*****.**")
        sensor = Sensor.objects.get(uuid="sensor_one_id")
        cs = claimSensor(sensor, None, owner)
        self.assertTrue(isinstance(cs, list))
Example #6
0
    def test_claimSensor_good_data_create(self):
        '''
            Test that we get back a new sensor given good data
        '''

        stream_data = {'name': "Brand New name"} 
        data = {"uuid": "brand_new_sensor", "stream_data": stream_data} 
        owner = PortcullisUser.objects.get(email="*****@*****.**")
        sensor = claimSensor(data, owner)
        self.assertEqual(Sensor.objects.get(uuid="brand_new_sensor"), sensor)
Example #7
0
    def test_claimSensor_swap_sensor(self):
        '''
            Test that we can claim a new sensor.
        '''

        data = {"uuid": "brand_new_sensor", "stream_data": {"name": "Datastream One"}}
        owner = PortcullisUser.objects.get(email="*****@*****.**")

        ds = DataStream.objects.get(owner=owner, name=data['stream_data']['name'])
        oldSensor = Sensor.objects.get(uuid="sensor_one_id")
        self.assertEqual(ds.sensor, oldSensor)

        newSensor = claimSensor(data, owner)
        self.assertTrue(isinstance(newSensor, Sensor)) 
        self.assertNotEqual(newSensor, oldSensor)
        self.assertEqual(DataStream.objects.get(owner=owner, name=data['stream_data']['name']).sensor, newSensor)
Example #8
0
    def test_claimSensor_good_data_unclaimed_update(self):
        '''
            Test that we get back a updated sensor given good data and the sensor is not claimed
        '''

        owner = PortcullisUser.objects.get(email="*****@*****.**")
        ds = DataStream.objects.get(owner=owner, name="Datastream One")
        ds.sensor = None
        ds.save()
        sensor = Sensor.objects.get(uuid="sensor_one_id")
        sensor.description = ''
        sensor.save()
        data = {"uuid": sensor.uuid, "description": "new description", "stream_data": {"name": ds.name, "units": "new units"}} 
        
        updatedSensor = claimSensor(data, owner)

        self.assertTrue(isinstance(updatedSensor, Sensor))
        self.assertNotEqual(updatedSensor.description, sensor.description)