def test_put_agent_updated(self, agent_xml, rf): identifier = agent_xml.identifier agent = factories.AgentFactory.create(agent_identifier=identifier) request = rf.put('/', agent_xml.obj_xml, content_type='application/xml') views.app_agent(request, agent.agent_identifier) updated_agent = models.Agent.objects.get(agent_identifier=identifier) assert updated_agent.agent_name != agent.agent_name
def test_head_and_get_headers_match_without_identifier(self, rf): head_request, get_request = rf.head('/'), rf.get('/') head_response = views.app_agent(head_request) get_response = views.app_agent(get_request) expected_headers = get_response.serialize_headers() actual_headers = head_response.serialize_headers() assert expected_headers == actual_headers, 'The response headers do not match.'
def test_head_and_get_headers_match_with_identifier(self, rf): agent = factories.AgentFactory.create() head_request, get_request = rf.head('/'), rf.get('/') head_response = views.app_agent(head_request, agent.agent_identifier) get_response = views.app_agent(get_request, agent.agent_identifier) expected_headers = get_response.serialize_headers() actual_headers = head_response.serialize_headers() assert expected_headers == actual_headers, 'The response headers do not match.'
def test_put_returns_ok(self, agent_xml, rf): identifier = agent_xml.identifier agent = factories.AgentFactory.create(agent_identifier=identifier) request = rf.put('/', agent_xml.obj_xml, content_type='application/xml') response = views.app_agent(request, agent.agent_identifier) assert response.status_code == 200
def test_put_response_content_type(self, agent_xml, rf): identifier = agent_xml.identifier agent = factories.AgentFactory.create(agent_identifier=identifier) request = rf.put('/', agent_xml.obj_xml, content_type='application/xml') response = views.app_agent(request, agent.agent_identifier) assert response.get('Content-Type') == self.CONTENT_TYPE
def test_invalid_identifier_returns_not_found(self, rf): """Test that a nonexistent Agent identifier results in a 404 Not Found. """ request = rf.get('/') response = views.app_agent(request, 'fake-identifier') assert response.status_code == 404
def test_list_returns_ok(self, rf): request = rf.get('/') response = views.app_agent(request) assert response.status_code == 200
def test_head_with_identifier(self, rf): agent = factories.AgentFactory.create() request = rf.head('/') response = views.app_agent(request, agent.agent_identifier) assert response.content == '', 'The message body must be empty' assert response.status_code == 200
def test_list_with_invalid_page(self, rf): request = rf.get('/?page=3') views.app_agent(request)
def test_head_without_identifier(self, rf): request = rf.head('/') response = views.app_agent(request) assert response.content == '', 'The message body must be empty' assert response.status_code == 200
def test_get_with_identifier_response_content(self, rf): agent = factories.AgentFactory.create() request = rf.get('/') response = views.app_agent(request, agent.agent_identifier) assert agent.agent_identifier in response.content
def test_get_with_identifier_response_content_type(self, rf): agent = factories.AgentFactory.create() request = rf.get('/') response = views.app_agent(request, agent.agent_identifier) assert response.get('Content-Type') == self.CONTENT_TYPE
def test_get_with_identifier_returns_ok(self, rf): agent = factories.AgentFactory.create() request = rf.get('/') response = views.app_agent(request, agent.agent_identifier) assert response.status_code == 200
def test_post_returns_created(self, rf, agent_xml): request = rf.post('/', agent_xml.obj_xml, content_type='application/xml') response = views.app_agent(request) assert response.status_code == 201
def test_list_response_content_type(self, rf): request = rf.get('/') response = views.app_agent(request) assert response.get('Content-Type') == self.CONTENT_TYPE
def test_delete_removes_agent(self, rf): agent = factories.AgentFactory.create() request = rf.delete('/') views.app_agent(request, agent.agent_identifier) assert models.Agent.objects.count() == 0
def test_delete_without_identifier_returns_bad_request(self, rf): request = rf.delete('/') response = views.app_agent(request) assert response.status_code == 400
def test_post_without_body_is_handled(self, rf): request = rf.post('/') views.app_agent(request)
def test_post_response_content(self, rf, agent_xml): request = rf.post('/', agent_xml.obj_xml, content_type='application/xml') response = views.app_agent(request) identifier = agent_xml.identifier assert identifier in response.content
def test_post_response_content_type(self, rf, agent_xml): request = rf.post('/', agent_xml.obj_xml, content_type='application/xml') response = views.app_agent(request) assert response.get('Content-Type') == self.CONTENT_TYPE