def test_uploading_duplicate(self):
        found = MarketingProductUsage.objects()
        self.assertEquals(len(found), 0)

        datestr = "2012-12-06T11:13:06.432367"
        mpu = MarketingProductUsage()
	mpu.instance_identifier="instance-1"
	mpu.splice_server = "ss-1"
	mpu.date=datestr
        mpu.save()

        self.assertEquals(len(found), 1)
        example = {"objects":[mpu]}
        post_data = utils.obj_to_json(example)
        LOG.info("Calling api for marketing product usage import with post data: '%s'" % (post_data))
        resp = self.raw_api_client.post('/api/v1/marketingproductusage/', format='json', data=post_data,
                                        SSL_CLIENT_CERT=self.expected_valid_splice_server_identity_pem)
        self.assertEquals(resp.status_code, 204)
        # Now check that the server api saved the object as expected
        found = MarketingProductUsage.objects()
        self.assertEquals(len(found), 1)
        self.assertEquals(found[0].instance_identifier, mpu.instance_identifier)
예제 #2
0
    def test_example_with_raw_string_data(self):
	example = {"objects":[
			{"splice_server": "foofoofoo",
			 "checkin_date": "2006-10-25 14:30:59",
			 "instance_identifier": "bar"},
			{"splice_server": "foofoofoo",
			 "checkin_date": "2007-10-25 14:40:59",
			 "facts": {"fact1": "factresult1"},
			 "instance_identifier": "barbar"}
		]}

        post_data = json.dumps(example)
        LOG.info("Post to marketing product usage with data: %s" % (post_data))
        resp = self.raw_api_client.post('/api/v1/marketingproductusage/', format='json', data=post_data,
            SSL_CLIENT_CERT=self.expected_valid_splice_server_identity_pem)
        LOG.info("Response: %s" % (resp))
        self.assertEquals(resp.status_code, 204)
        found = MarketingProductUsage.objects()
        self.assertEquals(len(found), 2)
        self.assertIn(found[0].instance_identifier, ("bar", "barbar"))
예제 #3
0
파일: api.py 프로젝트: splice/splice-server
 def get_existing(self, obj):
     return MarketingProductUsage.objects(instance_identifier=obj.instance_identifier, checkin_date=obj.checkin_date).first()