def test_model_pass_through(self): result = panels.record_panel(Context({}), HatWearer) self.assertEqual(result["title"], "Wearer of Hats") self.assertEqual( result["detail_template"], HatWearer.get_detail_template() ) self.assertEqual( result["singleton"], False )
def test_subrecord_data_dictionary(self, subrecords): subrecords.return_value = [HatWearer] dd = extract.get_data_dictionary() hat_wearer = dd.pop(HatWearer.get_display_name()) hats = next(i for i in hat_wearer if i["display_name"] == 'Hats') self.assertEqual(hats['type_display_name'], 'Some of the Hats') wearing_a_hat = next(i for i in hat_wearer if i["display_name"] == 'Wearing A Hat') self.assertEqual(wearing_a_hat['type_display_name'], 'Either True or False')
def test_get_get_subrecord_from_api_name(self): hatwearer_api_name = HatWearer.get_api_name() famous_api_name = FamousLastWords.get_api_name() self.assertEqual( HatWearer, subrecords.get_subrecord_from_api_name(hatwearer_api_name)) self.assertEqual( FamousLastWords, subrecords.get_subrecord_from_api_name(famous_api_name))
def test_context(self): """ context should include logic from template context processors, but should not pollute the global context with this information. """ template = Template( '{% load panels %}{{ title }}{% record_panel models.HatWearer %}{{ title }}' ) ctx = {"models": {"HatWearer": HatWearer}, "title": "someTitle"} result = str(template.render(Context(ctx))) self.assertTrue(result.startswith('someTitle')) self.assertTrue(result.endswith('someTitle')) # the rest of the result should just use the hat wearter title # so lets just remove the start and end result = result.split("someTitle", 1)[1].rsplit("someTitle", 1)[0] self.assertFalse("someTitle" in result) self.assertIn(HatWearer.get_display_name(), result)
def test_defaults_if_there_are_no_defaults(self): self.assertEqual(None, HatWearer._get_field_default("name"))
def test_get_title_over_many_to_many(self): hats = HatWearer._get_field_title("hats") self.assertEqual(hats, "Hats")
def test_get_display_name_from_property(self): self.assertEqual('Wearer of Hats', HatWearer.get_display_name())
def test_register_subrecords(self, subrecords, register): subrecords.return_value = [HatWearer] api.register_subrecords() self.assertEqual(register.call_count, 1) self.assertTrue(register.call_args[0][0][0], HatWearer.get_api_name())