Skip to content

Commit

Permalink
feat: generate unit tests using current api defs
Browse files Browse the repository at this point in the history
  • Loading branch information
mamoonraja committed Aug 24, 2020
1 parent 9ef3c6e commit 99555f0
Show file tree
Hide file tree
Showing 14 changed files with 1,380 additions and 27 deletions.
4 changes: 2 additions & 2 deletions test/unit/test_assistant_v1.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# -*- coding: utf-8 -*-
# (C) Copyright IBM Corp. 2018, 2020.
# (C) Copyright IBM Corp. 2020.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand All @@ -22,7 +22,7 @@
import ibm_watson.assistant_v1
from ibm_watson.assistant_v1 import *

base_url = 'https://gateway.watsonplatform.net/assistant/api'
base_url = 'https://api.us-south.assistant.watson.cloud.ibm.com'

##############################################################################
# Start of Service: Message
Expand Down
169 changes: 167 additions & 2 deletions test/unit/test_assistant_v2.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# -*- coding: utf-8 -*-
# (C) Copyright IBM Corp. 2018, 2020.
# (C) Copyright IBM Corp. 2020.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand All @@ -21,7 +21,7 @@
import ibm_watson.assistant_v2
from ibm_watson.assistant_v2 import *

base_url = 'https://gateway.watsonplatform.net/assistant/api'
base_url = 'https://api.us-south.assistant.watson.cloud.ibm.com'

##############################################################################
# Start of Service: Sessions
Expand Down Expand Up @@ -329,6 +329,170 @@ def construct_required_body(self):
# End of Service: Message
##############################################################################

##############################################################################
# Start of Service: Logs
##############################################################################
# region

#-----------------------------------------------------------------------------
# Test Class for list_logs
#-----------------------------------------------------------------------------
class TestListLogs():

#--------------------------------------------------------
# Test 1: Send fake data and check response
#--------------------------------------------------------
@responses.activate
def test_list_logs_response(self):
body = self.construct_full_body()
response = fake_response_LogCollection_json
send_request(self, body, response)
assert len(responses.calls) == 1

#--------------------------------------------------------
# Test 2: Send only required fake data and check response
#--------------------------------------------------------
@responses.activate
def test_list_logs_required_response(self):
# Check response with required params
body = self.construct_required_body()
response = fake_response_LogCollection_json
send_request(self, body, response)
assert len(responses.calls) == 1

#--------------------------------------------------------
# Test 3: Send empty data and check response
#--------------------------------------------------------
@responses.activate
def test_list_logs_empty(self):
check_empty_required_params(self, fake_response_LogCollection_json)
check_missing_required_params(self)
assert len(responses.calls) == 0

#-----------
#- Helpers -
#-----------
def make_url(self, body):
endpoint = '/v2/assistants/{0}/logs'.format(body['assistant_id'])
url = '{0}{1}'.format(base_url, endpoint)
return url

def add_mock_response(self, url, response):
responses.add(responses.GET,
url,
body=json.dumps(response),
status=200,
content_type='application/json')

def call_service(self, body):
service = AssistantV2(
authenticator=NoAuthAuthenticator(),
version='2020-04-01',
)
service.set_service_url(base_url)
output = service.list_logs(**body)
return output

def construct_full_body(self):
body = dict()
body['assistant_id'] = "string1"
body['sort'] = "string1"
body['filter'] = "string1"
body['page_limit'] = 12345
body['cursor'] = "string1"
return body

def construct_required_body(self):
body = dict()
body['assistant_id'] = "string1"
return body


# endregion
##############################################################################
# End of Service: Logs
##############################################################################

##############################################################################
# Start of Service: UserData
##############################################################################
# region

#-----------------------------------------------------------------------------
# Test Class for delete_user_data
#-----------------------------------------------------------------------------
class TestDeleteUserData():

#--------------------------------------------------------
# Test 1: Send fake data and check response
#--------------------------------------------------------
@responses.activate
def test_delete_user_data_response(self):
body = self.construct_full_body()
response = fake_response__json
send_request(self, body, response)
assert len(responses.calls) == 1

#--------------------------------------------------------
# Test 2: Send only required fake data and check response
#--------------------------------------------------------
@responses.activate
def test_delete_user_data_required_response(self):
# Check response with required params
body = self.construct_required_body()
response = fake_response__json
send_request(self, body, response)
assert len(responses.calls) == 1

#--------------------------------------------------------
# Test 3: Send empty data and check response
#--------------------------------------------------------
@responses.activate
def test_delete_user_data_empty(self):
check_empty_required_params(self, fake_response__json)
check_missing_required_params(self)
assert len(responses.calls) == 0

#-----------
#- Helpers -
#-----------
def make_url(self, body):
endpoint = '/v2/user_data'
url = '{0}{1}'.format(base_url, endpoint)
return url

def add_mock_response(self, url, response):
responses.add(responses.DELETE,
url,
body=json.dumps(response),
status=202,
content_type='')

def call_service(self, body):
service = AssistantV2(
authenticator=NoAuthAuthenticator(),
version='2020-04-01',
)
service.set_service_url(base_url)
output = service.delete_user_data(**body)
return output

def construct_full_body(self):
body = dict()
body['customer_id'] = "string1"
return body

def construct_required_body(self):
body = dict()
body['customer_id'] = "string1"
return body


# endregion
##############################################################################
# End of Service: UserData
##############################################################################


def check_empty_required_params(obj, response):
"""Test function to assert that the operation will throw an error when given empty required data
Expand Down Expand Up @@ -397,3 +561,4 @@ def send_request(obj, body, response, url=None):
fake_response_SessionResponse_json = """{"session_id": "fake_session_id"}"""
fake_response_MessageResponse_json = """{"output": {"generic": [], "intents": [], "entities": [], "actions": [], "debug": {"nodes_visited": [], "log_messages": [], "branch_exited": false, "branch_exited_reason": "fake_branch_exited_reason"}, "spelling": {"text": "fake_text", "original_text": "fake_original_text", "suggested_text": "fake_suggested_text"}}, "context": {"global": {"system": {"timezone": "fake_timezone", "user_id": "fake_user_id", "turn_count": 10, "locale": "fake_locale", "reference_time": "fake_reference_time"}, "session_id": "fake_session_id"}, "skills": {}}}"""
fake_response_MessageResponseStateless_json = """{"output": {"generic": [], "intents": [], "entities": [], "actions": [], "debug": {"nodes_visited": [], "log_messages": [], "branch_exited": false, "branch_exited_reason": "fake_branch_exited_reason"}, "spelling": {"text": "fake_text", "original_text": "fake_original_text", "suggested_text": "fake_suggested_text"}}, "context": {"global": {"system": {"timezone": "fake_timezone", "user_id": "fake_user_id", "turn_count": 10, "locale": "fake_locale", "reference_time": "fake_reference_time"}, "session_id": "fake_session_id"}, "skills": {}}}"""
fake_response_LogCollection_json = """{"logs": [], "pagination": {"next_url": "fake_next_url", "matched": 7, "next_cursor": "fake_next_cursor"}}"""
4 changes: 2 additions & 2 deletions test/unit/test_compare_comply_v1.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# -*- coding: utf-8 -*-
# (C) Copyright IBM Corp. 2018, 2020.
# (C) Copyright IBM Corp. 2020.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand All @@ -23,7 +23,7 @@
import ibm_watson.compare_comply_v1
from ibm_watson.compare_comply_v1 import *

base_url = 'https://gateway.watsonplatform.net/compare-comply/api'
base_url = 'https://api.us-south.compare-comply.watson.cloud.ibm.com'

##############################################################################
# Start of Service: HTMLConversion
Expand Down
4 changes: 2 additions & 2 deletions test/unit/test_discovery_v1.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# -*- coding: utf-8 -*-
# (C) Copyright IBM Corp. 2016, 2020.
# (C) Copyright IBM Corp. 2020.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand All @@ -23,7 +23,7 @@
import ibm_watson.discovery_v1
from ibm_watson.discovery_v1 import *

base_url = 'https://gateway.watsonplatform.net/discovery/api'
base_url = 'https://api.us-south.discovery.watson.cloud.ibm.com'

##############################################################################
# Start of Service: Environments
Expand Down
Loading

0 comments on commit 99555f0

Please sign in to comment.