Example #1
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)
Example #2
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'
                    }]
                }
            })
Example #3
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)
Example #4
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)
Example #5
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)
Example #6
0
 def test_regular(self):
     target = Target()
     actual = target.generate_empty_structure(["en"])
     self.assertDictEqual({"en": {}}, actual)