Esempio n. 1
0
    def test_quota_list_one_with_data_details(self):
        """ Check that list one returns a list of data details within the
        designated time period """

        # Check that correct quota data is returned by date strings
        one_quota = QuotaResource.list_one_details(
            guid='test_guid', start_date='2013-12-31', end_date='2014-07-02')
        self.assertEqual(len(one_quota['memory']), 1)

        # Check that correct quota data is returned by datetime.dates
        one_quota = QuotaResource.list_one_details(
            guid='test_guid',
            start_date=datetime.date(2013, 12, 31),
            end_date=datetime.date(2014, 1, 2))
        self.assertEqual(len(one_quota['memory']), 1)
Esempio n. 2
0
    def test_quota_list_one_with_data_details(self):
        """ Check that list one returns a list of data details within the
        designated time period """

        # Check that correct quota data is returned by date strings
        one_quota = QuotaResource.list_one_details(
            guid='test_guid', start_date='2013-12-31', end_date='2014-07-02')
        self.assertEqual(len(one_quota['memory']), 1)

        # Check that correct quota data is returned by datetime.dates
        one_quota = QuotaResource.list_one_details(
            guid='test_guid',
            start_date=datetime.date(2013, 12, 31),
            end_date=datetime.date(2014, 1, 2))
        self.assertEqual(len(one_quota['memory']), 1)
Esempio n. 3
0
 def test_prepare_memory_data(self):
     """ Check that memory data is prepared into more descriptive format """
     sample_data = [[1875, 14], [2000, 15]]
     memory_data = QuotaResource.prepare_memory_data(sample_data)
     self.assertEqual([
         {'size': 1875, 'days': 14}, {'size': 2000, 'days': 15}
     ], memory_data)
Esempio n. 4
0
 def test_prepare_memory_data(self):
     """ Check that memory data is prepared into more descriptive format """
     sample_data = [[1875, 14], [2000, 15]]
     memory_data = QuotaResource.prepare_memory_data(sample_data)
     self.assertEqual([
         {'size': 1875, 'days': 14}, {'size': 2000, 'days': 15}
     ], memory_data)
Esempio n. 5
0
 def test_generate_cvs(self):
     """ Check that function returns a csv generator """
     csv = QuotaResource.generate_cvs().split('\r\n')
     self.assertEqual(
         'quota_name,quota_guid,quota_cost,quota_created_date',
         csv[0])
     self.assertEqual('test_name,test_guid,13.2,None', csv[1])
     self.assertEqual('test_name_2,test_guid_2,0,None', csv[2])
Esempio n. 6
0
 def test_generate_cvs(self):
     """ Check that function returns a csv generator """
     csv = QuotaResource.generate_cvs().split('\r\n')
     self.assertEqual(
         'quota_name,quota_guid,quota_cost,quota_created_date',
         csv[0])
     self.assertEqual('test_name,test_guid,13.2,None', csv[1])
     self.assertEqual('test_name_2,test_guid_2,0,None', csv[2])
Esempio n. 7
0
def api_all_dates():
    """ Endpoint that lists all quotas with details between
    two specific dates """
    start_date = request.args.get('since')
    end_date = request.args.get('until', datetime.datetime.today().now())
    return jsonify({
        'Quotas':
        QuotaResource.list_all(start_date=start_date, end_date=end_date)
    })
Esempio n. 8
0
def api_all_dates():
    """ Endpoint that lists all quotas with details between
    two specific dates """
    start_date = request.args.get('since')
    end_date = request.args.get('until', datetime.datetime.today().now())
    return jsonify(
        {'Quotas':
            QuotaResource.list_all(start_date=start_date, end_date=end_date)}
    )
Esempio n. 9
0
def api_one_dates(guid):
    """ Endpoint that lists one quota details limited by date """
    start_date = request.args.get('since')
    end_date = request.args.get('until', datetime.datetime.today().now())
    data = QuotaResource.list_one_aggregate(
        guid=guid, start_date=start_date, end_date=end_date)
    if data:
        return jsonify(data)
    else:
        return jsonify({'error': 'No Data'}), 404
Esempio n. 10
0
 def test_prepare_csv_row(self):
     """ Check that function returns one row of prepared csv data """
     sample_row = {
         'name': 'test',
         'guid': 'id2',
         'cost': 4,
         'created_at': datetime.datetime(2014, 4, 4)
     }
     row = QuotaResource.prepare_csv_row(sample_row)
     self.assertEqual(['test', 'id2', '4', '2014-04-04 00:00:00'], row)
Esempio n. 11
0
 def test_prepare_csv_row(self):
     """ Check that function returns one row of prepared csv data """
     sample_row = {
         'name': 'test',
         'guid': 'id2',
         'cost': 4,
         'created_at': datetime.datetime(2014, 4, 4)
     }
     row = QuotaResource.prepare_csv_row(sample_row)
     self.assertEqual(['test', 'id2', '4', '2014-04-04 00:00:00'], row)
Esempio n. 12
0
def api_one_dates(guid):
    """ Endpoint that lists one quota details limited by date """
    start_date = request.args.get('since')
    end_date = request.args.get('until', datetime.datetime.today().now())
    data = QuotaResource.list_one_aggregate(guid=guid,
                                            start_date=start_date,
                                            end_date=end_date)
    if data:
        return jsonify(data)
    else:
        return jsonify({'error': 'No Data'}), 404
Esempio n. 13
0
 def setUp(self):
     db.create_all()
     quota = Quota(guid='test_guid', name='test_name', url='test_url')
     db.session.add(quota)
     quota2 = QuotaResource(
         guid='test_guid_2', name='test_name_2', url='test_url_2')
     db.session.add(quota2)
     db.session.commit()
     quota_data = QuotaData(quota, datetime.date(2013, 1, 1))
     quota_data.memory_limit = 2000
     quota.data.append(quota_data)
     quota_data = QuotaData(quota, datetime.date(2014, 1, 1))
     quota_data.memory_limit = 1000
     quota.data.append(quota_data)
     quota_data = QuotaData(quota, datetime.date(2015, 1, 1))
     quota_data.memory_limit = 1000
     quota.data.append(quota_data)
     db.session.commit()
     db.session.commit()
Esempio n. 14
0
 def test_list_one_aggregate(self):
     """ Check that the aggregator functionp produces all data include
     cost """
     one_quota = QuotaResource.list_one_aggregate(guid='test_guid')
     self.assertEqual(one_quota['guid'], 'test_guid')
     self.assertEqual(one_quota['cost'], 13.2)
Esempio n. 15
0
 def test_get_mem_cost_multipe_mem_types(self):
     """ Check that the cost function works with multiple days
     with multiple mem limits """
     sample_data = [[1875, 14], [2000, 15]]
     cost = QuotaResource.get_mem_cost(sample_data)
     self.assertEqual(cost, 185.625)
Esempio n. 16
0
 def test_get_mem_single_cost(self):
     """ Check that the cost function works with multiple days
     with single mem limit """
     sample_data = [[1875, 14]]
     cost = QuotaResource.get_mem_cost(sample_data)
     self.assertEqual(cost, 86.625)
Esempio n. 17
0
 def test_list_all(self):
     """ Check that list all function returns dict of multiple quotas """
     quotas = QuotaResource.list_all()
     self.assertEqual(len(quotas), 2)
     self.assertEqual(quotas[0]['guid'], 'test_guid')
     self.assertEqual(quotas[1]['guid'], 'test_guid_2')
Esempio n. 18
0
 def test_list_one_aggregate(self):
     """ Check that the aggregator functionp produces all data include
     cost """
     one_quota = QuotaResource.list_one_aggregate(guid='test_guid')
     self.assertEqual(one_quota['guid'], 'test_guid')
     self.assertEqual(one_quota['cost'], 13.2)
Esempio n. 19
0
 def test_get_mem_single_cost(self):
     """ Check that the cost function works with multiple days
     with single mem limit """
     sample_data = [[1875, 14]]
     cost = QuotaResource.get_mem_cost(sample_data)
     self.assertEqual(cost, 86.625)
Esempio n. 20
0
def download_quotas():
    """ Route for downloading quotas """
    start_date = request.args.get('since')
    end_date = request.args.get('until', datetime.datetime.today().now())
    csv = QuotaResource.generate_cvs(start_date=start_date, end_date=end_date)
    return Response(csv, mimetype='text/csv')
Esempio n. 21
0
 def test_list_all(self):
     """ Check that list all function returns dict of multiple quotas """
     quotas = QuotaResource.list_all()
     self.assertEqual(len(quotas), 2)
     self.assertEqual(quotas[0]['guid'], 'test_guid')
     self.assertEqual(quotas[1]['guid'], 'test_guid_2')
Esempio n. 22
0
 def test_list_one_details(self):
     """ Check that list one function returns dict of one quota """
     one_quota = QuotaResource.list_one_details(guid='test_guid')
     self.assertEqual(one_quota['guid'], 'test_guid')
     self.assertEqual(one_quota['name'], 'test_name')
Esempio n. 23
0
 def test_list_one_details(self):
     """ Check that list one function returns dict of one quota """
     one_quota = QuotaResource.list_one_details(guid='test_guid')
     self.assertEqual(one_quota['guid'], 'test_guid')
     self.assertEqual(one_quota['name'], 'test_name')
Esempio n. 24
0
def download_quotas():
    """ Route for downloading quotas """
    start_date = request.args.get('since')
    end_date = request.args.get('until', datetime.datetime.today().now())
    csv = QuotaResource.generate_cvs(start_date=start_date, end_date=end_date)
    return Response(csv, mimetype='text/csv')
Esempio n. 25
0
 def test_get_mem_cost_multipe_mem_types(self):
     """ Check that the cost function works with multiple days
     with multiple mem limits """
     sample_data = [[1875, 14], [2000, 15]]
     cost = QuotaResource.get_mem_cost(sample_data)
     self.assertEqual(cost, 185.625)