Skip to content

Commit

Permalink
Updated tests for solutions folder, category and articles
Browse files Browse the repository at this point in the history
  • Loading branch information
Pr0teus committed Apr 6, 2021
1 parent 482a1f5 commit 4f8f1cb
Show file tree
Hide file tree
Showing 3 changed files with 143 additions and 76 deletions.
74 changes: 22 additions & 52 deletions freshdesk/v2/api.py
Expand Up @@ -554,38 +554,21 @@ def get_category(self, category_id):
url = "solutions/categories/%d" % category_id
return SolutionCategory(**self._api._get(url))

def create_category(self, name, description):
def create_category(self, *args, **kwargs):
url = "solutions/categories"
data = {
'name': name,
'description': description
}
print(json.dumps(data))
return SolutionCategory(**self._api._post(url, data=json.dumps(data)))
return SolutionCategory(**self._api._post(url, data=json.dumps(kwargs)))

def create_category_translation(self, category_id, lang_code, name, description):
def create_category_translation(self, category_id, lang_code, *args, **kwargs):
url = "solutions/categories/%d/%s" %(category_id, lang_code)
data = {
'name': name,
'description': description
}
return SolutionCategory(**self._api._post(url, data=json.dumps(data)))
return SolutionCategory(**self._api._post(url, data=json.dumps(kwargs)))

def update_category(self, category_id, name, description):
def update_category(self, category_id, *args, **kwargs):
url = "solutions/categories/%d" % category_id
data = {
'name': name,
'description': description
}
return SolutionCategory(**self._api._put(url, data=json.dumps(data)))
return SolutionCategory(**self._api._put(url, data=json.dumps(kwargs)))

def update_category_translation(self, category_id, lang_code, name, description):
def update_category_translation(self, category_id, lang_code, *args, **kwargs):
url = "solutions/categories/%d/%s" %(category_id, lang_code)
data = {
'name': name,
'description': description
}
return SolutionCategory(**self._api._put(url, data=json.dumps(data)))
return SolutionCategory(**self._api._put(url, data=json.dumps(kwargs)))

def delete_category(self, category_id):
url = 'solutions/categories/%s' % category_id
Expand Down Expand Up @@ -618,25 +601,21 @@ def get_folder_translated(self, folder_id, lang_code):
url = "solutions/folders/%d/%s" % (folder_id, lang_code)
return SolutionFolder(**self._api._get(url))

def create_folder(self, category_id, **kwargs):
def create_folder(self, category_id, *args, **kwargs):
url = "solutions/categories/%s/folders" % category_id
data = {}
data.update(kwargs)
return SolutionFolder(**self._api._post(url, data=json.dumps(data)))
return SolutionFolder(**self._api._post(url, data=json.dumps(kwargs)))

def create_folder_translation(self, folder_id, lang_code, **kwargs):
def create_folder_translation(self, folder_id, lang_code, *args, **kwargs):
url = "solutions/folders/%s/%s" % ( folder_id, lang_code)
data = {}
data.update(kwargs)
return SolutionFolder(**self._api._post(url, data=json.dumps(data)))
return SolutionFolder(**self._api._post(url, data=json.dumps(kwargs)))

def update_folder(self, folder_id, **kwargs):
def update_folder(self, folder_id, *args, **kwargs):
url = "solutions/folders/%s" % (folder_id)
data = {}
data.update(kwargs)
return SolutionFolder(**self._api._put(url, data=json.dumps(data)))

def update_folder_translation(self, folder_id, lang_code, **kwargs):
def update_folder_translation(self, folder_id, lang_code, *args, **kwargs):
url = "solutions/folders/%s/%s" % (folder_id, lang_code)
print(url)
data = {}
Expand Down Expand Up @@ -670,30 +649,21 @@ def list_from_folder_translated(self, id, language_code):
articles = self._api._get(url)
return [SolutionArticle(**a) for a in articles]

def create_article(self, folder_id, **kwargs):
def create_article(self, folder_id, *args, **kwargs):
url = 'solutions/folders/%s/articles' % folder_id
print(url)
data = {}
data.update(kwargs)
return SolutionArticle(**self._api._post(url, data=json.dumps(data)))
return SolutionArticle(**self._api._post(url, data=json.dumps(kwargs)))

def create_article_translation(self, article_id, lang, **kwargs):
def create_article_translation(self, article_id, lang, *args, **kwargs):
url = 'solutions/articles/%s/%s' %( article_id, lang )
data = {}
data.update(kwargs)
return SolutionArticle(**self._api._post(url, data=json.dumps(data)))
return SolutionArticle(**self._api._post(url, data=json.dumps(kwargs)))

def update_article(self, article_id, **kwargs):
def update_article(self, article_id, *args, **kwargs):
url = 'solutions/articles/%s' % article_id
data = {}
data.update(kwargs)
return SolutionArticle(**self._api._put(url, data=json.dumps(data)))
return SolutionArticle(**self._api._put(url, data=json.dumps(kwargs)))

def update_article_translation(self, article_id, lang, **kwargs):
def update_article_translation(self, article_id, lang, *args, **kwargs):
url = 'solutions/articles/%s/%s' % ( article_id, lang )
data = {}
data.update(kwargs)
return SolutionArticle(**self._api._put(url, data=json.dumps(data)))
return SolutionArticle(**self._api._put(url, data=json.dumps(kwargs)))

def delete_article(self, article_id):
url = 'solutions/articles/%s' % article_id
Expand Down
21 changes: 13 additions & 8 deletions freshdesk/v2/tests/conftest.py
Expand Up @@ -63,10 +63,13 @@ def __init__(self, *args):
re.compile(r"tickets/1/reply$"): self.read_test_file("reply_1.json"),
re.compile(r"contacts$"): self.read_test_file("contact.json"),
re.compile(r"companies$"): self.read_test_file("company.json"),
re.compile(r"solutions/categories$"): self.read_test_file("solution_categories.json"),
re.compile(r"solutions/categories/2/fr$"): self.read_test_file("solution_categories_fr.json"),
re.compile(r"solutions/articles$"): self.read_test_file("solution_articles.json"),
re.compile(r"solutions/articles/2/fr$"): self.read_test_file("solution_articles_fr.json"),
re.compile(r"solutions/categories$"): self.read_first_from_test_file("solution_categories.json"),
re.compile(r"solutions/categories/2/fr$"): self.read_first_from_test_file("solution_categories_fr.json"),
re.compile(r"solutions/categories/2/folders$"): self.read_first_from_test_file("solution_folders.json"),
re.compile(r"solutions/folders/3/fr$"): self.read_first_from_test_file("solution_folders_fr.json"),
re.compile(r"solutions/folders/2/articles$"): self.read_first_from_test_file("solution_articles.json"),
re.compile(r"solutions/articles$"): self.read_first_from_test_file("solution_articles.json"),
re.compile(r"solutions/articles/4/fr$"): self.read_first_from_test_file("solution_articles_fr.json"),
},
"put": {
re.compile(r"tickets/1$"): self.read_test_file("ticket_1_updated.json"),
Expand All @@ -75,10 +78,12 @@ def __init__(self, *args):
re.compile(r"contacts/1/make_agent$"): self.read_test_file("contact_1_agent.json"),
re.compile(r"agents/1$"): self.read_test_file("agent_1_updated.json"),
re.compile(r"companies/1$"): self.read_test_file("company_updated.json"),
re.compile(r"solutions/categories/2$"): self.read_test_file("solution_categories.json"),
re.compile(r"solutions/categories/2/fr$"): self.read_test_file("solution_categories_fr.json"),
re.compile(r"solutions/articles/2/$"): self.read_test_file("solution_articles.json"),
re.compile(r"solutions/articles/2/fr$"): self.read_test_file("solution_articles_fr.json"),
re.compile(r"solutions/categories/2$"): self.read_first_from_test_file("solution_categories.json"),
re.compile(r"solutions/categories/2/fr$"): self.read_first_from_test_file("solution_categories_fr.json"),
re.compile(r"solutions/articles/4$"): self.read_first_from_test_file("solution_articles.json"),
re.compile(r"solutions/articles/4/fr$"): self.read_first_from_test_file("solution_articles_fr.json"),
re.compile(r"solutions/folders/3$"): self.read_first_from_test_file("solution_folders.json"),
re.compile(r"solutions/folders/3/fr$"): self.read_first_from_test_file("solution_folders_fr.json"),
},
"delete": {
re.compile(r"tickets/1$"): None,
Expand Down
124 changes: 108 additions & 16 deletions freshdesk/v2/tests/test_solutions.py
Expand Up @@ -60,19 +60,47 @@ def test_list_solutions_categories(api, solution_category):
assert categories[0].id == TEST_CATEGORY
assert categories[0].id == solution_category.id

def test_create_solutions_category(api, solution_category):

pass
def test_create_solutions_category(api):
category_data = {
"name": "General Category",
"description": "Default solution category, feel free to edit or delete it."
}
new_category = api.solutions.categories.create_category(category_data)
assert isinstance(new_category, SolutionCategory)
assert new_category.name == category_data['name']
assert new_category.description == category_data['description']



def test_create_solutions_category_translate(api, solution_category):
pass
category_data = {
"name": "Catégorie générale",
"description": "French translation of Category General"
}
new_category = api.solutions.categories.create_category_translation(2, 'fr', category_data)
assert isinstance(new_category, SolutionCategory)
assert new_category.name == category_data['name']
assert new_category.description == category_data['description']

def test_update_solutions_category(api, solution_category):
pass
category_data = {
"name": "General Category",
"description": "Default solution category, feel free to edit or delete it."
}
new_category = api.solutions.categories.update_category(2, category_data)
assert isinstance(new_category, SolutionCategory)
assert new_category.name == category_data['name']
assert new_category.description == category_data['description']

def test_update_solutions_category_translated(api, solution_category):
pass
category_data = {
"name": "Catégorie générale",
"description": "French translation of Category General"
}
new_category = api.solutions.categories.update_category_translation(2, 'fr', category_data)
assert isinstance(new_category, SolutionCategory)
assert new_category.name == category_data['name']
assert new_category.description == category_data['description']

def test_delete_solutions_category(api, solution_category):
assert api.solutions.categories.delete_category(2) is None
Expand Down Expand Up @@ -125,17 +153,49 @@ def test_list_solution_folders_translated(api, solution_folder):
assert folders[0].id == TEST_FOLDER
assert folders[0].name == 'Commencer'

def test_create_solutions_folder(api, solution_folder):
pass
def test_create_solutions_folder(api):
folder_data = {
"name": "Getting Started",
"description": "Default solution folder, feel free to edit or delete it.",
"visibility": 2
}
new_folder = api.solutions.folders.create_folder(2,folder_data)
assert isinstance(new_folder, SolutionFolder)
assert new_folder.name == "Getting Started"
assert new_folder.description == "Default solution folder, feel free to edit or delete it."

def test_create_solutions_folder_translate(api, solution_folder):
pass
folder_data = {
"name": "Commencer",
"description": "Default solution folder in french.",
"visibility": 2
}
new_folder = api.solutions.folders.create_folder_translation(3,'fr', folder_data)
assert isinstance(new_folder, SolutionFolder)
assert new_folder.name == "Commencer"
assert new_folder.description == "Default solution folder in french."

def test_update_solutions_folder(api, solution_folder):
pass
folder_data = {
"name": "Getting Started",
"description": "Default solution folder, feel free to edit or delete it.",
"visibility": 2
}
new_folder = api.solutions.folders.update_folder(3,folder_data)
assert isinstance(new_folder, SolutionFolder)
assert new_folder.name == "Getting Started"
assert new_folder.description == "Default solution folder, feel free to edit or delete it."

def test_update_solutions_folder_translated(api, solution_folder):
pass
folder_data = {
"name": "Commencer",
"description": "Default solution folder in french.",
"visibility": 2
}
new_folder = api.solutions.folders.update_folder_translation(3,'fr', folder_data)
assert isinstance(new_folder, SolutionFolder)
assert new_folder.name == "Commencer"
assert new_folder.description == "Default solution folder in french."

def test_delete_solutions_folder(api, solution_folder):
assert api.solutions.folders.delete_folder(2) is None
Expand Down Expand Up @@ -197,17 +257,49 @@ def test_list_solution_articles_translated(api, solution_article):
assert articles_fr[0].id == solution_article.id
assert articles_fr[0].title == 'Modifier les détails du compte'

def test_create_solutions_article(api, solution_article):
pass
def test_create_solutions_article(api):
article_data = {
"title": "Changing account details",
"description": "Update your account details like name, email address, phone number or address, anytime by following these steps: <br><br> <ol><li>Select <b>account details</b> from the menu bar.</li> <li>Click <b>edit icon</b> on the field you'd like to change.</li> <li>After you’ve added the updated details, click <b>save changes</b>.</li> <li>Click <b>done</b> after completing all the updates.</li> <li>You will receive an email from us to verify the changes.</li></ol><br> In case you have <i>forgotten your password</i>, click on the <b>forgot password</b> button and follow the instructions there. <br><br> Note: Once you verify the updated email details, you can resume your activities on your account.",
"status": 2
}
new_article = api.solutions.articles.create_article(2, article_data)
assert isinstance(new_article, SolutionArticle)
assert new_article.title == article_data['title']
assert new_article.description == article_data['description']

def test_create_solutions_article_translate(api, solution_article):
pass
article_data = {
"title": "Modifier les détails du compte",
"description": "Update your account details like name, email address, phone number or address, anytime by following these steps: <br><br> <ol><li>Select <b>account details</b> from the menu bar.</li> <li>Click <b>edit icon</b> on the field you'd like to change.</li> <li>After you’ve added the updated details, click <b>save changes</b>.</li> <li>Click <b>done</b> after completing all the updates.</li> <li>You will receive an email from us to verify the changes.</li></ol><br> In case you have <i>forgotten your password</i>, click on the <b>forgot password</b> button and follow the instructions there. <br><br> Note: Once you verify the updated email details, you can resume your activities on your account.",
"status": 2
}
new_article = api.solutions.articles.create_article_translation(4, 'fr', article_data)
assert isinstance(new_article, SolutionArticle)
assert new_article.title == article_data['title']
assert new_article.description == article_data['description']

def test_update_solutions_article(api, solution_article):
pass
article_data = {
"title": "Changing account details",
"description": "Update your account details like name, email address, phone number or address, anytime by following these steps: <br><br> <ol><li>Select <b>account details</b> from the menu bar.</li> <li>Click <b>edit icon</b> on the field you'd like to change.</li> <li>After you’ve added the updated details, click <b>save changes</b>.</li> <li>Click <b>done</b> after completing all the updates.</li> <li>You will receive an email from us to verify the changes.</li></ol><br> In case you have <i>forgotten your password</i>, click on the <b>forgot password</b> button and follow the instructions there. <br><br> Note: Once you verify the updated email details, you can resume your activities on your account.",
"status": 2
}
new_article = api.solutions.articles.update_article(4, article_data)
assert isinstance(new_article, SolutionArticle)
assert new_article.title == article_data['title']
assert new_article.description == article_data['description']

def test_update_solutions_article_translated(api, solution_article):
pass
article_data = {
"title": "Modifier les détails du compte",
"description": "Update your account details like name, email address, phone number or address, anytime by following these steps: <br><br> <ol><li>Select <b>account details</b> from the menu bar.</li> <li>Click <b>edit icon</b> on the field you'd like to change.</li> <li>After you’ve added the updated details, click <b>save changes</b>.</li> <li>Click <b>done</b> after completing all the updates.</li> <li>You will receive an email from us to verify the changes.</li></ol><br> In case you have <i>forgotten your password</i>, click on the <b>forgot password</b> button and follow the instructions there. <br><br> Note: Once you verify the updated email details, you can resume your activities on your account.",
"status": 2
}
new_article = api.solutions.articles.update_article_translation(4, 'fr', article_data)
assert isinstance(new_article, SolutionArticle)
assert new_article.title == article_data['title']
assert new_article.description == article_data['description']

def test_delete_solutions_article(api, solution_article):
assert api.solutions.articles.delete_article(2) is None

0 comments on commit 4f8f1cb

Please sign in to comment.