def test_clusters_creation(self):
        """
        Verify Clusters model.
        """
        # Make sure clusters is required
        self.assertRaises(TypeError, clusters.Clusters)

        # Make sure an empty Clusters is still valid
        clusters_model = clusters.Clusters(clusters=[])
        self.assertEquals('[]', clusters_model.to_json())

        # Make sure a Cluster is accepted as expected
        clusters_model = clusters.Clusters(clusters=[
            clusters.Cluster(status='ok',
                             hosts={
                                 'total': 1,
                                 'available': 1,
                                 'unavailable': 0
                             })
        ])
        self.assertEquals(1, len(clusters_model.clusters))
        self.assertEquals(type(str()), type(clusters_model.to_json()))

        # Make sure other instances are not accepted
        clusters_model = clusters.Clusters(clusters=[object()])
Exemple #2
0
    def test_cluster_creation(self):
        """
        Verify cluster model.
        """
        # Make sure it requires data
        self.assertRaises(
            TypeError,
            clusters.Cluster)

        # Make sure a Cluster creates expected results
        cluster_model = clusters.Cluster(status='OK', hostset=[])
        self.assertEquals(type(str()), type(cluster_model.to_json()))
        self.assertIn('total', cluster_model.hosts)
        self.assertIn('available', cluster_model.hosts)
        self.assertIn('unavailable', cluster_model.hosts)