Пример #1
0
    def setUp(self):
        self.op_name = 'saveApproval'
        self.query_under_test = \
            f'''
                mutation {self.op_name}($approvalInput: ApprovalInput!) {{
                  {self.op_name}(approvalInput: $approvalInput) {{
                    approval {{
                      id
                      state
                      task {{
                        id
                      }}
                      user {{
                        id
                      }}
                    }}
                  }}
                }}
            '''

        self.current_user_credentials = {
            'email': '*****@*****.**',
            'password': '******'
        }
        self.current_user = self.current_user = create_user(
            group=create_group(),
            **self.current_user_credentials)

        self.login(self.current_user_credentials.get('email'),
                   self.current_user_credentials.get('password'))
Пример #2
0
    def setUp(self):
        self.op_name = 'updateGroceries'
        self.query_under_test = \
            f'''
            mutation {self.op_name}($input: [GroceryUpdateInput!]!) {{
                {self.op_name}(input: $input) {{
                    groceries {{
                        id
                        name
                        info
                        inCart
                    }}
                }}
            }}            '''

        self.current_user_credentials = {
            'email': '*****@*****.**',
            'password': '******'
        }
        self.current_user = self.current_user = create_user(
            group=create_group(), **self.current_user_credentials)

        self.existing_grocery = create_grocery(group=self.current_user.group)

        self.login(self.current_user_credentials.get('email'),
                   self.current_user_credentials.get('password'))
Пример #3
0
    def test_should_return_expected_users(self):
        incorrect_group = create_group()
        correct_user_1 = create_user(group=self.current_user.group)
        correct_user_2 = create_user(group=self.current_user.group)
        correct_user_3 = create_user(group=self.current_user.group)
        incorrect_user_1 = create_user(group=incorrect_group)
        incorrect_user_2 = create_user(group=incorrect_group)
        incorrect_user_3 = create_user(group=incorrect_group)

        response = self.gql(self.query_under_test,
                            op_name=self.op_name,
                            variables={'id': str(self.current_user.id)})

        self.assertResponseNoErrors(response)

        users: dict = json.loads(response.content).get('data').get(
            self.op_name)

        self.assertIsNotNone(users)
        self.assertEquals(4, len(users))
        self.assertCountEqual([
            int(users[0].get('id')),
            int(users[1].get('id')),
            int(users[2].get('id')),
            int(users[3].get('id')),
        ], [
            self.current_user.id,
            correct_user_1.id,
            correct_user_2.id,
            correct_user_3.id,
        ])
Пример #4
0
    def setUp(self):
        self.op_name = 'allNotInCart'
        self.query_under_test = \
            f'''
            query {self.op_name} {{
              {self.op_name} {{
                id
                name
                inCart
                info
              }}
            }}
            '''

        self.current_user_credentials = {
            'email': '*****@*****.**',
            'password': '******'
        }
        self.current_user = create_user(group=create_group(),
                                        **self.current_user_credentials)

        self.login(self.current_user_credentials.get('email'),
                   self.current_user_credentials.get('password'))
Пример #5
0
    def setUp(self):
        self.op_name = 'users'
        self.query_under_test = \
            f'''
            query {self.op_name} {{
              {self.op_name} {{
                id
                email
                publicName
                credits
              }}
            }}
            '''

        self.current_user_credentials = {
            'email': '*****@*****.**',
            'password': '******'
        }
        self.current_user = create_user(group=create_group(),
                                        **self.current_user_credentials)

        self.login(self.current_user_credentials.get('email'),
                   self.current_user_credentials.get('password'))
Пример #6
0
    def test_should_return_expected_users(self):
        incorrect_group = create_group()
        correct_user_1 = create_user(group=self.current_user.group)
        correct_user_2 = create_user(group=self.current_user.group)
        correct_user_3 = create_user(group=self.current_user.group)
        incorrect_user_1 = create_user(group=incorrect_group)
        incorrect_user_2 = create_user(group=incorrect_group)
        incorrect_user_3 = create_user(group=incorrect_group)

        response = self.gql(self.query_under_test,
                            op_name=self.op_name,
                            variables={'userEmail': self.current_user.email})

        self.assertResponseNoErrors(response)

        users: dict = json.loads(response.content).get('data').get(
            self.op_name)

        self.assertIsNotNone(users)
        self.assertEquals(3, len(users))

        self.assertCountEqual(
            [correct_user_1.id, correct_user_2.id, correct_user_3.id],
            list(map(lambda u: int(u.get('id')), users)))
Пример #7
0
    def test_should_return_expected_results(self):
        group_1 = create_group()

        # ok
        grocery_1 = create_grocery(
            group=self.current_user.group,
            in_cart=False,
        )

        # wrong group
        grocery_2 = create_grocery(
            group=group_1,
            in_cart=False,
        )

        # ok
        grocery_3 = create_grocery(
            group=self.current_user.group,
            in_cart=False,
        )

        # wrong in_cart
        grocery_4 = create_grocery(
            group=group_1,
            in_cart=True,
        )

        # ok
        grocery_5 = create_grocery(
            group=self.current_user.group,
            in_cart=False,
        )

        # wrong group
        grocery_6 = create_grocery(
            group=group_1,
            in_cart=False,
        )

        # ok
        grocery_7 = create_grocery(
            group=self.current_user.group,
            in_cart=False,
        )

        # wrong in_cart
        grocery_8 = create_grocery(
            group=group_1,
            in_cart=True,
        )

        response = self.gql(self.query_under_test, op_name=self.op_name)

        self.assertResponseNoErrors(response)

        groceries: dict = json.loads(response.content).get('data').get(
            self.op_name)

        self.assertIsNotNone(groceries)
        self.assertEquals(4, len(groceries))
        self.assertCountEqual(list(map(lambda g: int(g.get('id')), groceries)),
                              [
                                  grocery_1.id,
                                  grocery_3.id,
                                  grocery_5.id,
                                  grocery_7.id,
                              ])
Пример #8
0
    def test_should_update_and_return_approval(self, notify_task_mock_1, notify_task_mock_2):
        with self.subTest('should update approval, but not task'):
            group = create_group()
            user_0 = create_user(group=group)
            user_1 = create_user(group=group)
            user_2 = create_user(group=group)
            user_3 = create_user(group=group)
            task = create_task(group=group,
                               state=TaskState.TO_APPROVE, user=user_1)
            approval_0 = create_approval(user=user_0,
                                         state=ApprovalState.NONE, task=task)
            approval_1 = create_approval(user=user_1, state=ApprovalState.NONE,
                                         task=task)
            approval_2 = create_approval(user=user_2, state=ApprovalState.NONE,
                                         task=task)
            approval_3 = create_approval(user=user_3, state=ApprovalState.NONE,
                                         task=task)

            response = self.gql(self.query_under_test,
                                op_name=self.op_name,
                                variables={
                                    'approvalInput': dict(id=approval_0.id,
                                                          state=str(
                                                              ApprovalState.APPROVED))})

            self.assertResponseNoErrors(response)

            approval: dict = json.loads(response.content).get(
                'data').get(self.op_name).get('approval')

            self.assertIsNotNone(approval)
            self.assertEqual(approval.get('state'), str(
                ApprovalState.APPROVED))

            task.refresh_from_db()
            self.assertEqual(task.state, TaskState.TO_APPROVE)

        with self.subTest('should update approval and set task state to '
                          'DECLINED and not update the user\'s credits'):
            group = create_group()
            user_0 = create_user(group=group, credits=200)
            user_1 = create_user(group=group)
            user_2 = create_user(group=group)
            user_3 = create_user(group=group)
            task = create_task(group=group,
                               credits_calc=CreditsCalc.FIXED,
                               fixed_credits=500,
                               state=TaskState.TO_APPROVE, user=user_1)
            approval_0 = create_approval(user=user_0,
                                         state=ApprovalState.NONE, task=task)
            approval_1 = create_approval(user=user_1,
                                         state=ApprovalState.APPROVED,
                                         task=task)
            approval_2 = create_approval(user=user_2,
                                         state=ApprovalState.APPROVED,
                                         task=task)
            approval_3 = create_approval(user=user_3,
                                         state=ApprovalState.APPROVED,
                                         task=task)

            response = self.gql(self.query_under_test,
                                op_name=self.op_name,
                                variables={
                                    'approvalInput': dict(id=approval_0.id,
                                                          state=str(
                                                              ApprovalState.DECLINED),
                                                          message='Something wrong')})

            self.assertResponseNoErrors(response)

            approval: dict = json.loads(response.content).get(
                'data').get(self.op_name).get('approval')

            self.assertIsNotNone(approval)
            self.assertEqual(approval.get('state'), str(
                ApprovalState.DECLINED))

            task.refresh_from_db()
            self.assertEqual(task.state, TaskState.DECLINED)

            user_0.refresh_from_db()
            self.assertEqual(user_0.credits, 200)