示例#1
0
    def test_uploading_single_spliceserver(self):
        found = SpliceServer.objects()
        self.assertEquals(len(found), 0)

        server = SpliceServer()
        server.uuid = "Splice Server Test UUID-1"
        server.description = "Description data"
        server.hostname = "server.example.com"
        server.environment = "environment info"

        example = {"objects":[server]}
        post_data = utils.obj_to_json(example)
        LOG.info("Calling api for spliceserver import with post data: '%s'" % (post_data))
        resp = self.raw_api_client.post('/api/v1/spliceserver/', format='json', data=post_data,
            SSL_CLIENT_CERT=self.expected_valid_splice_server_identity_pem)
        LOG.info("Response for spliceserver import: Status Code: %s, Response: %s" % (resp.status_code, resp))
        self.assertEquals(resp.status_code, 204)
        # Now check that the server api saved the object as expected
        found = SpliceServer.objects()
        self.assertEquals(len(found), 1)
        self.assertEquals(found[0].uuid, server.uuid)
        self.assertEquals(found[0].description, server.description)
        self.assertEquals(found[0].hostname, server.hostname)
        self.assertEquals(found[0].environment, server.environment)
        self.assertIsNotNone(found[0].created)
        self.assertIsNotNone(found[0].updated)
示例#2
0
    def test_upload_newer_spliceserver(self):
        found = SpliceServer.objects()
        self.assertEquals(len(found), 0)
        # Create 'newer' server and save to DB
        orig_uuid = "Splice Server UUID"
        orig_description = "Original Description"
        orig_hostname = "Original.hostname.com"
        orig_environment = "Original environment"
        older = SpliceServer()
        older.uuid = orig_uuid
        older.description = orig_description
        older.hostname = orig_hostname
        older.environment = orig_environment
        older.created = "2011-01-01T11:13:06.432367"
        older.updated = "2012-12-01T11:13:06.432367"
        older.save()
        found = SpliceServer.objects()
        self.assertEquals(len(found), 1)

        # Create 'older' which is one month older than newer
        newer = SpliceServer()
        newer.uuid = orig_uuid
        newer.description = "Updated description"
        newer.hostname = "updated.server.example.com"
        newer.environment = "Updated environment info"
        newer.created = "2011-01-01T11:13:06.432367"
        newer.updated = "2012-12-31T11:13:06.432367+00:00"

        example = {"objects": [newer]}
        post_data = utils.obj_to_json(example)
        LOG.info("Calling api for spliceserver import with post data: '%s'" % (post_data))
        resp = self.raw_api_client.post('/api/v1/spliceserver/', format='json', data=post_data,
            SSL_CLIENT_CERT=self.expected_valid_splice_server_identity_pem)
        LOG.info("Response for spliceserver import: Status Code: %s, Response: %s" % (resp.status_code, resp))
        self.assertEquals(resp.status_code, 204)
        # Now check that the server api kept the 'newer' as is and ignored the older
        found = SpliceServer.objects()
        self.assertEquals(len(found), 1)
        self.assertEquals(found[0].uuid, orig_uuid)
        self.assertEquals(found[0].description, newer.description)
        self.assertEquals(found[0].hostname, newer.hostname)
        self.assertEquals(found[0].environment, newer.environment)
        self.assertEquals(str(found[0].updated), "2012-12-31 11:13:06.432000+00:00")
 def create_splice_server_metadata(self, num, save=True):
     retval = []
     for index in range(0, num):
         s = SpliceServer()
         s.uuid = str(uuid4())
         s.description = "Description for %s" % (s.uuid)
         s.hostname = "hostname.example.com"
         s.environment = "environment example"
         # s.created & s.modified will be set on pre_save() hook
         if save:
             s.save()
         retval.append(s)
     return retval
示例#4
0
    def test_date_as_string_is_converted_on_save(self):
        found = SpliceServer.objects()
        self.assertEquals(len(found), 0)

        server = SpliceServer()
        server.uuid = "Splice Server Test UUID-1"
        server.description = "Description data"
        server.hostname = "server.example.com"
        server.environment = "environment info"
        server.created = "2012-12-06T11:13:06.432367"
        server.updated = "2012-12-06T11:13:06.432367"
        server.save()

        found = SpliceServer.objects()
        self.assertEquals(len(found), 1)
        self.assertEquals(found[0].uuid, server.uuid)
        self.assertEquals(found[0].description, server.description)
        self.assertEquals(found[0].hostname, server.hostname)
        self.assertEquals(found[0].environment, server.environment)
        self.assertIsNotNone(found[0].created)
        self.assertEquals(type(found[0].created), datetime.datetime)
        self.assertIsNotNone(found[0].updated)
        self.assertEquals(type(found[0].updated), datetime.datetime)