mirror of
				https://github.com/inventree/InvenTree.git
				synced 2025-11-03 22:55:43 +00:00 
			
		
		
		
	more coverage
This commit is contained in:
		@@ -120,10 +120,74 @@ class WebhookMessageTests(TestCase):
 | 
				
			|||||||
        )
 | 
					        )
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        assert response.status_code == HTTPStatus.FORBIDDEN
 | 
					        assert response.status_code == HTTPStatus.FORBIDDEN
 | 
				
			||||||
        assert (
 | 
					        assert (json.loads(response.content)['detail'] == WebhookView.MESSAGE_TOKEN_ERROR)
 | 
				
			||||||
            json.loads(response.content)['detail'] == WebhookView.MESSAGE_TOKEN_ERROR
 | 
					
 | 
				
			||||||
 | 
					    def test_bad_url(self):
 | 
				
			||||||
 | 
					        response = self.client.post(
 | 
				
			||||||
 | 
					            f'/api/webhook/1234/',
 | 
				
			||||||
 | 
					            content_type='application/json',
 | 
				
			||||||
        )
 | 
					        )
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        assert response.status_code == HTTPStatus.NOT_FOUND
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    def test_bad_json(self):
 | 
				
			||||||
 | 
					        response = self.client.post(
 | 
				
			||||||
 | 
					            self.url,
 | 
				
			||||||
 | 
					            data="{'this': 123}",
 | 
				
			||||||
 | 
					            content_type='application/json',
 | 
				
			||||||
 | 
					            **{'HTTP_TOKEN': str(self.endpoint_def.token)},
 | 
				
			||||||
 | 
					        )
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        assert response.status_code == HTTPStatus.NOT_ACCEPTABLE
 | 
				
			||||||
 | 
					        assert (
 | 
				
			||||||
 | 
					            json.loads(response.content)['detail'] == 'Expecting property name enclosed in double quotes'
 | 
				
			||||||
 | 
					        )
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    def test_success_no_token_check(self):
 | 
				
			||||||
 | 
					        # delete token
 | 
				
			||||||
 | 
					        self.endpoint_def.token = ''
 | 
				
			||||||
 | 
					        self.endpoint_def.save()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        # check
 | 
				
			||||||
 | 
					        response = self.client.post(
 | 
				
			||||||
 | 
					            self.url,
 | 
				
			||||||
 | 
					            content_type='application/json',
 | 
				
			||||||
 | 
					        )
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        assert response.status_code == HTTPStatus.OK
 | 
				
			||||||
 | 
					        assert json.loads(response.content)['message'] == WebhookView.MESSAGE_OK
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    def test_bad_hmac(self):
 | 
				
			||||||
 | 
					        # delete token
 | 
				
			||||||
 | 
					        self.endpoint_def.token = ''
 | 
				
			||||||
 | 
					        self.endpoint_def.secret = '123abc'
 | 
				
			||||||
 | 
					        self.endpoint_def.save()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        # check
 | 
				
			||||||
 | 
					        response = self.client.post(
 | 
				
			||||||
 | 
					            self.url,
 | 
				
			||||||
 | 
					            content_type='application/json',
 | 
				
			||||||
 | 
					        )
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        assert response.status_code == HTTPStatus.FORBIDDEN
 | 
				
			||||||
 | 
					        assert (json.loads(response.content)['detail'] == WebhookView.MESSAGE_TOKEN_ERROR)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    def test_success_hmac(self):
 | 
				
			||||||
 | 
					        # delete token
 | 
				
			||||||
 | 
					        self.endpoint_def.token = ''
 | 
				
			||||||
 | 
					        self.endpoint_def.secret = '123abc'
 | 
				
			||||||
 | 
					        self.endpoint_def.save()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        # check
 | 
				
			||||||
 | 
					        response = self.client.post(
 | 
				
			||||||
 | 
					            self.url,
 | 
				
			||||||
 | 
					            content_type='application/json',
 | 
				
			||||||
 | 
					            **{'HTTP_TOKEN': str('68MXtc/OiXdA5e2Nq9hATEVrZFpLb3Zb0oau7n8s31I=')},
 | 
				
			||||||
 | 
					        )
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        assert response.status_code == HTTPStatus.OK
 | 
				
			||||||
 | 
					        assert json.loads(response.content)['message'] == WebhookView.MESSAGE_OK
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def test_success(self):
 | 
					    def test_success(self):
 | 
				
			||||||
        response = self.client.post(
 | 
					        response = self.client.post(
 | 
				
			||||||
            self.url,
 | 
					            self.url,
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user