def test_getlist(self): #create json here n = (datetime.now() + timedelta(days=1)).strftime('%s') entry = TestData.create_product_usage_json() #entry["date"] = "abcd" """
def test_post_unique_ident(self): entry1 = TestData.create_product_usage_json(instance_identifier='00:11') entry2 = TestData.create_product_usage_json(instance_identifier='00:22') resp0 = self.api_client.post('/api/v1/productusage/', format='json', data=entry1) resp1 = self.api_client.post('/api/v1/productusage/', format='json', data=entry2) self.assertEqual(202, resp0.status_code, 'http status code is expected') self.assertEqual(202, resp1.status_code, 'http status code is expected') self.assertEqual(2, ReportData.objects.all().count(), 'product_usuage successfully imported') self.assertEqual(0, QuarantinedReportData.objects.all().count(), 'asserted 1 product usuage quarantined')
def test_post_202(self): self.assertEqual(0, ReportData.objects.all().count(), 'product_usuage successfully imported') entry = TestData.create_product_usage_json() resp = self.api_client.post( '/api/v1/productusage/', format='json', data=entry) self.assertEqual(202, resp.status_code, 'http status code is expected') self.assertEqual(1, ReportData.objects.all().count(), 'product_usuage successfully imported') self.assertEqual(0, QuarantinedReportData.objects.all().count(), 'asserted no product usuage quarantined')
def test_getlist(self): #create json here, memory greater than biz rules allow e = TestData.create_product_usage_json(memory='604836000000') entry = json.dumps(e) resp = self.post('/api/v1/productusage/', data=entry ) self.assertEqual(202, resp.status_code, 'http status code is expected') self.assertEqual(ReportData.objects.count(), 1) resp = self.get('/api/v1/compliancedata/') self.assertEqual(200, resp.status_code, 'http status code is expected') self.assertContains(resp, '"rule": "0 > 8388608; 8388608 > 83886080"', count=1, status_code=200)
def test_post_duplicate(self): entry = TestData.create_product_usage_json() resp0 = self.api_client.post( '/api/v1/productusage/', format='json', data=entry) resp1 = self.api_client.post( '/api/v1/productusage/', format='json', data=entry) self.assertEqual( 202, resp0.status_code, 'http status code is expected') #duplicates are now only logged and not rejected w/ a 409 self.assertEqual( 202, resp1.status_code, 'http status code is expected') self.assertEqual(1, ReportData.objects.all().count(), 'product_usuage successfully imported') #get a 202, but still there is only one object in db self.assertEqual(1, ReportData.objects.all().count(), 'product_usuage successfully imported')
def test_getlist(self): #create json here, a valid entry self.assertEqual(0, ReportData.objects.all().count()) #print('count: ' + str(ReportData.objects.all().count())) e = TestData.create_product_usage_json(instance_identifier="00:11") entry = json.dumps(e) #print('ENTRY: ' + entry) resp = self.post('/api/v1/productusage/', data=entry) #print('resp:' + str(resp.status_code)) self.assertEqual(202, resp.status_code, 'http status code is expected') self.assertEqual(1, ReportData.objects.all().count()) q = {"user": "******", "byMonth": "11,2012", "contract_number": "All", "rhic": "null", "env": "All"} myquery = json.dumps(q) resp = self.post('/api/v1/reportmeter/', data=myquery, code=200) #print(resp) self.assertEqual(200, resp.status_code, 'http status code is expected') self.assertContains(resp, '"count": 1', count=1, status_code=200)