def test_parse_report(self): response = ''' {"response":[ {"clicks":"103","money":"1000.00","day":"2010-10-08","campaign_id":123,"client_id":123,"client_name":"Ford","campaign_name":"Campaign1","ctr":"0.199","impressions":"51635"} ]} ''' account = Account.objects.create(remote_id=1) Campaign.objects.create(account=account, remote_id=123, fetched=datetime.now()) Client.objects.create(account=account, remote_id=123, fetched=datetime.now()) instance = Report(time_from=datetime.now(), time_to=datetime.now()) instance.parse(json.loads(response)['response'][0]) instance.save() self.assertTrue(isinstance(instance.campaign, Campaign)) self.assertEqual(instance.campaign.remote_id, 123) self.assertTrue(isinstance(instance.client, Client)) self.assertEqual(instance.client.remote_id, 123) self.assertEqual(instance.clicks, 103) self.assertEqual(instance.impressions, 51635) self.assertEqual(instance.day, date(2010,10,8)) self.assertEqual(instance.client_name, "Ford") self.assertEqual(instance.campaign_name, "Campaign1") self.assertEqual(instance.money, '1000.00') self.assertEqual(instance.ctr, '0.199')