def test__cmp__equal_statuses__compare_same(first_status, second_status): this = Hold(MyLibrary(), MyCard()) this.status = first_status other = Hold(MyLibrary(), MyCard()) other.status = second_status assert 0 == cmp(this, other) assert 0 == cmp(other, this)
def test__cmp__inequal_statuses__correctly_ordered(higher_status, lower_status): this = Hold(MyLibrary(), MyCard()) this.status = higher_status other = Hold(MyLibrary(), MyCard()) other.status = lower_status assert cmp(this, other) < 0 assert cmp(other, this) > 0
def test__cmp__inequal_statuses__correctly_ordered(first_status, second_status): this = Item(MyLibrary(), MyCard()) this.status = first_status other = Item(MyLibrary(), MyCard()) other.status = second_status assert cmp(this, other) < 0 assert cmp(other, this) > 0
def test__holds_sort__rwl_holds_with_integer_status__sorted_by_status(): library = MyLibrary() c = MyCard() holds = [Hold(library, c), Hold(library, c), Hold(library, c)] holds[0].status = 15 holds[1].status = 2 holds[2].status = 7 for i in range(len(holds)): holds[i].title = chr(i + ord('A')) holds.sort() assert ['B', 'C', 'A'] == [h.title for h in holds]
def test__holds_sort__delayed_hold__sorts_last(): library = MyLibrary() c = MyCard() holds = [Hold(library, c), Hold(library, c), Hold(library, c)] holds[0].title = 'A' holds[0].status = 15 holds[1].title = 'B' holds[1].status = Hold.DELAYED holds[2].title = 'C' holds[2].status = (7, 31) holds.sort() assert ['C', 'A', 'B'] == [h.title for h in holds]
def test__items_sort__same_date__sorted_by_name(): library = MyLibrary() c = MyCard() items = [Item(library, c), Item(library, c), Item(library, c)] items[0].status = datetime.date(2009, 9, 7) items[0].title = 'B' items[1].status = datetime.date(2009, 9, 7) items[1].title = 'A' items[2].status = datetime.date(2009, 9, 7) items[2].title = 'C' items.sort() assert ['A', 'B', 'C'] == [i.title for i in items]
def test__holds_sort__holds_with_integer_status_some_frozen__frozen_sorts_last( ): library = MyLibrary() c = MyCard() holds = [Hold(library, c), Hold(library, c), Hold(library, c)] holds[0].status = 1 holds[1].status = 3 holds[2].status = 2 holds[2].freeze() for i in range(len(holds)): holds[i].title = chr(i + ord('A')) holds.sort() assert ['A', 'B', 'C'] == [h.title for h in holds]
def test__holds_sort__all_ready__sorted_by_title(): library = MyLibrary() c = MyCard() holds = [Hold(library, c), Hold(library, c), Hold(library, c)] holds[0].status = Hold.READY holds[0].title = 'B' holds[1].status = Hold.READY holds[1].title = 'A' holds[2].status = Hold.READY holds[2].title = 'C' holds.sort() assert ['A', 'B', 'C'] == [h.title for h in holds]
def test__holds_sort__mixed_rwl_wpl_holds__sort_okay(): library = MyLibrary() c = MyCard() holds = [ Hold(library, c), Hold(library, c), Hold(library, c), Hold(library, c) ] holds[0].status = 15 holds[1].status = (2, 9) holds[2].status = (7, 31) holds[3].status = 1 for i in range(len(holds)): holds[i].title = chr(i + ord('A')) holds.sort() assert ['D', 'B', 'C', 'A'] == [h.title for h in holds]
def library(): """Sort of like setup - will provide a library argument to tests that want it""" return MyLibrary()
def test__status_text__position__correctly_rendered(): h = Hold(MyLibrary(), MyCard()) h.status = (3, 17) assert h.status_text() == '3 of 17'
def test__status_text__unknown_status__correctly_rendered(): h = Hold(MyLibrary(), MyCard()) h.status = 'something I made up' assert h.status_text() == 'something I made up'
def test__status_text__in_transit__correctly_rendered(): h = Hold(MyLibrary(), MyCard()) h.status = Hold.IN_TRANSIT assert h.status_text() == 'In transit'
def test__status_text__ready__correctly_rendered(): h = Hold(MyLibrary(), MyCard()) h.status = Hold.READY assert h.status_text() == 'Ready'