def test_patch_shard(self, params):
        """Create a shard. Issue a patch command,

        make sure command was successful. Check details to be sure.
        """

        doc = helpers.create_shard_body(
            weight=params.get('weight', 10),
            uri=params.get('uri', "mongodb://127.0.0.1:27017")
        )
        shard_name = params.get('name', "newshard")
        self.addCleanup(self.client.delete, url='/'+shard_name)
        result = self.client.put('/'+shard_name, data=doc)
        self.assertEqual(result.status_code, 201)
        # Update that shard

        patchdoc = helpers.create_shard_body(
            weight=5,
            uri="mongodb://127.0.0.1:27017"
        )
        result = self.client.patch('/'+shard_name, data=patchdoc)
        self.assertEqual(result.status_code, 200)

        # Get the shard, check update#
        result = self.client.get('/'+shard_name)
        self.assertEqual(result.status_code, 200)
        self.assertEqual(result.json()["weight"], 5)
 def test_patch_shard_non_exist(self, params):
     """Issue patch command to shard that doesn't exist. Assert 404."""
     doc = helpers.create_shard_body(
         weight=5,
         uri=params.get('uri', "mongodb://127.0.0.1:27018")
     )
     result = self.client.patch('/nonexistshard', data=doc)
     self.assertEqual(result.status_code, 404)
 def test_insert_shard_bad_data(self, params):
     """Create shards with invalid names and weights. Assert 400."""
     doc = helpers.create_shard_body(
         weight=params.get('weight', 10),
         uri=params.get('uri', "mongodb://127.0.0.1:27017")
     )
     shard_name = params.get('name', "newshard")
     self.addCleanup(self.client.delete, url='/'+shard_name)
     result = self.client.put('/'+shard_name, data=doc)
     self.assertEqual(result.status_code, 400)
    def test_patch_shard_bad_data(self, params):
        """Issue a patch command without a body. Assert 400."""
        # create a shard
        doc = helpers.create_shard_body(
            weight=params.get('weight', 10),
            uri=params.get('uri', "mongodb://127.0.0.1:27017")
        )
        shard_name = params.get('name', "newshard")
        self.addCleanup(self.client.delete, url='/'+shard_name)
        result = self.client.put('/'+shard_name, data=doc)
        self.assertEqual(result.status_code, 201)

        # Update shard with bad post data. Ensure 400
        result = self.client.patch('/'+shard_name)
        self.assertEqual(result.status_code, 400)
    def test_shard_details(self, params):
        """Get the details of a shard. Assert the respective schema."""
        doc = helpers.create_shard_body(
            weight=params.get('weight', 10),
            uri=params.get('uri', "mongodb://127.0.0.1:27017")
        )

        shard_name = params.get('name', "newshard")
        self.addCleanup(self.client.delete, url='/'+shard_name)
        result = self.client.put('/'+shard_name, data=doc)
        self.assertEqual(result.status_code, 201)

        # Test existence
        result = self.client.get('/'+shard_name+'?detailed=true')
        self.assertEqual(result.status_code, 200)
        self.assertSchema(result.json(), 'shard-detail')
    def test_insert_shard(self, params):
        """Test the registering of one shard."""
        doc = helpers.create_shard_body(
            weight=params.get('weight', 10),
            uri=params.get('uri', "mongodb://127.0.0.1:27017")
        )

        shard_name = params.get('name', "newshard")
        self.addCleanup(self.client.delete, url='/'+shard_name)

        result = self.client.put('/'+shard_name, data=doc)
        self.assertEqual(result.status_code, 201)

        # Test existence
        result = self.client.get('/'+shard_name)
        self.assertEqual(result.status_code, 200)
    def test_list_shards(self, params):
        """Add a shard. Get the list of all the shards.

        Assert respective schema
        """
        doc = helpers.create_shard_body(
            weight=params.get('weight', 10),
            uri=params.get('uri', "mongodb://127.0.0.1:27017")
        )
        shard_name = params.get('name', "newshard")
        self.addCleanup(self.client.delete, url='/'+shard_name)
        result = self.client.put('/'+shard_name, data=doc)
        self.assertEqual(result.status_code, 201)

        result = self.client.get()
        self.assertEqual(result.status_code, 200)
        self.assertSchema(result.json(), 'shard-list')
    def test_delete_shard(self, params):
        """Create a shard, then delete it.

        Make sure operation is successful.
        """

        # Create the shard
        doc = helpers.create_shard_body(
            weight=params.get('weight', 10),
            uri=params.get('uri', "mongodb://127.0.0.1:27017")
        )

        shard_name = params.get('name', "newshard")
        result = self.client.put('/'+shard_name, data=doc)
        self.assertEqual(result.status_code, 201)

        # Make sure it exists
        result = self.client.get('/'+shard_name)
        self.assertEqual(result.status_code, 200)

        # Delete it
        result = self.client.delete('/'+shard_name)
        self.assertEqual(result.status_code, 204)