Exemple #1
0
    def test_addPingExisting(self, datetime_mock):
        location = '30.000 20.000'

        current_time = datetime.datetime.now()
        datetime_mock.now.return_value = current_time

        device = createDevice(
            DevicePing(id="1", clusterId="cl1", location=location))
        device.buckets[0]['currentSequence'] = 1
        device.buckets[0]['data'] = [{'uptime': 100, 'date': current_time}]

        addPing(device)

        expected = createDevice(
            DevicePing(id="1", clusterId="cl1", location=location))
        expected.buckets[0]['currentSequence'] = 2
        expected.buckets[0]['data'] = [{
            'uptime': 100,
            'date': current_time
        }, {
            'uptime': 100,
            'date': current_time
        }]

        self.assertEq(expected, device)
Exemple #2
0
    def test_calculateAverageOnOverflow(self, datetime_mock):
        location = '30.000 20.000'

        current_time = datetime.datetime.now()
        datetime_mock.now.return_value = current_time
        old_time = current_time

        device = createDevice(
            DevicePing(id="1", clusterId="cl1", location=location))

        overflow = device.buckets[0]['overflow']
        data = []
        for i in range(0, overflow):
            data.append((i * 10) % 100)

        for i in range(0, len(data)):
            addPingCustom(device, current_time + timedelta(minutes=i + 1),
                          data[i])

        expectedUptime = Average(data)
        expected = createDevice(
            DevicePing(id="1", clusterId="cl1", location=location))
        expected.buckets[0]['currentSequence'] = 0
        expected.buckets[0]['data'] = device.buckets[0]['data']
        expected.buckets[1]['currentSequence'] = 1
        expected.buckets[1]['data'] = [{
            'uptime':
            expectedUptime,
            'date':
            current_time + timedelta(minutes=len(data))
        }]

        self.assertEq(expected, device)
Exemple #3
0
    def test_addMissingIntervalsPing(self, datetime_mock):
        location = '30.000 20.000'

        current_time = datetime.datetime.now()
        datetime_mock.now.return_value = current_time
        old_time = current_time - timedelta(seconds=140)

        device = createDevice(
            DevicePing(id="1", clusterId="cl1", location=location))

        data = [{'uptime': 100, 'date': old_time}]
        device.buckets[0]['currentSequence'] = 1
        device.buckets[0]['data'] = copy.deepcopy(data)

        addPing(device)

        data.append({'uptime': 0, 'date': old_time + timedelta(seconds=60)})
        data.append({'uptime': 0, 'date': old_time + timedelta(seconds=120)})
        data.append({'uptime': 100, 'date': current_time})
        expected = createDevice(
            DevicePing(id="1", clusterId="cl1", location=location))
        expected.buckets[0]['currentSequence'] = 4
        expected.buckets[0]['data'] = data

        self.assertEq(expected, device)
Exemple #4
0
    def test_addPingOverflows(self, datetime_mock):
        location = '30.000 20.000'

        current_time = datetime.datetime.now()
        datetime_mock.now.return_value = current_time

        device = createDevice(
            DevicePing(id="1", clusterId="cl1", location=location))
        overflow = device.buckets[0]['overflow']
        device.buckets[0]['currentSequence'] = overflow - 1
        data = [{'uptime': 100, 'date': current_time}] * (overflow - 1)
        device.buckets[0]['data'] = copy.deepcopy(data)

        addPing(device)

        data.append({'uptime': 100, 'date': current_time})
        expected = createDevice(
            DevicePing(id="1", clusterId="cl1", location=location))

        expected.buckets[0]['currentSequence'] = 0
        expected.buckets[0]['data'] = data
        expected.buckets[1]['currentSequence'] = 1
        expected.buckets[1]['data'] = [{'uptime': 100, 'date': current_time}]

        self.assertEq(expected, device)
Exemple #5
0
    def post(self, request, cluster_id, device_id):
        input_serializer = self.InputSerializer(data=request.data)
        input_serializer.is_valid()

        acceptPing(DevicePing(id=device_id, clusterId=cluster_id, location=input_serializer.data['location']))

        return Response()
Exemple #6
0
    def setUp(self):
        location = '30.000 20.000'

        self.current_time = datetime.datetime.now()

        self.cluster_id = 1

        devices = []

        for i in range(0, 3):
            device = createDevice(
                DevicePing(id=i, clusterId=self.cluster_id, location=location))
            devices.append(device)

        for device in devices:
            overflow = device.buckets[0]['overflow']
            device.buckets[0]['currentSequence'] = overflow - 1
            data = [{
                'uptime': 100,
                'date': self.current_time
            }] * (overflow - 1)
            device.buckets[0]['data'] = copy.deepcopy(data)

            device.save()

        self.service = getDevicesByClusterAndBucketLevel
Exemple #7
0
    def test_addPingRemovesIfFull(self, datetime_mock):
        location = '30.000 20.000'

        current_time = datetime.datetime.now()
        datetime_mock.now.return_value = current_time

        device = createDevice(
            DevicePing(id="1", clusterId="cl1", location=location))
        maxSize = device.buckets[0]['maxSize']
        data = [{'uptime': 100, 'date': current_time}] * maxSize
        device.buckets[0]['data'] = copy.deepcopy(data)

        addPing(device)

        del data[0]
        data.append({'uptime': 100, 'date': current_time})
        expected = createDevice(
            DevicePing(id="1", clusterId="cl1", location=location))
        expected.buckets[0]['currentSequence'] = 1
        expected.buckets[0]['data'] = data

        self.assertEq(expected, device)