Example #1
0
    def test_no_scores(self):
        content = Mock()
        target = Target(content)

        actual = target.get_reason_summary(
            {

            }
        )

        self.assertListEqual(
            actual,
            []
        )
Example #2
0
    def test_has_scores(self):
        content = Mock()
        target = Target(content)
        target.get_reason_summary = Mock()
        target.get_reason_summary.return_value = "reason_summary_value"
        target.weight_item_scores = Mock()
        target.weight_item_scores.return_value = "weighted_scores_value"
        target.score_items = Mock()
        target.score_items.return_value = ["score_1", "score_2"]
        target.sort_items = Mock()
        target.sort_items.return_value = "sort_scores_value"

        actual = target.create_suggestion_items("context")

        self.assertEqual("weighted_scores_value", actual)

        self.assertEqual(1, target.score_items.call_count)
        self.assertEqual("context", target.score_items.call_args_list[0][0][0])

        self.assertEqual(1, target.weight_item_scores.call_count)
        self.assertEqual('sort_scores_value', target.weight_item_scores.call_args_list[0][0][0])

        self.assertEqual(1, target.sort_items.call_count)
        self.assertEqual(["score_1", "score_2"], target.sort_items.call_args_list[0][0][0])
Example #3
0
    def test_scores_multiple_reason(self):
        content = Mock()
        target = Target(content)

        actual = target.get_reason_summary(
            {
                '1': {
                    'reasons': [
                        {
                            'key': 'black',
                            'score': 60.0,
                            'type': 'color',
                            'raw_score': 100,
                            'weighting': 60.0
                        },
                        {
                            'raw_score': 50,
                            'score': 3.912023005428146,
                            'type': 'popular'
                        }
                    ],
                    'score': 63.912023005428146
                },
                '2': {
                    'reasons': [
                        {
                            'key': 'black',
                            'score': 60.0,
                            'type': 'color',
                            'raw_score': 100,
                            'weighting': 60.0
                        },
                        {
                            'raw_score': 20,
                            'score': 2.995732273553991,
                            'type': 'popular'
                        }
                    ],
                    'score': 62.99573227355399
                },
                '3': {
                    'reasons': [
                        {
                            'key': 'black',
                            'score': 60.0,
                            'type': 'color',
                            'raw_score': 100,
                            'weighting': 60.0
                        },
                        {
                            'raw_score': 20,
                            'score': 2.995732273553991,
                            'type': 'popular'
                        }
                    ],
                    'score': 60.99573227355399
                },
                '4': {
                    'reasons': [
                        {
                            'key': 'red',
                            'score': 60.0,
                            'type': 'color',
                            'raw_score': 100,
                            'weighting': 60.0
                        },
                        {
                            'raw_score': 20,
                            'score': 4.995732273553991,
                            'type': 'popular'
                        }
                    ],
                    'score': 64.99573227355399
                },
                '5': {
                    'reasons': [
                        {
                            'key': 'red',
                            'score': 60.0,
                            'type': 'color',
                            'raw_score': 100,
                            'weighting': 60.0
                        },
                        {
                            'key': 'black',
                            'score': 60.0,
                            'type': 'color',
                            'raw_score': 100,
                            'weighting': 60.0
                        },
                        {
                            'raw_score': 20,
                            'score': 4.995732273553991,
                            'type': 'popular'
                        }
                    ],
                    'score': 124.99573227355399
                }
            }
        )

        self.assertListEqual(
            actual,
            [
                {
                    'average_score': 124.99573227355398,
                    'count': 1,
                    'reasons': [
                        {
                            'key': 'red', 'score': 60.0, 'type': 'color'
                        },
                        {
                            'key': 'black', 'score': 60.0, 'type': 'color'
                        }
                    ],
                    'total_score': 124.99573227355398
                },
                {
                    'average_score': 64.99573227355398,
                    'count': 1,
                    'reasons': [
                        {
                            'key': 'red', 'score': 60.0, 'type': 'color'
                        }
                    ],
                    'total_score': 64.99573227355398
                },
                {
                    'average_score': 62.634495850845376,
                    'count': 3,
                    'reasons': [
                        {
                            'key': 'black', 'score': 60.0, 'type': 'color'
                        }
                    ],
                    'total_score': 187.90348755253612
                }
            ]
        )
Example #4
0
    def test_scores_single_reason(self):
        content = Mock()
        target = Target(content)

        actual = target.get_reason_summary(
            {
                '1': {
                    'reasons': [
                        {
                            'key': 'black',
                            'score': 60.0,
                            'type': 'color',
                            'raw_score': 100,
                            'weighting': 60.0
                        },
                        {
                            'raw_score': 50,
                            'score': 3.912023005428146,
                            'type': 'popular'
                        }
                    ],
                    'score': 63.912023005428146
                },
                '2': {
                    'reasons': [
                        {
                            'key': 'black',
                            'score': 60.0,
                            'type': 'color',
                            'raw_score': 100,
                            'weighting': 60.0
                        },
                        {
                            'raw_score': 20,
                            'score': 2.995732273553991,
                            'type': 'popular'
                        }
                    ],
                    'score': 62.99573227355399
                },
                '3': {
                    'reasons': [
                        {
                            'key': 'black',
                            'score': 60.0,
                            'type': 'color',
                            'raw_score': 100,
                            'weighting': 60.0
                        },
                        {
                            'raw_score': 20,
                            'score': 4.995732273553991,
                            'type': 'popular'
                        }
                    ],
                    'score': 64.99573227355399
                }
            }
        )

        self.assertListEqual(
            actual,
            [
                {
                    'average_score': 63.967829184178704,
                    'count': 3,
                    'reasons': [
                        {
                            'key': 'black', 'score': 60.0, 'type': 'color'
                        }
                    ],
                    'total_score': 191.90348755253612
                }
            ]
        )