def test_state_class(self): """Test State Class.""" state = State(id="The exploration hash id") # A new state should have a default name property. self.assertEqual(state.name, feconf.DEFAULT_STATE_NAME) # A state that is put into the datastore must have a parent # exploration. with self.assertRaises(Exception): state.put()
def test_exploration_class(self): """Test the Exploration class.""" exploration = Exploration(id='The exploration hash id') # A new exploration should have a default title property. self.assertEqual(exploration.title, 'New exploration') # A new exploration should have a default is_public property. self.assertEqual(exploration.is_public, False) # An Exploration must have properties 'category' and 'init_state' set. with self.assertRaises(BadValueError): exploration.put() exploration.category = 'The category' with self.assertRaises(BadValueError): exploration.put() # The 'init_state' property must be a valid State. with self.assertRaises(BadValueError): exploration.init_state = 'The State' state = State(id='The state hash id') state.put() exploration.init_state = state.key # The 'states' property must be a list. with self.assertRaises(BadValueError): exploration.states = 'A string' # TODO(emersoj): We should put the initial state in the states list. It # should not be empty exploration.states = [] # The 'states property must be a list of State keys. with self.assertRaises(BadValueError): exploration.states = ['A string'] with self.assertRaises(BadValueError): exploration.states = [state] exploration.states = [state.key] # The 'parameters' property must be a list of Parameter objects. with self.assertRaises(BadValueError): exploration.parameters = 'A string' exploration.parameters = [] parameter = Parameter(name='theParameter', obj_type='Int') with self.assertRaises(BadValueError): exploration.parameters = [parameter.key] exploration.parameters = [parameter] # The 'is_public' property must be a boolean. with self.assertRaises(BadValueError): exploration.is_public = 'true' exploration.is_public = True # The 'image_id' property must be a string. image = Image(id='The image') with self.assertRaises(BadValueError): exploration.image_id = image with self.assertRaises(BadValueError): exploration.image_id = image.key exploration.image_id = 'A string' # The 'editors' property must be a list of User objects. with self.assertRaises(BadValueError): exploration.editors = 'A string' with self.assertRaises(BadValueError): exploration.editors = ['A string'] exploration.editors = [] # There must be at least one editor. with self.assertRaises(BadValueError): exploration.put() exploration.editors = [self.user] # Put and Retrieve the exploration. exploration.put() retrieved_exploration = Exploration.get_by_id('The exploration hash id') self.assertEqual(retrieved_exploration.category, 'The category') self.assertEqual(retrieved_exploration.init_state, state.key) self.assertEqual(retrieved_exploration.title, 'New exploration') self.assertEqual(retrieved_exploration.states, [state.key]) self.assertEqual(retrieved_exploration.parameters, [parameter]) self.assertEqual(retrieved_exploration.is_public, True) self.assertEqual(retrieved_exploration.image_id, 'A string') self.assertEqual(retrieved_exploration.editors, [self.user])