Beispiel #1
0
class OrderingTests(unittest.TestCase):
    def setUp(self):
        self.searcher = ArtistSearcher(fake_data)

    def test_should_not_order_if_not_told_to_do_so(self):
        result = self.searcher.search_by_age(1, 100)
        self.assertEquals(result, fake_data)

    def test_should_order_from_middle_to_edges(self):
        from search_artists.sorter import MedianSorter
        result = self.searcher.search_by_age(1, 100, sorterKlass=MedianSorter)

        expected = [{
            "age": 10
        }, {
            "age": 9
        }, {
            "age": 15
        }, {
            "age": 16
        }, {
            "age": 5
        }, {
            "age": 2
        }, {
            "age": 20
        }]
        self.assertEquals(result, expected)
class OrderingTests(unittest.TestCase):
    def setUp(self):
        self.searcher = ArtistSearcher(fake_data)

    def test_should_not_order_if_not_told_to_do_so(self):
        result = self.searcher.search_by_age(1, 100)
        self.assertEquals(result, fake_data)

    def test_should_order_from_middle_to_edges(self):
        from search_artists.sorter import MedianSorter
        result = self.searcher.search_by_age(1, 100, sorterKlass=MedianSorter)

        expected = [{"age": 10}, {"age": 9}, {"age": 15},
                    {"age": 16}, {"age": 5}, {"age": 2},
                    {"age": 20}]
        self.assertEquals(result, expected)
class SearchingTests(unittest.TestCase):
    def setUp(self):
        self.searcher = ArtistSearcher(fake_data)

    def test_min_value_should_not_be_equal_or_lesser_than_zero(self):

        with self.assertRaises(ValueError) as cm:
            self.searcher.search_by_age(0, 5)
        exception = cm.exception

        error_message = 'min age can not be equal or less than 0'
        self.assertEquals(exception.message, error_message)

    def test_max_value_should_not_be_less_than_min_value(self):
        with self.assertRaises(ValueError) as cm:
            self.searcher.search_by_age(50, 5)
        exception = cm.exception

        error_message = 'max age can not be greater min age'
        self.assertEquals(exception.message, error_message)

    def test_filter_the_data_based_on_provided_parameters(self):
        result = self.searcher.search_by_age(10, 15)
        self.assertEquals(len(result), 2)
Beispiel #4
0
class SearchingTests(unittest.TestCase):
    def setUp(self):
        self.searcher = ArtistSearcher(fake_data)

    def test_min_value_should_not_be_equal_or_lesser_than_zero(self):

        with self.assertRaises(ValueError) as cm:
            self.searcher.search_by_age(0, 5)
        exception = cm.exception

        error_message = 'min age can not be equal or less than 0'
        self.assertEquals(exception.message, error_message)

    def test_max_value_should_not_be_less_than_min_value(self):
        with self.assertRaises(ValueError) as cm:
            self.searcher.search_by_age(50, 5)
        exception = cm.exception

        error_message = 'max age can not be greater min age'
        self.assertEquals(exception.message, error_message)

    def test_filter_the_data_based_on_provided_parameters(self):
        result = self.searcher.search_by_age(10, 15)
        self.assertEquals(len(result), 2)