PageRenderTime 77ms CodeModel.GetById 21ms RepoModel.GetById 0ms app.codeStats 0ms

/tests/test_request_pool.py

https://gitlab.com/gbozee/api-gateway-client
Python | 270 lines | 0 code | 55 blank | 215 comment | 0 complexity | 4b5e6c037a92fcb8abd75a61339786e1 MD5 | raw file
  1. # from . import unittest
  2. # from . import mock
  3. # import graphene
  4. # from gateway_client.request_pool import MatchingService
  5. # from gateway_client import TuteriaApiException, GraphQLClient
  6. # class TutorNode(graphene.ObjectType):
  7. # first_name = graphene.String()
  8. # last_name = graphene.String()
  9. # username = graphene.String()
  10. # def resolve_username(self, *args):
  11. # return self['username']
  12. # def resolve_first_name(self, *args):
  13. # return self['first_name']
  14. # def resolve_last_name(self, *args):
  15. # return self['last_name']
  16. # class SampleNode(graphene.ObjectType):
  17. # id = graphene.Int()
  18. # tutor = graphene.Field(TutorNode)
  19. # subjects = graphene.List(graphene.String)
  20. # cost = graphene.Float()
  21. # recommended = graphene.Boolean()
  22. # request_status = graphene.String()
  23. # default_subject = graphene.String()
  24. # approved = graphene.Boolean()
  25. # req_id = graphene.Int()
  26. # def resolve_id(self, *args):
  27. # return self['id']
  28. # def resolve_tutor(self, *args):
  29. # return self['tutor']
  30. # def resolve_subjects(self, *args):
  31. # return self['subjects']
  32. # def resolve_cost(self, *args):
  33. # return self['cost']
  34. # def resolve_recommended(self, *args):
  35. # return self['recommended']
  36. # def resolve_default_subject(self, *args):
  37. # return self['default_subject']
  38. # def resolve_approved(self, *args):
  39. # return self['approved']
  40. # def resolve_req_id(self, *args):
  41. # return self['req_id']
  42. # sample_record = [
  43. # {
  44. # 'id': 23,
  45. # 'tutor': {
  46. # 'first_name': "John",
  47. # 'last_name': "Doe",
  48. # 'username': 'johndoe'
  49. # },
  50. # "subjects": ['English', "Mathematics"],
  51. # "cost":20000,
  52. # "recommended":False,
  53. # "default_subject":"",
  54. # "approved":True
  55. # }]
  56. # class AddToPoolMutation(graphene.Mutation):
  57. # class Input:
  58. # tutor_slug = graphene.String()
  59. # cost = graphene.Float()
  60. # request_subjects = graphene.List(graphene.String)
  61. # notify_job = graphene.Boolean()
  62. # req_id = graphene.Int()
  63. # pool_instance = graphene.Field(SampleNode)
  64. # @staticmethod
  65. # def mutate(root, args, *extra):
  66. # instance = sample_record[0]
  67. # instance['cost'] = args['cost']
  68. # return AddToPoolMutation(pool_instance=instance)
  69. # class CreatePoolMutation(graphene.Mutation):
  70. # class Input:
  71. # tutor_slug = graphene.String()
  72. # approved = graphene.Boolean()
  73. # req_id = graphene.Int()
  74. # create = graphene.Boolean()
  75. # pool_instance = graphene.Field(SampleNode)
  76. # @staticmethod
  77. # def mutate(root, args, *extra):
  78. # instance = sample_record[0]
  79. # return CreatePoolMutation(pool_instance=instance)
  80. # class Mutation(graphene.ObjectType):
  81. # create_dummy_pool = CreatePoolMutation.Field()
  82. # add_tutor_to_pool = AddToPoolMutation.Field()
  83. # class Query(graphene.ObjectType):
  84. # pool_instance = graphene.Field(
  85. # SampleNode,
  86. # request_id=graphene.Int(required=True),
  87. # tutor_slug=graphene.String())
  88. # approved_tutors = graphene.List(
  89. # SampleNode,
  90. # request_id=graphene.Int(required=True))
  91. # approved_tutors_teach_all_subjects = graphene.List(
  92. # SampleNode,
  93. # request_id=graphene.Int(required=True))
  94. # def resolve_pool_instance(self, args, *extra):
  95. # return sample_record[0]
  96. # def resolve_approved_tutors(self, args, context, info):
  97. # new_result = []
  98. # for o in sample_record:
  99. # o.update(req_id=args['request_id'])
  100. # new_result.append(o)
  101. # return new_result
  102. # def resolve_approved_tutors_teach_all_subjects(self, args, *remaining):
  103. # new_result = []
  104. # for o in sample_record:
  105. # o.update(req_id=args['request_id'])
  106. # new_result.append(o)
  107. # return new_result
  108. # class BaseTestCase(object):
  109. # def setUp(self):
  110. # self.fields = """
  111. # id
  112. # tutor{
  113. # first_name
  114. # last_name
  115. # }
  116. # req_id
  117. # """
  118. # self.query_string = lambda x=32: """
  119. # {
  120. # approved_tutors(request_id:%s){
  121. # %s
  122. # }
  123. # }
  124. # """ % (x, self.fields)
  125. # def test_service_can_receive_a_schema_object(self):
  126. # self.assertEqual(self.service.client, self.schema)
  127. # def test_service_throws_error_when_no_url_is_passed(self):
  128. # with self.assertRaises(TuteriaApiException):
  129. # service = MatchingService()
  130. # def test_actual_service_call_returns_valid_result_on_approve_tutors(self):
  131. # pool_instance = self.service.init_instance(28)
  132. # self.service.fields = self.fields
  133. # result = self.service.approved_tutors()
  134. # self.assertEqual(self.service.fields, self.fields)
  135. # self.assertEqual(result[0]['req_id'], 28)
  136. # def test_approved_tutors_teach_all_subjects(self):
  137. # pool_instance = self.service.init_instance(28)
  138. # self.service.fields = self.fields
  139. # result = self.service.approved_tutors_teach_all_subjects()
  140. # self.assertEqual(self.service.fields, self.fields)
  141. # self.assertEqual(result[0]['req_id'], 28)
  142. # def test_creation_of_dummy_data(self):
  143. # self.service.init_instance(28)
  144. # self.service.fields = self.fields
  145. # result = self.service.create_dummy_pool(tutor_slug="dandolo",
  146. # approved=True)
  147. # self.assertEqual(result['pk'], 23)
  148. # self.assertEqual(result['tutor_slug'], "johndoe")
  149. # def test_fetching_of_request_pool_containing_tutor(self):
  150. # self.service.init_instance(28)
  151. # self.service.fields = self.fields
  152. # result = self.service.get_tutor_for_request("johndoe")
  153. # self.assertEqual(result['pk'], 23)
  154. # self.assertEqual(result['tutor_slug'], "johndoe")
  155. # def test_create_and_add_tutor_to_pool(self):
  156. # self.service.init_instance(28)
  157. # self.service.fields = self.fields
  158. # result = self.service.create_and_add_tutor_to_pool(
  159. # request_subjects=["English Language"],
  160. # tutor_slug="johndoe",
  161. # cost=7000
  162. # )
  163. # self.assertEqual(result['id'], 23)
  164. # self.assertEqual(result['tutor']['username'], 'johndoe')
  165. # self.assertEqual(result['cost'], 7000)
  166. # class LocalMatchingServiceTestCase(BaseTestCase, unittest.TestCase):
  167. # def setUp(self):
  168. # super().setUp()
  169. # self.schema = graphene.Schema(
  170. # query=Query, mutation=Mutation, auto_camelcase=False)
  171. # self.service = MatchingService(self.schema)
  172. # def test_above_schema_works_well(self):
  173. # result = self.schema.execute(self.query_string())
  174. # self.assertIsNone(result.errors)
  175. # class RemoteMatchingServiceTestCase(BaseTestCase, unittest.TestCase):
  176. # def setUp(self):
  177. # super().setUp()
  178. # self.patcher = mock.patch.object(GraphQLClient, "execute")
  179. # self.mocker = self.patcher.start()
  180. # ss = sample_record[0].copy()
  181. # ss.update(req_id=28)
  182. # so = ss.copy()
  183. # so.update(cost=7000)
  184. # self.mocker.return_value = {
  185. # 'data': {
  186. # 'approved_tutors': [ss],
  187. # 'approved_tutors_teach_all_subjects': [ss],
  188. # 'create_dummy_pool': {
  189. # 'pool_instance': ss
  190. # },
  191. # 'add_tutor_to_pool': {
  192. # 'pool_instance': so
  193. # },
  194. # 'pool_instance': ss
  195. # }
  196. # }
  197. # self.service = MatchingService("http://localhost:5000")
  198. # self.schema = self.service.client
  199. # def tearDown(self):
  200. # self.patcher.stop()
  201. # def test_instance_of_client_is_of_GraphQLClient(self):
  202. # self.assertIsInstance(self.service.client, GraphQLClient)
  203. # self.assertFalse(self.service.change)
  204. # def test_creation_of_dummy_data(self):
  205. # super().test_creation_of_dummy_data()
  206. # self.mocker.assert_called_once_with(self.service.query, dict(tutor_slug="dandolo",
  207. # approved=True, req_id=28), "createDummyPool")
  208. # def test_create_and_add_tutor_to_pool(self):
  209. # super().test_create_and_add_tutor_to_pool()
  210. # def test_fetching_of_request_pool_containing_tutor(self):
  211. # super().test_fetching_of_request_pool_containing_tutor()
  212. # self.mocker.assert_called_once_with(self.service.query, {
  213. # 'request_id': 28,
  214. # 'tutor_slug': 'johndoe'
  215. # }, "SingleRequestPool")