def test_load_existing_value_in_form(self): NEWVAL = 'fooval' prop = SiteProperty.objects.create(site=self.site, slug='foo') dato = ProfileData(site_property=prop, user=self.user) dato.set_value(NEWVAL) form = ProfileForm(user=self.user, site=self.site) assert_equals(form.fields[prop.slug].initial, NEWVAL)
def test_profile_data_update_long_string(self): dato_long_str = 's' * 50 dato = ProfileData(user=self.user, site_property=self.site_prop) dato.set_value(dato_long_str, self.site_prop.value_type) dato.set_value(dato_long_str*2) assert_equals(dato.value_big.value, dato_long_str*2)
def test_load_existing_value_in_form(self): NEWVAL = "fooval" prop = SiteProperty.objects.create(site=self.site, slug="foo") dato = ProfileData(site_property=prop, user=self.user) dato.set_value(NEWVAL) form = ProfileForm(user=self.user, site=self.site) assert_equals(form.fields[prop.slug].initial, NEWVAL)
def test_profile_data_save_short_str(self): dato_short_str = 's' * 10 dato = ProfileData(user=self.user, site_property=self.site_prop) dato.set_value(dato_short_str, self.site_prop.value_type) assert_equals(dato.value, dato_short_str) assert_equals(dato.value_str, dato_short_str) assert_equals(dato.value_big, None)
def test_profile_data_save_bool(self): data_bool = 50 prop = SiteProperty.objects.create(value_type=TYPE_BOOL, slug='prop', site=self.site) dato = ProfileData(user=self.user, site_property=prop) dato.set_value(data_bool, prop.value_type) assert_equals(dato.value, data_bool)
def test_profile_data_update_int(self): data_int = 50 prop = SiteProperty.objects.create(value_type=TYPE_INT, slug='prop', site=self.site) dato = ProfileData(user=self.user, site_property=prop) dato.set_value(data_int, prop.value_type) dato.set_value(data_int*2) assert_equals(dato.value_int, data_int*2)
def test_delete_signal_remove_relevant_profiledata(self): prop = SiteProperty.objects.create(site=self.site, slug='foo') user = Identity.objects.create(email='*****@*****.**') NEWVAL = 'foobar' dato = ProfileData(site_property=prop, user=user) dato.set_value(NEWVAL) prop.delete() assert_equals([], list(ProfileData.objects.all()))
def test_update_existing_value(self): prop = SiteProperty.objects.create(slug="foo", is_unique=True, site=self.site) NEWVAL = "foobar" dato = ProfileData(site_property=prop, user=self.user) dato.set_value("foo") valid_data = {"foo": NEWVAL} form = ProfileForm(user=self.user, site=self.site, data=valid_data) assert_equals(True, form.is_valid()) load_dato = ProfileData.objects.get(site_property=prop, user=self.user) assert_equals(load_dato.value, NEWVAL)
def test_update_existing_value(self): prop = SiteProperty.objects.create(slug='foo', is_unique=True, site=self.site) NEWVAL = 'foobar' dato = ProfileData(site_property=prop, user=self.user) dato.set_value('foo') valid_data = {'foo': NEWVAL} form = ProfileForm(user=self.user, site=self.site, data=valid_data) assert_equals(True, form.is_valid()) load_dato = ProfileData.objects.get(site_property=prop, user=self.user) assert_equals(load_dato.value, NEWVAL)
def test_clean_flushes_profile_cache(self): prop = SiteProperty.objects.create(slug="foo", is_unique=True, site=self.site) profile = SiteProfile.objects.create(user=self.user, site=self.site, is_active=True) # cache data SiteProfile.objects.get_data(user=self.user, site=self.site) NEWVAL = "foobar" dato = ProfileData(site_property=prop, user=self.user) dato.set_value("foo") valid_data = {"foo": NEWVAL} form = ProfileForm(user=self.user, site=self.site, data=valid_data) assert_equals(True, form.is_valid()) changed_data = SiteProfile.objects.get_data(user=self.user, site=self.site) assert_equals(NEWVAL, changed_data["foo"])
def test_clean_flushes_profile_cache(self): prop = SiteProperty.objects.create(slug='foo', is_unique=True, site=self.site) profile = SiteProfile.objects.create(user=self.user, site=self.site, is_active=True) #cache data SiteProfile.objects.get_data(user=self.user, site=self.site) NEWVAL = 'foobar' dato = ProfileData(site_property=prop, user=self.user) dato.set_value('foo') valid_data = {'foo': NEWVAL} form = ProfileForm(user=self.user, site=self.site, data=valid_data) assert_equals(True, form.is_valid()) changed_data = SiteProfile.objects.get_data(user=self.user, site=self.site) assert_equals(NEWVAL, changed_data['foo'])
def test_profile_data_update_long_string(self): dato_long_str = 's' * 50 dato = ProfileData(user=self.user, site_property=self.site_prop) dato.set_value(dato_long_str, self.site_prop.value_type) dato.set_value(dato_long_str * 2) assert_equals(dato.value_big.value, dato_long_str * 2)
def test_profile_data_update_int(self): data_int = 50 prop = SiteProperty.objects.create(value_type=TYPE_INT, slug='prop', site=self.site) dato = ProfileData(user=self.user, site_property=prop) dato.set_value(data_int, prop.value_type) dato.set_value(data_int * 2) assert_equals(dato.value_int, data_int * 2)
def test_profile_data_unicode_pass(self): #coverage ftw name = u'námé únícódé' p_data = ProfileData(user=self.user, site_property=self.site_prop) assert_equals(True, self.site_prop.name in unicode(p_data))