Skip to content

Commit

Permalink
Merge pull request #20 from ViderumGlobal/Add-tests
Browse files Browse the repository at this point in the history
Add tests
  • Loading branch information
klikstermkd committed Feb 1, 2018
2 parents 74125b0 + ed6ad18 commit c06aeac
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 1 deletion.
60 changes: 60 additions & 0 deletions ckanext/requestdata/tests/test_helpers.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
# encoding: utf-8
import nose
import json
from datetime import datetime, timedelta
from ckanext.requestdata import helpers as h
import ckan.plugins as p
from ckan.tests import helpers, factories
from ckan import logic
from ckan.common import request

ok_ = nose.tools.ok_
eq_ = nose.tools.eq_
raises = nose.tools.raises
assert_equals = nose.tools.assert_equals
assert_not_equal = nose.tools.assert_not_equal


class ActionBase(object):
Expand Down Expand Up @@ -37,3 +41,59 @@ def test_time_ago_from_datetime_valid(self):
def test_time_ago_from_datetime_valid_string_result(self):
d = datetime.today() - timedelta(days=2)
assert isinstance(h.time_ago_from_datetime(d), str)

def test_convert_id_to_emails_valid(self):
user = factories.User()
users = [{'name': user['name']}]
ids = user['id']
response = h.convert_id_to_email(ids)
email = '@ckan.org'
assert email in response

def test_convert_id_to_emails_invalid(self):
ids = '231'
response = h.convert_id_to_email(ids)
email = 'test_user_05@ckan.org'
assert_not_equal(email, response)

def test_convert_str_to_json_invalid(self):
str = "test: 123"
res = h.convert_str_to_json(str)
assert_equals("string cannot be parsed", res)

def test_convert_str_to_json_valid(self):
str = "{'test': 2}"
res = h.convert_str_to_json(json.dumps(str))
assert_not_equal(res, "string cannot be parsed")

def test_group_archived_requests_valid(self):
id2 = 2
id3 = 3
id55 = 55
requests = [{
'package_id': id55,
'title': 'test5',
'maintainers': 'm',
'requests_archived': 'r',
'shared': '',
'requests': 'r'
}, {
'package_id': id3,
'title': 'test3',
'maintainers': '',
'requests_archived': '',
'shared': '',
'requests': ''
}, {
'package_id': id2,
'title': 'test2',
'maintainers': 't',
'requests_archived': 'r',
'shared': 't',
'requests': 'r'
}]

res = h.group_archived_requests_by_dataset(requests)
assert_equals(res[0]['package_id'], id2)
assert_equals(res[1]['package_id'], id3)
assert_equals(res[2]['package_id'], id55)
13 changes: 12 additions & 1 deletion ckanext/requestdata/tests/test_validators.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,18 @@ def test_boolean_validator_is_not_instance(self):
else:
assert False

def test_boolean_validator_is_instance(self):
def test_boolean_validator_wrong_value(self):
key = 'state'
data = {'state': '3'}
errors = {key: []}
error_msg = "String is not true/false"
try:
boolean_validator(key, data, errors, None)
assert False
except ValueError as e:
assert error_msg in e.message

def test_boolean_validator_string_value(self):
key = ('state')
data = {('state'): 'Test'}
errors = {key: []}
Expand Down

0 comments on commit c06aeac

Please sign in to comment.