Ejemplo n.º 1
0
    def test_tineye_response(self):
        """ Test TinEyeAPI.TinEyeResponse object. """

        matches = {
            'results': {
                'matches': [{
                    'backlinks': [],
                    'format': '',
                    'overlay': '',
                    'height': 297,
                    'width': 350,
                    'image_url': '',
                    'filesize': 87918,
                    'contributor': True,
                    'size': 103950
                }]
            }
        }
        r = TinEyeResponse._from_dict(matches)
        self.assertEquals(
            repr(r),
            'TinEyeResponse(matches="[Match(image_url="", width=350, height=297)]", total_results=0)'
        ),
        self.assertEquals(len(r.matches), 1)
        self.assertEquals(r.matches[0].height, 297)
        self.assertEquals(r.matches[0].width, 350)

        matches = {
            'results': {
                'matches': [{
                    'backlinks': [],
                    'format': '',
                    'overlay': '',
                    'height': 297,
                    'width': 350,
                    'image_url': '',
                    'filesize': 87918,
                    'contributor': True,
                    'size': 103950
                }, {
                    'backlinks': [],
                    'format': '',
                    'overlay': '',
                    'height': 200,
                    'width': 300,
                    'image_url': '',
                    'filesize': 87918,
                    'contributor': True,
                    'size': 103950
                }]
            }
        }
        r = TinEyeResponse._from_dict(matches)
        self.assertEquals(len(r.matches), 2)
        self.assertEquals(r.matches[1].height, 200)
        self.assertEquals(r.matches[1].width, 300)

        matches = {'results': {'matches': []}}
        r = TinEyeResponse._from_dict(matches)
        self.assertEquals(len(r.matches), 0)
Ejemplo n.º 2
0
 def test_total_results_in_response(self):
     """Test if TinEyeAPI.TinEyeResponse have total_results object."""
     response = {
         'results': {'total_results': 123, 'matches': []}
     }
     r = TinEyeResponse._from_dict(response)
     self.assertEqual(r.total_results, 123)
Ejemplo n.º 3
0
    def test_total_results_in_response(self):
        """ Test if TinEyeAPI.TinEyeResponse contains total_results. """

        response = {
            'results': {'matches': []},
            'stats': {'total_results': 123}
        }
        r = TinEyeResponse._from_dict(response)
        self.assertEqual(r.stats['total_results'], 123)
Ejemplo n.º 4
0
    def test_total_results_in_response(self):
        """ Test if TinEyeAPI.TinEyeResponse contains total_results. """

        response = {
            "results": {
                "matches": []
            },
            "stats": {
                "total_results": 123
            }
        }
        r = TinEyeResponse._from_dict(response)
        self.assertEqual(r.stats["total_results"], 123)
Ejemplo n.º 5
0
    def test_tineye_response(self):
        """ Test TinEyeAPI.TinEyeResponse object. """

        matches = {'results': {'matches': [{'backlinks': [], 'format': '', 'overlay': '', 'height': 297, 'width': 350,
                                            'image_url': '', 'filesize': 87918, 'contributor': True, 'size': 103950}]}}
        r = TinEyeResponse._from_dict(matches)
        self.assertEquals(repr(r), 'TinEyeResponse(matches="[Match(image_url="", width=350, height=297)]")')
        self.assertEquals(len(r.matches), 1)
        self.assertEquals(r.matches[0].height, 297)
        self.assertEquals(r.matches[0].width, 350)

        matches = {'results': {'matches': [{'backlinks': [], 'format': '', 'overlay': '', 'height': 297, 'width': 350,
                                            'image_url': '', 'filesize': 87918, 'contributor': True, 'size': 103950},
                                           {'backlinks': [], 'format': '', 'overlay': '', 'height': 200, 'width': 300,
                                            'image_url': '', 'filesize': 87918, 'contributor': True, 'size': 103950}]}}
        r = TinEyeResponse._from_dict(matches)
        self.assertEquals(len(r.matches), 2)
        self.assertEquals(r.matches[1].height, 200)
        self.assertEquals(r.matches[1].width, 300)

        matches = {'results': {'matches': []}}
        r = TinEyeResponse._from_dict(matches)
        self.assertEquals(len(r.matches), 0)
Ejemplo n.º 6
0
    def test_tineye_response(self):
        """ Test TinEyeAPI.TinEyeResponse object. """

        matches = {
            "results": {
                "matches": [
                    {
                        "backlinks": [],
                        "domain": "",
                        "score": 89.36,
                        "format": "",
                        "overlay": "",
                        "height": 297,
                        "width": 350,
                        "image_url": "",
                        "filesize": 87918,
                        "contributor": True,
                        "size": 103950,
                    }
                ]
            }
        }
        r = TinEyeResponse._from_dict(matches)
        self.assertEqual(
            repr(r),
            'TinEyeResponse(matches=[Match(image_url="", score=89.36, width=350, height=297)], stats={})',
        ),
        self.assertEqual(len(r.matches), 1)
        self.assertEqual(r.matches[0].height, 297)
        self.assertEqual(r.matches[0].width, 350)

        matches = {
            "results": {
                "matches": [
                    {
                        "backlinks": [],
                        "domain": "",
                        "score": 89.36,
                        "format": "",
                        "overlay": "",
                        "height": 297,
                        "width": 350,
                        "image_url": "",
                        "filesize": 87918,
                        "tags": [],
                        "size": 103950,
                    },
                    {
                        "backlinks": [],
                        "domain": "",
                        "score": 50.4,
                        "format": "",
                        "overlay": "",
                        "height": 200,
                        "width": 300,
                        "image_url": "",
                        "filesize": 87918,
                        "tags": [],
                        "size": 103950,
                    },
                ]
            }
        }
        r = TinEyeResponse._from_dict(matches)
        self.assertEqual(len(r.matches), 2)
        self.assertEqual(r.matches[1].height, 200)
        self.assertEqual(r.matches[1].width, 300)

        matches = {"results": {"matches": []}}
        r = TinEyeResponse._from_dict(matches)
        self.assertEqual(len(r.matches), 0)