Пример #1
0
    def test_no_value(self):
        target = Target()
        acutal = {
            "en": {
                "black": [
                    {
                        "key": "black",
                        "type": "color"
                    }
                ]
            }
        }

        target.add_value(
            acutal,
            "en",
            "blue",
            [
                {
                    "key": "blue",
                    "type": "color"
                }
            ]
        )

        self.assertDictEqual(
            {
                'en': {
                    'black': [{'key': 'black', 'type': 'color'}],
                    'blue': [{'key': 'blue', 'type': 'color'}]
                }
            },
            acutal
        )
Пример #2
0
    def test_display_name_not_exists(self):
        target = Target()
        target.add_hearts = Mock()
        target.get_from_database = Mock()
        target.get_from_database.return_value = [{
            "_id": {
                "type": "brand",
                "key": "ash"
            },
            "aliases": [{
                "value": "ash",
                "language": "en"
            }]
        }]

        actual = target.load(["en"])

        self.assertDictEqual(
            actual, {
                'en': {
                    'ash': [{
                        'type': 'brand',
                        'key': 'ash',
                        'source': 'content',
                        'display_name': 'ash',
                        'match_type': 'alias'
                    }]
                }
            })
        self.assertEqual(target.add_hearts.call_count, 1)
Пример #3
0
    def test_display_name_not_exists(self):
        target = Target()
        target.add_hearts = Mock()
        target.get_from_database = Mock()
        target.get_from_database.return_value = [
            {
                "_id": {
                    "type": "brand",
                    "key": "ash"
                },
                "aliases": [
                    {
                        "value": "ash",
                        "language": "en"
                    }
                ]
            }
        ]

        actual = target.load(["en"])

        self.assertDictEqual(
            actual,
            {
                'en': {
                    'ash': [{'type': 'brand', 'key': 'ash', 'source': 'content', 'display_name': 'ash',
                             'match_type': 'alias'}]
                }
            }
        )
        self.assertEqual(
            target.add_hearts.call_count,
            1
        )
Пример #4
0
 def get(self):
     container = Container()
     vocab = Vocab(container=container)
     vocab.load(['en'])
     self.set_header('Content-Type', 'application/json')
     self.set_status(200)
     self.finish({"status": "OK"})
Пример #5
0
 def get(self):
     container = Container()
     vocab = Vocab(container=container)
     vocab.load(['en'])
     self.set_header('Content-Type', 'application/json')
     self.set_status(200)
     self.finish({
         "status": "OK"
     })
Пример #6
0
 def test_regular(self):
     target = Target()
     actual = target.generate_empty_structure(["en"])
     self.assertDictEqual(
         {
             "en": {}
         },
         actual
     )
Пример #7
0
    def test_multiple_alias_different_type(self):
        target = Target()
        target.get_from_database = Mock()
        target.get_from_database.return_value = [{
            "_id": {
                "type": "brand",
                "key": "ash"
            },
            "display_name":
            "Ash",
            "aliases": [{
                "value": "ash",
                "language": "en"
            }]
        }, {
            "_id": {
                "type": "color",
                "key": "ash"
            },
            "display_name":
            None,
            "aliases": [{
                "value": "ash",
                "language": "en"
            }]
        }]

        actual = target.load(["en"])

        self.assertDictEqual(
            actual, {
                'en': {
                    'hearts': [{
                        'type': 'interest',
                        'key': 'heart',
                        'source': 'context',
                        'display_name': 'heart',
                        'match_type': 'alias'
                    }],
                    'ash': [{
                        'type': 'brand',
                        'key': 'ash',
                        'source': 'content',
                        'display_name': 'Ash',
                        'match_type': 'alias'
                    }, {
                        'type': 'color',
                        'key': 'ash',
                        'source': 'content',
                        'display_name': 'ash',
                        'match_type': 'alias'
                    }]
                }
            })
Пример #8
0
    def test_spelling_mistakes(self):
        target = Target()
        target.add_hearts = Mock()
        target.get_from_database = Mock()
        target.get_from_database.return_value = [
            {
                "_id": {
                    "type": "color",
                    "key": "citrus"
                },
                "aliases": [
                    {
                        "value": "citrus",
                        "language": "en"
                    },
                    {
                        "value": "agrume",
                        "language": "it"
                    },
                    {
                        "value": "citrin",
                        "language": "fr"
                    },
                    {
                        "value": "citru",
                        "language": "en",
                        "type": "spelling"
                    }
                ]
            }
        ]

        actual = target.load(["en"])

        self.assertDictEqual(
            actual,
            {
                'en': {
                    'citru': [{'type': 'color', 'key': 'citrus', 'source': 'content', 'display_name': 'citrus',
                               'match_type': 'spelling'}],
                    'citrus': [{'type': 'color', 'key': 'citrus', 'source': 'content', 'display_name': 'citrus',
                                'match_type': 'alias'}],
                }
            }
        )

        self.assertEqual(
            target.add_hearts.call_count,
            1
        )
Пример #9
0
    def test_spelling_mistakes(self):
        target = Target()
        target.add_hearts = Mock()
        target.get_from_database = Mock()
        target.get_from_database.return_value = [{
            "_id": {
                "type": "color",
                "key": "citrus"
            },
            "aliases": [{
                "value": "citrus",
                "language": "en"
            }, {
                "value": "agrume",
                "language": "it"
            }, {
                "value": "citrin",
                "language": "fr"
            }, {
                "value": "citru",
                "language": "en",
                "type": "spelling"
            }]
        }]

        actual = target.load(["en"])

        self.assertDictEqual(
            actual, {
                'en': {
                    'citru': [{
                        'type': 'color',
                        'key': 'citrus',
                        'source': 'content',
                        'display_name': 'citrus',
                        'match_type': 'spelling'
                    }],
                    'citrus': [{
                        'type': 'color',
                        'key': 'citrus',
                        'source': 'content',
                        'display_name': 'citrus',
                        'match_type': 'alias'
                    }],
                }
            })

        self.assertEqual(target.add_hearts.call_count, 1)
Пример #10
0
    def test_multiple_alias_different_type(self):
        target = Target()
        target.get_from_database = Mock()
        target.get_from_database.return_value = [
            {
                "_id": {
                    "type": "brand",
                    "key": "ash"
                },
                "display_name": "Ash",
                "aliases": [
                    {
                        "value": "ash",
                        "language": "en"
                    }
                ]
            },
            {
                "_id": {
                    "type": "color",
                    "key": "ash"
                },
                "display_name": None,
                "aliases": [
                    {
                        "value": "ash",
                        "language": "en"
                    }
                ]
            }
        ]

        actual = target.load(["en"])

        self.assertDictEqual(
            actual,
            {
                'en': {
                    'hearts': [{'type': 'interest', 'key': 'heart', 'source': 'context', 'display_name': 'heart',
                                'match_type': 'alias'}],
                    'ash': [{'type': 'brand', 'key': 'ash', 'source': 'content', 'display_name': 'Ash',
                             'match_type': 'alias'},
                            {'type': 'color', 'key': 'ash', 'source': 'content', 'display_name': 'ash',
                             'match_type': 'alias'}]
                }
            }
        )
Пример #11
0
    def __init__(self):
        from detect.container import Container
        from detect.vocab import Vocab

        container = Container()
        vocab = Vocab(container=container)
        alias_data = vocab.load(['en'])

        handlers = [
            url(r"/status", Status, name="status"),
            url(r"/refresh", Refresh, name="refresh"),
            url(r"/(.*)?", Detect, dict(alias_data=alias_data), name="detect")
        ]

        settings = dict(
            # static_path = os.path.join(os.path.dirname(__file__), "static"),
            # template_path = os.path.join(os.path.dirname(__file__), "templates"),
            debug=tornado.options.options.debug, )
        tornado.web.Application.__init__(self, handlers, **settings)
Пример #12
0
    def __init__(self):
        from detect.container import Container
        from detect.vocab import Vocab

        container = Container()
        vocab = Vocab(container=container)
        alias_data = vocab.load(['en'])

        handlers = [
            url(r"/status", Status, name="status"),
            url(r"/refresh", Refresh, name="refresh"),
            url(r"/(.*)?", Detect, dict(alias_data=alias_data), name="detect")
        ]

        settings = dict(
            # static_path = os.path.join(os.path.dirname(__file__), "static"),
            # template_path = os.path.join(os.path.dirname(__file__), "templates"),
            debug=tornado.options.options.debug,
        )
        tornado.web.Application.__init__(self, handlers, **settings)
Пример #13
0
    def test_already_exsits(self):
        target = Target()
        acutal = {"en": {"black": [{"key": "black", "type": "color"}]}}

        target.add_value(acutal, "en", "black", [{
            "key": "new_black",
            "type": "color"
        }])

        self.assertDictEqual(
            {
                'en': {
                    'black': [{
                        'key': 'black',
                        'type': 'color'
                    }, {
                        'key': 'new_black',
                        'type': 'color'
                    }]
                }
            }, acutal)
Пример #14
0
    def test_no_value(self):
        target = Target()
        acutal = {"en": {"black": [{"key": "black", "type": "color"}]}}

        target.add_value(acutal, "en", "blue", [{
            "key": "blue",
            "type": "color"
        }])

        self.assertDictEqual(
            {
                'en': {
                    'black': [{
                        'key': 'black',
                        'type': 'color'
                    }],
                    'blue': [{
                        'key': 'blue',
                        'type': 'color'
                    }]
                }
            }, acutal)
Пример #15
0
    def test_already_exsits(self):
        target = Target()
        acutal = {
            "en": {
                "black": [
                    {
                        "key": "black",
                        "type": "color"
                    }
                ]
            }
        }

        target.add_value(
            acutal,
            "en",
            "black",
            [
                {
                    "key": "new_black",
                    "type": "color"
                }
            ]
        )

        self.assertDictEqual(
            {
                'en': {
                    'black': [
                        {'key': 'black', 'type': 'color'},
                        {'key': 'new_black', 'type': 'color'}
                    ]
                }
            },
            acutal
        )
Пример #16
0
 def test_regular(self):
     target = Target()
     actual = target.generate_empty_structure(["en"])
     self.assertDictEqual({"en": {}}, actual)