def test__cmp__equal_statuses__compare_same(first_status, second_status): this = Item(MyLibrary(), MyCard()) this.status = first_status other = Item(MyLibrary(), MyCard()) other.status = second_status assert 0 == cmp(this, other) assert 0 == cmp(other, this)
def check(first_status, second_status): print 'first_status =', first_status, 'second_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__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__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']
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']
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']
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']
def parse_checkouts(self, checkouts_soup): checkouts = [] checkouts_rows = checkouts_soup.findAll('tr', {'class': 'checkoutsLine'}) for row in checkouts_rows: title = row('td')[2].find('a').string author = row('td')[2].find('p').find(text=True).strip() due_date = datetime.datetime.strptime(row('td')[4].string, '%m/%d/%y').date() logging.debug('%s / %s / %s', title, author, due_date) checkout = Item(self.library, self.card) checkout.title = title checkout.author = author checkout.status = due_date checkouts.append(checkout) return checkouts
def parse_checkouts(self, checkouts_soup): checkouts = [] checkouts_rows = checkouts_soup.findAll('tr', {'class': 'checkoutsLine'}) for row in checkouts_rows: title = row('td')[2].find('a').string author = row('td')[2].find('p').find(text=True).strip() due_date = datetime.datetime.strptime( row('td')[4].string, '%m/%d/%y').date() logging.debug('%s / %s / %s', title, author, due_date) checkout = Item(self.library, self.card) checkout.title = title checkout.author = author checkout.status = due_date checkouts.append(checkout) return checkouts
def parse_items(self, items): table_header = items.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 = Item(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 == "STATUS": status = parse_status(cell) entry.status = status[0] entry.add_status_note((" ".join(status[1:])).strip()) i += 1 entries.append(entry) return entries
def parse_items(self, items): table_header = items.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 = Item(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 == 'STATUS': status = parse_status(cell) entry.status = status[0] entry.add_status_note((' '.join(status[1:])).strip()) i += 1 entries.append(entry) return entries