Ejemplo n.º 1
0
 def test_purge_notifications(self):
     default_setting = settings.NODESHOT['NOTIFICATIONS']['DELETE_OLD']
     settings.NODESHOT['NOTIFICATIONS']['DELETE_OLD'] = 7
     
     n = Notification.objects.create(**{
         "to_user_id": 1,
         "type": "custom",
         "text": "testing"
     })
     # not enough old to be purged
     n.added = ago(days=3)
     n.save(auto_update=False)
     management.call_command('purge_notifications')
     # no notifications have been deleted
     self.assertEqual(Notification.objects.count(), 1)
     
     # enough old to be purged
     n.added = ago(days=14)
     n.save(auto_update=False)
     management.call_command('purge_notifications')
     self.assertEqual(Notification.objects.count(), 0)
     
     n = Notification.objects.create(**{
         "to_user_id": 1,
         "type": "custom",
         "text": "testing"
     })
     n.added = ago(days=14)
     n.save(auto_update=False)
     purge_notifications.delay()
Ejemplo n.º 2
0
    def test_purge_notifications(self):
        n = Notification.objects.create(**{
            "to_user_id": 1,
            "type": "custom",
            "text": "testing"
        })
        # not enough old to be purged
        n.added = ago(days=3)
        n.save(auto_update=False)
        management.call_command('purge_notifications')
        # no notifications have been deleted
        self.assertEqual(Notification.objects.count(), 1)

        # enough old to be purged
        n.added = ago(days=41)
        n.save(auto_update=False)
        management.call_command('purge_notifications')
        self.assertEqual(Notification.objects.count(), 0)

        n = Notification.objects.create(**{
            "to_user_id": 1,
            "type": "custom",
            "text": "testing"
        })
        n.added = ago(days=41)
        n.save(auto_update=False)
        purge_notifications.delay()
        self.assertEqual(Notification.objects.count(), 0)
 def retrieve_old_notifications(self):
     """
     Retrieve notifications older than X days, where X is specified in settings
     """
     
     date = ago(days=settings.NODESHOT['NOTIFICATIONS'].get('DELETE_OLD', 40))
     
     return Notification.objects.filter(added__lte=date)
Ejemplo n.º 4
0
 def test_write_timestamp_datetime(self):
     metric = self._create_metric('test_metric_datetime')
     datetime = ago(days=365)
     metric.write({'value1': 4, 'value2': 'datetime'}, timestamp=datetime, async=False)
     measurement = list(query('select * from test_metric_datetime').get_points())[0]
     self.assertEqual(measurement['value1'], 4)
     self.assertEqual(measurement['value2'], 'datetime')
     self.assertEqual(measurement['time'], datetime.strftime('%Y-%m-%dT%H:%M:%SZ'))
Ejemplo n.º 5
0
    def retrieve_old_notifications(self):
        """
        Retrieve notifications older than X days, where X is specified in settings
        """

        date = ago(days=DELETE_OLD)

        return Notification.objects.filter(added__lte=date)
Ejemplo n.º 6
0
    def retrieve_old_notifications(self):
        """
        Retrieve notifications older than X days, where X is specified in settings
        """

        date = ago(
            days=settings.NODESHOT['NOTIFICATIONS'].get('DELETE_OLD', 40))

        return Notification.objects.filter(added__lte=date)
Ejemplo n.º 7
0
 def test_write_timestamp_datetime(self):
     metric = self._create_metric('test_metric_datetime')
     datetime = ago(days=365)
     metric.write({
         'value1': 4,
         'value2': 'datetime'
     },
                  timestamp=datetime,
                  async=False)
     measurement = list(
         query('select * from test_metric_datetime').get_points())[0]
     self.assertEqual(measurement['value1'], 4)
     self.assertEqual(measurement['value2'], 'datetime')
     self.assertEqual(measurement['time'],
                      datetime.strftime('%Y-%m-%dT%H:%M:%SZ'))
Ejemplo n.º 8
0
 def test_write_timestamp_datetime(self):
     metric = Metric(name='test_metric')
     metric.related_object = User.objects.first()
     metric.full_clean()
     metric.save()
     datetime = ago(days=365)
     metric.write({'value1': 1, 'value2': 'string'}, timestamp=datetime)
     sleep(2)
     sql = "select * from test_metric where content_type = 'user' and object_id = '{0}'".format(metric.object_id)
     points = query(sql)['test_metric']
     self.assertEqual(len(points), 1)
     self.assertEqual(points[0]['time'], datetime.strftime('%Y-%m-%dT%H:%M:%SZ'))
     # drop series
     series_id = query('show series')['test_metric'][0]['_id']
     query('drop measurement test_metric')
     query('drop series {0}'.format(series_id))