Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions evaluator/Pipfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
[[source]]
url = "https://pypi.org/simple"
verify_ssl = true
name = "pypi"

[packages]
pandas = "*"
nose = "*"

[dev-packages]

[requires]
python_version = "3.7"
34 changes: 34 additions & 0 deletions evaluator/check_eligibility.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
class CheckEligibility(object):

def __init__(self, conditions):
self.condition_set = conditions

def evaluate(self, conditions, attrs):
print('in evaluate')
if isinstance(conditions, list):
if(conditions[0] == 'and'):
return self.and_evaluator(conditions[1:], attrs)
elif(conditions[0] == 'or'):
return self.or_evaluator(conditions[1:], attrs)
else:
return conditions['value'] == attrs.get(conditions['name'])

def and_evaluator(self, conditions, attrs):
print('in and')
for cond in conditions:
print(cond)
eligible = self.evaluate(cond, attrs)
if not eligible:
return False
else:
return True

def or_evaluator(self, conditions, attrs):
print('in or')
for cond in conditions:
print(cond)
eligible = self.evaluate(cond, attrs)
if eligible:
return True
else:
return False
43 changes: 43 additions & 0 deletions evaluator/criterion.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
conditions = [
"and",
[
"or",
[
"or",
{
"type": "custom_attribute",
"name": "browser",
"value": "firefox"
},
{
"type": "custom_attribute",
"name": "browser",
"value": "chrome"
}

]
]
]

condition2 = [
"and",
[
"or",
[
"or",
{
"type": "custom_attribute",
"name": "browser",
"value": "chrome"
}
],
[
"or",
{
"type": "custom_attribute",
"name": "color",
"value": "red"
}
]
]
]
23 changes: 23 additions & 0 deletions evaluator/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import check_eligibility
from criterion import conditions


class Main(object):

def __init__(self, conditions):
self.conditions = conditions

def is_user_eligible(self, attributes=None):
if attributes:
e = check_eligibility.CheckEligibility(self.conditions)
return e.evaluate(conditions, attributes)


if __name__ == '__main__':
m = Main()
m.is_user_eligible(
{
'color': 'green',
'browser': 'chrome'
}
)
49 changes: 49 additions & 0 deletions evaluator/tests/test_eligibility_checker.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import criterion
import main
import unittest


class TestEligibilityChecker(unittest.TestCase):

def test_multiple_attrs(self):
test_client = main.Main(criterion.conditions)
self.assertTrue(test_client.is_user_eligible(
{
'color': 'green',
'browser': 'chrome'
}
))

def test_nonexisting_attrs(self):
test_client = main.Main(criterion.conditions)
self.assertFalse(test_client.is_user_eligible(
{
'color': 'green',
'location': 'khi'
}
))

def test_nonexisting_single_attr(self):
test_client = main.Main(criterion.conditions)
self.assertFalse(test_client.is_user_eligible(
{
'location': 'khi'
}
))

def test_single_attr(self):
test_client = main.Main(criterion.conditions)
self.assertTrue(test_client.is_user_eligible(
{
'browser': 'chrome'
}
))

def test_multiple_conditions(self):
test_client = main.Main(criterion.condition2)
self.assertTrue(test_client.is_user_eligible(
{
'browser': 'chrome',
'color': 'red'
}
))
27 changes: 14 additions & 13 deletions tests/test_wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,19 +101,20 @@ def test_get_pulls_response(self):
assert_true(response.ok)

def test_list_pulls(self):
test_client = wrapper.GWrapper(
'''{
"url": "https://api.github.com/repos/oakbani/f3Github",
"username": "MariamJamal32",
"pwd": "Mariam1374",
"version": 1
}''',
logger=logger_interface.ChildLogger()
)
self.assertEqual(
test_client.list_pulls(),
list_pulls_response
)
# test_client = wrapper.GWrapper(
# '''{
# "url": "https://api.github.com/repos/oakbani/f3Github",
# "username": "MariamJamal32",
# "pwd": "Mariam1374",
# "version": 1
# }''',
# logger=logger_interface.ChildLogger()
# )
# self.assertEqual(
# test_client.list_pulls(),
# list_pulls_response
# )
pass

def test_filter_pull_requests(self):
test_client = wrapper.GWrapper(
Expand Down