def set_value_on_user(self): user = User() self.assertEquals(user.age, None) self.assertEquals(user.gender, None) user.set_value("age", 12) self.assertEquals(user.age, 12) self.assertEquals(user.gender, None) user.set_value("gender", "f") self.assertEquals(user.gender, "f")
def setUp(self): # clean up Question.objects.all().delete() UserResponse.objects.all().delete() # user self.backend = PersistantBackend(slug="MockBackend1") self.backend.save() self.pconnection = PersistantConnection(backend=self.backend, reporter=None, identity="user_1_identity") self.pconnection.save() self.governorate1 = Governorate.objects.get(pk=1) self.district1 = District.objects.get(pk=29) self.user = User(connection=self.pconnection, age=12, gender='m', governorate=self.governorate1.code, district=self.district1.code) self.user.save() # create categorical poll self.question1 = Question(text = 'question1', max_choices = 1) self.question1.save() yellow = Color(file_name="yellow.png", code="#yellow") yellow.save() fruits = Category(name="fruits", color=yellow) fruits.save() red = Color(file_name="red.png", code="#red") red.save() meat = Category(name="meat", color=red) meat.save() self.green = Color(file_name="green.png", code="#green") self.green.save() vegetables = Category(name="vegetables", color=self.green) vegetables.save() self.apple =Choice(code= 'a',question = self.question1, text="apple", category=fruits) self.apple.save() self.bear = Choice(code= 'b',question = self.question1, text="bear", category=meat) self.bear.save() self.cabbage = Choice(code= 'c',question = self.question1, text="cabbage", category=vegetables) self.cabbage.save() self.dillpickle = Choice(code= 'd',question = self.question1, text="dillpickle", category=vegetables) self.dillpickle.save()
def test_dont_set_geolocation_when_not_present(self): user = User() user.set_user_geolocation_if_registered(None) self.assertEquals(user.governorate , None) self.assertEquals(user.district, None)
def test_set_user_geolocation(self): user = User() user.set_user_geolocation_if_registered(self.pconnection) self.assertEquals(user.governorate , "3") self.assertEquals(user.district, "4")