def test_to_dict(self): o = BookOfferFactory().create() d = o.to_dict() self.assertEqual(d["type"], o.__TYPE__) keys = ("binding", "page_extent") self.assertTrue(all(k in d for k in keys)) for k in keys: self.assertEqual(d[k], getattr(o, k))
def test_to_xml(self): f = BookOfferFactory() o = f.create() el = o.to_xml() # Get values and pop book values values = f.get_values() values.pop("binding") values.pop("page_extent") # Change __TYPE__ to "book" AbstractBookOfferFactory.__cls__.__TYPE__ = BookOffer.__TYPE__ abstract_offer = AbstractBookOfferFactory(**values).create() # Create expected element manually expected_el = abstract_offer.to_xml() binding_el = ET.SubElement(expected_el, "binding") binding_el.text = o.binding page_extent_el = ET.SubElement(expected_el, "page_extent") page_extent_el.text = o._page_extent self.assertElementsEquals(el, expected_el)
def test_page_extent_raises_error(self): with self.assertRaises(ValidationError) as e: v = fake.pyint(min_value=-100, max_value=-1) BookOfferFactory(page_extent=v).create() self.assertEqual(str(e), "page_extent must be positive int")
def test_from_xml(self): o = BookOfferFactory().create() el = o.to_xml() parsed_o = BookOffer.from_xml(el) self.assertEqual(o.to_dict(), parsed_o.to_dict())