def start_following(entity, details): """Peform all necessary steps to allow an entity to start follow the current entity. This involves: - Performing discovery on the entity wishing to follow the current entity. - Making a GET request to the specified notification path which must return 200 OK. - Creating a relationship in the DB. - Returning the relationship in JSON.""" profile = discover_entity(details['entity']) follower = Follower( entity=entity, identity=profile[CoreProfile.__schema__]['entity'], licenses=details['licences'], types=details['types'], notification_path=details['notification_path']) notify_status = notify_following(follower) if not notify_status == 200: raise APIException("Could notify to {}/{}".format( follower.identity, follower.notification_path ), notify_status) return follower.save()
def start_following(entity, details): """Peform all necessary steps to allow an entity to start follow the current entity. This involves: - Performing discovery on the entity wishing to follow the current entity. - Making a GET request to the specified notification path which must return 200 OK. - Creating a relationship in the DB. - Returning the relationship in JSON.""" profile = discover_entity(details['entity']) follower = Follower(entity=entity, identity=profile[CoreProfile.__schema__]['entity'], licenses=details['licences'], types=details['types'], notification_path=details['notification_path']) notify_status = notify_following(follower) if not notify_status == 200: raise APIException( "Could notify to {}/{}".format(follower.identity, follower.notification_path), notify_status) return follower.save()
def before(self): self.assertIsInstance(requests.post, MockFunction) self.assertIsInstance(requests.get, MockFunction) self.follower = Follower(entity=self.entity, identity='http://follower.example.com/tentd', notification_path='notification').save()
def test_entity_follow_delete(self): """Test that an entity can stop being followed.""" # Add a follower to delete follower = Follower(entity=self.entity, identity="http://tent.example.com/test", notification_path="notification").save() # Delete it. response = self.client.delete('/{}/followers/{}'.format( self.name, follower.id)) self.assertEquals(200, response.status_code)
def test_entity_follow_update(self): """Test that the following relationship can be edited correctly.""" # Add a follower to update follower = Follower(entity=self.entity, identity='http://follower.example.com', notification_path='notification').save() response = self.client.put('/{}/followers/{}'.format( self.name, follower.id), data=dumps({'entity': self.new_identity})) # Ensure the request was made sucessfully. self.assertIsNotNone(response) self.assertStatus(response, 200) # Ensure the update happened sucessfully in the JSON. self.assertEquals(str(follower.id), response.json()['id']) self.assertEquals(self.new_identity, response.json()['identity']) # Ensure the DB was updated updated_follower = Follower.objects.get(id=follower.id) self.assertEquals(self.new_identity, updated_follower.identity)