def test_get_credits_protobuf(self): ''' Test for endpoint: /api/v2/Credits With accept-type "application/x-protobuf" ''' response = self.client.get('/api/v2/Credits',\ **{'HTTP_ACCEPT':'application/x-protobuf'}) self.assertEqual(response.status_code, 200, \ msg='/api/v2/Credits endpoint did not return 200 status code.') response_pb = Model_pb2.Credits() response_pb.ParseFromString(response.content) self.assertEqual(response_pb.TotalCredits, 100000.0, \ msg='/api/v2/Credits endpoint did not return proper Protobuf message.')
def get_credits(request): ''' Endpoint for API GET Credits request. Since this is a research server, mock information will be returned. The user will have plenty of credits. In addition, a message will be returned to indicate that credits will not apply. Returns either: 1. Protobuf-serialized response if "accept" header is "application/x-protobuf" 2. JSON response otherwise ''' total_cred = 100000 display_warning = True message = "Local Research Server - Credits will not apply." language = "English" credits_info = Model_pb2.Credits() credits_info.TotalCredits = total_cred credits_info.DisplayCreditsWarning = display_warning credits_info.CreditsWarningMessage = message credits_info.LanguageCode = language return format_and_send_response(request, credits_info)