コード例 #1
0
    def setUp(self):
        # Setup a mock response
        from rubber import settings, resource
        settings.RUBBER_MOCK_HTTP_RESPONSE = """{"took":2,"timed_out":false,"_shards":{"total":5,"successful":5,"failed":0},"hits":{"total":2,"max_score":1.0,"hits":[{"_index":"auth","_type":"user","_id":"6","_score":1.0, "_source" : {"username": "******", "first_name": "", "last_name": "", "is_active": true, "is_superuser": false, "is_staff": false, "last_login": "******", "groups": [], "user_permissions": [], "password": "******", "email": "*****@*****.**", "date_joined": "2012-08-02T08:30:11"}},{"_index":"auth","_type":"user","_id":"8","_score":1.0, "_source" : {"username": "******", "first_name": "", "last_name": "", "is_active": true, "is_superuser": false, "is_staff": false, "last_login": "******", "groups": [], "user_permissions": [], "password": "******", "email": "*****@*****.**", "date_joined": "2012-08-02T09:14:38"}}]}}"""
            
        requestmock = RequestMock()
        resource.requests = requestmock

        from rubber import ElasticSearch
        self.client = ElasticSearch('foo', 'bar')
コード例 #2
0
ファイル: alltests.py プロジェクト: mazandaran/rubber
    def setUp(self):
        # Setup a mock response
        from rubber import settings, resource
        settings.RUBBER_MOCK_HTTP_RESPONSE = """{"took":2,"timed_out":false,"_shards":{"total":5,"successful":5,"failed":0},"hits":{"total":2,"max_score":1.0,"hits":[{"_index":"auth","_type":"user","_id":"6","_score":1.0, "_source" : {"username": "******", "first_name": "", "last_name": "", "is_active": true, "is_superuser": false, "is_staff": false, "last_login": "******", "groups": [], "user_permissions": [], "password": "******", "email": "*****@*****.**", "date_joined": "2012-08-02T08:30:11"}},{"_index":"auth","_type":"user","_id":"8","_score":1.0, "_source" : {"username": "******", "first_name": "", "last_name": "", "is_active": true, "is_superuser": false, "is_staff": false, "last_login": "******", "groups": [], "user_permissions": [], "password": "******", "email": "*****@*****.**", "date_joined": "2012-08-02T09:14:38"}}]}}"""
            
        requestmock = RequestMock()
        resource.requests = requestmock

        from rubber import ElasticSearch
        self.client = ElasticSearch('foo', 'bar')
コード例 #3
0
ファイル: alltests.py プロジェクト: mazandaran/rubber
class ResponseTest(TestCase):
    def setUp(self):
        # Setup a mock response
        from rubber import settings, resource
        settings.RUBBER_MOCK_HTTP_RESPONSE = """{"took":2,"timed_out":false,"_shards":{"total":5,"successful":5,"failed":0},"hits":{"total":2,"max_score":1.0,"hits":[{"_index":"auth","_type":"user","_id":"6","_score":1.0, "_source" : {"username": "******", "first_name": "", "last_name": "", "is_active": true, "is_superuser": false, "is_staff": false, "last_login": "******", "groups": [], "user_permissions": [], "password": "******", "email": "*****@*****.**", "date_joined": "2012-08-02T08:30:11"}},{"_index":"auth","_type":"user","_id":"8","_score":1.0, "_source" : {"username": "******", "first_name": "", "last_name": "", "is_active": true, "is_superuser": false, "is_staff": false, "last_login": "******", "groups": [], "user_permissions": [], "password": "******", "email": "*****@*****.**", "date_joined": "2012-08-02T09:14:38"}}]}}"""
            
        requestmock = RequestMock()
        resource.requests = requestmock

        from rubber import ElasticSearch
        self.client = ElasticSearch('foo', 'bar')


    def test_response_class(self):
        """
        Responses should be rubber.response.Response objects, except
        for the search response which should be a rubber.response.SearchResponse
        """

        response = self.client.search({})

        from rubber.response import Response, SearchResponse
        self.assertTrue(isinstance(response, Response))
        self.assertTrue(isinstance(response, SearchResponse))

        response = self.client.mapping.get()
        self.assertTrue(isinstance(response, Response))
        self.assertFalse(isinstance(response, SearchResponse))

    def test_response_json(self):
        """
        Responses should have a json property if json has been parsed.
        """
        response = self.client.search()
        self.assertTrue(isinstance(response.json, dict))


        # with invalid json
        from rubber import settings
        settings.RUBBER_MOCK_HTTP_RESPONSE = """;;;"""
            
        response = self.client.search()
        self.assertIsNone(response.json)
コード例 #4
0
class ResponseTest(TestCase):
    def setUp(self):
        # Setup a mock response
        from rubber import settings, resource
        settings.RUBBER_MOCK_HTTP_RESPONSE = """{"took":2,"timed_out":false,"_shards":{"total":5,"successful":5,"failed":0},"hits":{"total":2,"max_score":1.0,"hits":[{"_index":"auth","_type":"user","_id":"6","_score":1.0, "_source" : {"username": "******", "first_name": "", "last_name": "", "is_active": true, "is_superuser": false, "is_staff": false, "last_login": "******", "groups": [], "user_permissions": [], "password": "******", "email": "*****@*****.**", "date_joined": "2012-08-02T08:30:11"}},{"_index":"auth","_type":"user","_id":"8","_score":1.0, "_source" : {"username": "******", "first_name": "", "last_name": "", "is_active": true, "is_superuser": false, "is_staff": false, "last_login": "******", "groups": [], "user_permissions": [], "password": "******", "email": "*****@*****.**", "date_joined": "2012-08-02T09:14:38"}}]}}"""
            
        requestmock = RequestMock()
        resource.requests = requestmock

        from rubber import ElasticSearch
        self.client = ElasticSearch('foo', 'bar')


    def test_response_class(self):
        """
        Responses should be rubber.response.Response objects, except
        for the search response which should be a rubber.response.SearchResponse
        """

        response = self.client.search({})

        from rubber.response import Response, SearchResponse
        self.assertTrue(isinstance(response, Response))
        self.assertTrue(isinstance(response, SearchResponse))

        response = self.client.mapping.get()
        self.assertTrue(isinstance(response, Response))
        self.assertFalse(isinstance(response, SearchResponse))

    def test_response_json(self):
        """
        Responses should have a json property if json has been parsed.
        """
        response = self.client.search()
        self.assertTrue(isinstance(response.json, dict))


        # with invalid json
        from rubber import settings
        settings.RUBBER_MOCK_HTTP_RESPONSE = """;;;"""
            
        response = self.client.search()
        self.assertIsNone(response.json)
コード例 #5
0
 class Article(models.Model):
     elasticsearch = ElasticSearch(auto_index=True)