Пример #1
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
Пример #2
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)
Пример #3
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
Пример #4
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
Пример #5
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
Пример #6
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
Пример #7
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
Пример #8
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
Пример #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__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']
Пример #11
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']
Пример #12
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
Пример #13
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
Пример #14
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']
Пример #15
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
Пример #16
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
Пример #17
0
def test__status_text__position__correctly_rendered():
    h = Hold(MyLibrary(), MyCard())
    h.status = (3, 17)
    assert h.status_text() == '3 of 17'
Пример #18
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'
Пример #19
0
def test__status_text__in_transit__correctly_rendered():
    h = Hold(MyLibrary(), MyCard())
    h.status = Hold.IN_TRANSIT
    assert h.status_text() == 'In transit'
Пример #20
0
def test__status_text__ready__correctly_rendered():
    h = Hold(MyLibrary(), MyCard())
    h.status = Hold.READY
    assert h.status_text() == 'Ready'
Пример #21
0
def test__status_text__ready__correctly_rendered():
    h = Hold(MyLibrary(), MyCard())
    h.status = Hold.READY
    assert h.status_text() == 'Ready'
Пример #22
0
def test__status_text__in_transit__correctly_rendered():
    h = Hold(MyLibrary(), MyCard())
    h.status = Hold.IN_TRANSIT
    assert h.status_text() == 'In transit'
Пример #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__position__correctly_rendered():
    h = Hold(MyLibrary(), MyCard())
    h.status = (3, 17)
    assert h.status_text() == '3 of 17'