Пример #1
0
    def check(first_status, second_status):
        print 'first_status =', first_status, 'second_status =', second_status
        this = Hold(MyLibrary(), MyCard())
        this.status = first_status
        other = Hold(MyLibrary(), MyCard())
        other.status = second_status

        assert cmp(this, other) < 0
        assert cmp(other, this) > 0
Пример #2
0
def test__build_tempate__hold_expires_soon__expires_added_to_status_note(status, library, card):
    family = None

    hold = Hold(library, card)
    hold.status = (3, 5)
    hold.expires = datetime.date(2010, 2, 28)
    status.holds = [hold]

    template_values = libraryhippo.build_template([status], family)
    assert 'expires on 28&nbsp;February (Sunday)' in template_values['holds_not_ready'][0].status_notes
Пример #3
0
def test__build_tempate__hold_expires_in_a_long_time__expires_not_added_to_status_note(status, library, card):
    family = None

    hold = Hold(library, card)
    hold.status = (3, 5)
    hold.expires = datetime.date(2010, 7, 13)
    status.holds = [hold]

    template_values = libraryhippo.build_template([status], family)
    assert [] == template_values['holds_not_ready'][0].status_notes
Пример #4
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]
Пример #5
0
def test__build_tempate__hold_expires_in_a_long_time__expires_not_added_to_status_note(
        status, library, card):
    family = None

    hold = Hold(library, card)
    hold.status = (3, 5)
    hold.expires = datetime.date(2010, 7, 13)
    status.holds = [hold]

    template_values = libraryhippo.build_template([status], family)
    assert [] == template_values['holds_not_ready'][0].status_notes
Пример #6
0
def test__build_tempate__hold_expires_soon__expires_added_to_status_note(
        status, library, card):
    family = None

    hold = Hold(library, card)
    hold.status = (3, 5)
    hold.expires = datetime.date(2010, 2, 28)
    status.holds = [hold]

    template_values = libraryhippo.build_template([status], family)
    assert 'expires on 28&nbsp;February (Sunday)' in template_values[
        'holds_not_ready'][0].status_notes
Пример #7
0
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]
Пример #8
0
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]
Пример #9
0
def test__build_template__no_messges_no_holds_ready_one_item_due__sets_should_notify(status, library, card):
    item = Item(library, card)
    item.status = datetime.date(2010, 2, 2)
    status.items = [item]

    hold = Hold(library, card)
    hold.status = (3, 5)
    status.holds = [hold]

    family = None

    template_values = libraryhippo.build_template([status], family)
    assert template_values['should_notify']
Пример #10
0
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]
Пример #11
0
def test__build_template__no_messges_no_holds_ready_one_item_due__sets_should_notify(
        status, library, card):
    item = Item(library, card)
    item.status = datetime.date(2010, 2, 2)
    status.items = [item]

    hold = Hold(library, card)
    hold.status = (3, 5)
    status.holds = [hold]

    family = None

    template_values = libraryhippo.build_template([status], family)
    assert template_values['should_notify']
Пример #12
0
def test__build_template__one_messge_no_holds_ready_no_items_due__sets_should_notify(status, library, card):
    item = Item(library, card)
    item.status = datetime.date(2010, 2, 10)
    status.items = [item]

    hold = Hold(library, card)
    hold.status = (3, 5)
    status.holds = [hold]

    status.info = [CardInfo(status.library_name, status.patron_name, 'blah')]

    family = None

    template_values = libraryhippo.build_template([status], family)
    assert template_values['should_notify']
Пример #13
0
def test__build_template__one_messge_no_holds_ready_no_items_due__sets_should_notify(
        status, library, card):
    item = Item(library, card)
    item.status = datetime.date(2010, 2, 10)
    status.items = [item]

    hold = Hold(library, card)
    hold.status = (3, 5)
    status.holds = [hold]

    status.info = [CardInfo(status.library_name, status.patron_name, 'blah')]

    family = None

    template_values = libraryhippo.build_template([status], family)
    assert template_values['should_notify']
Пример #14
0
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]
Пример #15
0
    def parse_holds(self, response):
        table_header = response.find("tr", attrs={"class": "patFuncHeaders"})
        if not table_header:
            return []
        headers = [th.string.strip() for th in table_header("th")]

        entries = []
        for row in table_header.findNextSiblings("tr"):
            entry = Hold(self.library, self.card)
            i = 0
            for cell in row.findAll(td_or_th_regex):
                column_name = headers[i]

                if column_name == "TITLE":
                    self.parse_title(cell, entry)
                elif column_name == "PICKUP LOCATION":
                    if cell.select:
                        all_selected = cell.select.findAll("option",
                                                           selected="selected")
                        if all_selected:
                            pickup = all_selected[0].string
                        else:
                            pickup = ""
                    else:
                        pickup = cell.string

                    # make sure we clean up the string
                    # also ensures that we're saving a true string,
                    # not a NaviagableString, which pickles terribly!
                    entry.pickup = str(pickup).strip()

                elif column_name == "STATUS":
                    entry.status = parse_hold_status(cell)

                elif column_name == "CANCEL IF NOT FILLED BY":
                    try:
                        entry.expires = parse_hold_expires(cell)
                    except:  # noqa E722 - do not use bare except
                        # expiration info isn't critical - ignore
                        pass

                elif column_name == "FREEZE":
                    try:
                        if parse_hold_frozen(cell):
                            entry.freeze()
                    except:  # noqa E722 - do not use bare except
                        # frozen info isn't critical - ignore
                        logging.warn("error getting frozen info",
                                     exc_info=True)
                        pass
                i += 1

            entries.append(entry)
        return entries
Пример #16
0
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
Пример #17
0
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)
Пример #18
0
    def parse_holds(self, response):
        table_header = response.find('tr', attrs={'class': 'patFuncHeaders'})
        if not table_header:
            return []
        headers = [th.string.strip() for th in table_header('th')]

        entries = []
        for row in table_header.findNextSiblings('tr'):
            entry = Hold(self.library, self.card)
            i = 0
            for cell in row('td'):
                column_name = headers[i]

                if column_name == 'TITLE':
                    self.parse_title(cell, entry)
                elif column_name == 'PICKUP LOCATION':
                    if cell.select:
                        pickup = cell.select.findAll('option', selected='selected')[0].string
                    else:
                        pickup = cell.string

                    # make sure we clean up the string
                    # also ensures that we're saving a true string,
                    # not a NaviagableString, which pickles terribly!
                    entry.pickup = str(pickup).strip()

                elif column_name == 'STATUS':
                    entry.status = parse_hold_status(cell)

                elif column_name == 'CANCEL IF NOT FILLED BY':
                    try:
                        entry.expires = parse_hold_expires(cell)
                    except: # noqa E722 - do not use bare except
                        # expiration info isn't critical - ignore
                        pass

                elif column_name == 'FREEZE':
                    try:
                        if parse_hold_frozen(cell):
                            entry.freeze()
                    except: # noqa E722 - do not use bare except
                        # frozen info isn't critical - ignore
                        logging.warn('error getting frozen info', exc_info=True)
                        pass
                i += 1

            entries.append(entry)
        return entries
Пример #19
0
    def parse_holds(self, response):
        table_header = response.find('tr', attrs={'class': 'patFuncHeaders'})
        if not table_header:
            return []
        headers = [th.string.strip() for th in table_header('th')]

        entries = []
        for row in table_header.findNextSiblings('tr'):
            entry = Hold(self.library, self.card)
            i = 0
            for cell in row('td'):
                column_name = headers[i]

                if column_name == 'TITLE':
                    self.parse_title(cell, entry)
                elif column_name == 'PICKUP LOCATION':
                    if cell.select:
                        pickup = cell.select.findAll('option', selected='selected')[0].string
                    else:
                        pickup = cell.string

                    # make sure we clean up the string
                    # also ensures that we're saving a true string,
                    # not a NaviagableString, which pickles terribly!
                    entry.pickup = str(pickup).strip()

                elif column_name == 'STATUS':
                    entry.status = parse_hold_status(cell)

                elif column_name == 'CANCEL IF NOT FILLED BY':
                    try:
                        entry.expires = parse_hold_expires(cell)
                    except:
                        # expiration info isn't critical - ignore
                        pass

                elif column_name == 'FREEZE':
                    try:
                        if parse_hold_frozen(cell):
                            entry.freeze()
                    except:
                        # frozen info isn't critical - ignore
                        logging.warn('error getting frozen info', exc_info=True)
                        pass
                i += 1

            entries.append(entry)
        return entries
Пример #20
0
    def parse_holds(self, holds_soup):
        holds = []
        holds_rows = holds_soup.findAll('tr', {'class': 'pickupHoldsLine'})
        for row in holds_rows:
            title = row('td')[2].find('a').string
            author = row('td')[2].find('p').find(text=True)
            is_frozen = row('td')[3].string == 'Suspended'
            pickup = row('td')[4].string
            rank = int(row('td')[6].string)

            logging.debug('%s / %s / %s', title, author, rank)

            hold = Hold(self.library, self.card)
            hold.title = title
            hold.author = author
            hold.pickup = pickup
            hold.status = self.parse_status(row)
            if is_frozen:
                hold.freeze()

            holds.append(hold)

        return holds
Пример #21
0
    def parse_holds(self, holds_soup):
        holds = []
        holds_rows = holds_soup.findAll('tr', {'class': 'pickupHoldsLine'})
        for row in holds_rows:
            title = row('td')[2].find('a').string
            author = row('td')[2].find('p').find(text=True)
            is_frozen = row('td')[3].string == 'Suspended'
            pickup = row('td')[4].string
            rank = int(row('td')[6].string)

            logging.debug('%s / %s / %s', title, author, rank)

            hold = Hold(self.library, self.card)
            hold.title = title
            hold.author = author
            hold.pickup = pickup
            hold.status = self.parse_status(row)
            if is_frozen:
                hold.freeze()

            holds.append(hold)

        return holds
Пример #22
0
def test__status_text__position__correctly_rendered():
    h = Hold(MyLibrary(), MyCard())
    h.status = (3, 17)
    assert h.status_text() == '3 of 17'
Пример #23
0
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'
Пример #24
0
def test__status_text__in_transit__correctly_rendered():
    h = Hold(MyLibrary(), MyCard())
    h.status = Hold.IN_TRANSIT
    assert h.status_text() == 'In transit'
Пример #25
0
def test__status_text__ready__correctly_rendered():
    h = Hold(MyLibrary(), MyCard())
    h.status = Hold.READY
    assert h.status_text() == 'Ready'
Пример #26
0
def test__status_text__ready__correctly_rendered():
    h = Hold(MyLibrary(), MyCard())
    h.status = Hold.READY
    assert h.status_text() == 'Ready'
Пример #27
0
def test__status_text__in_transit__correctly_rendered():
    h = Hold(MyLibrary(), MyCard())
    h.status = Hold.IN_TRANSIT
    assert h.status_text() == 'In transit'
Пример #28
0
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'
Пример #29
0
def test__status_text__position__correctly_rendered():
    h = Hold(MyLibrary(), MyCard())
    h.status = (3, 17)
    assert h.status_text() == '3 of 17'