Example #1
0
 def test_list_by_user(self, client, public_event, user1):
     client.force_login(user1)
     with pytest.raises(QueryException) as excinfo:
         run_query(client, EVENT_WITH_TICKETS_QUERY,
                   {'event_id': public_event.uuid})
     assert 'Forbidden' in excinfo.value.errors[0][
         'message']  # common users can't list tickets
Example #2
0
    def test_my_ok(self, client, public_event, user1):
        client.force_login(user1)

        run_query(client, REGISTER_MUTATION, {'event_id': public_event.uuid})

        res = run_query(client, EVENT_WITH_MY_TICKET_QUERY,
                        {'event_id': public_event.uuid})
        assert res['event']['my_ticket']['created']
Example #3
0
def test_update_by_staff(client, staff_user):
    client.force_login(staff_user)

    with pytest.raises(QueryException) as excinfo:
        run_query(client, UPDATE_SHIFT_MUTATION, {'is_night': True})

    assert (
        'Forbidden' in excinfo.value.errors[0]['message']
    )  # staff is not enough, should be manager
Example #4
0
def test_index(admin_client):
    run_query(
        admin_client, """
        {
            zadarmaPbxCalls(first: 10) {
                nodes {
                    pbx_call_id
                }
            }
        }
        """)
Example #5
0
    def test_good(self, client):
        token = get_magic_token('*****@*****.**')
        data = run_query(client, self.LOGIN_MUTATION, {'token': token})

        assert data['authLogin']['error'] is None
        assert data['authLogin']['registered'] is True
        assert data['authLogin']['user']['is_authenticated'] is True
        assert client.cookies['sessionid']
        assert client.cookies['csrftoken']

        data = run_query(client, """{ my { user { is_authenticated } } }""")
        assert data['my']['user']['is_authenticated'] is True
Example #6
0
    def test_my_delete(self, client, public_event, user1, admin_user):
        client.force_login(user1)

        # register...
        run_query(client, REGISTER_MUTATION, {'event_id': public_event.uuid})

        # ...and unregister
        run_query(client, UNREGISTER_MUTATION, {'event_id': public_event.uuid})

        client.force_login(admin_user)

        res = run_query(client, EVENT_WITH_TICKETS_QUERY,
                        {'event_id': public_event.uuid})
        assert res['event']['tickets'][0]['status'] == 'inactive'

        client.force_login(user1)

        res = client.post(
            f'/api/events/{public_event.uuid}/my_ticket/unregister')
        # double unregister is ok
        run_query(client, UNREGISTER_MUTATION, {'event_id': public_event.uuid})

        client.force_login(admin_user)

        res = run_query(client, EVENT_WITH_TICKETS_QUERY,
                        {'event_id': public_event.uuid})
        assert res['event']['tickets'][0]['status'] == 'inactive'
Example #7
0
def test_update_unknown_watchman(client, manager_user):
    client.force_login(manager_user)

    res = run_query(client, UPDATE_SHIFT_MUTATION, {'watchman_id': 123})

    assert res['watchmenUpdateShift']['__typename'] == 'GenericError'
    assert res['watchmenUpdateShift']['message'] == 'Watchman does not exist'
Example #8
0
    def test_create_ok(self, client, admin_user, public_event, user1):
        client.force_login(user1)
        res = run_query(client, REGISTER_MUTATION,
                        {'event_id': public_event.uuid})
        assert res['ticket']['created']

        with pytest.raises(QueryException) as excinfo:
            run_query(client, EVENT_WITH_TICKETS_QUERY,
                      {'event_id': public_event.uuid})
        assert 'Forbidden' in excinfo.value.errors[0][
            'message']  # still can't list tickets

        client.force_login(admin_user)
        res = run_query(client, EVENT_WITH_TICKETS_QUERY,
                        {'event_id': public_event.uuid})
        assert len(res['event']['tickets']) == 1
Example #9
0
    def test_create_double(self, client, public_event, user1):
        client.force_login(user1)

        for i in range(2):
            # double registration is ok (no errors)
            res = run_query(client, REGISTER_MUTATION,
                            {'event_id': public_event.uuid})
            assert res['ticket']['created']
Example #10
0
    def test_set_first_password(self, client):
        user = get_user_model().objects.create_user(self.EMAIL)
        client.force_login(user)

        res = run_query(
            client,
            self.SET_PASSWORD_MUTATION,
            {'new_password': self.NEW_PASSWORD},
        )
        assert res['result']['__typename'] == 'SetMyPasswordOkResult'
        user.check_password(self.NEW_PASSWORD)
Example #11
0
 def test_bad_password_wrong_user(self, client):
     res = run_query(
         client,
         self.LOGIN_MUTATION,
         {
             'email': self.EMAIL,
             'password': '******'
         },
     )
     assert res['authLogin']['error'] == "Некорректные учетные данные."
     assert not res['authLogin']['user']
Example #12
0
def test_nonempty_trainings(client, admin_user):
    client.force_login(admin_user)
    result = run_query(
        client,
        """
    mutation AppliedSolstice {
      result: createRatioTraining(input: {
        name: "Прикладное солнцестояние"
        slug: "solstice-training"
        date: "2020-12-21"
        telegram_link: "http://whatever.com"
      }) {
        __typename
      }
    }
 """,
    )
    assert result['result']['__typename'] == 'RatioTraining'

    run_query(client, "{ ratioTrainings(first: 10) { edges { node { id } } } }")
Example #13
0
def test_list(admin_client):
    res = run_query(
        admin_client,
        """
        {
            imageTemplatesAll {
                name
            }
        }
        """
    )
    assert type(res['imageTemplatesAll']) == list
Example #14
0
    def test_no_old_password(self, client):
        user = get_user_model().objects.create_user(self.EMAIL)
        user.set_password(self.PASSWORD)
        user.save()
        client.force_login(user)

        res = run_query(
            client,
            self.SET_PASSWORD_MUTATION,
            {'new_password': self.NEW_PASSWORD},
        )
        assert res['result']['__typename'] == 'ValidationError'
        assert res['result']['errors'][0]['messages'][0] == 'Пароль не указан.'
Example #15
0
def test_update_normal(client, manager_user):
    client.force_login(manager_user)
    member = Member.objects.create(
        user=manager_user,
        short_name='abc',
    )
    watchman = Watchman.objects.create(member=member)

    res = run_query(client, UPDATE_SHIFT_MUTATION, {'watchman_id': watchman.id})
    assert res['watchmenUpdateShift']['watchman']['id'] == str(watchman.id)

    shift = Shift.objects.get(date=date(2019, 3, 5), shift='MORNING')
    assert shift.watchman.member.short_name == 'abc'
Example #16
0
    def test_bad_password_existing_user(self, client):
        get_user_model().objects.create_user(self.EMAIL)

        res = run_query(
            client,
            self.LOGIN_MUTATION,
            {
                'email': self.EMAIL,
                'password': '******'
            },
        )
        assert res['authLogin']['error']
        assert not res['authLogin']['user']
Example #17
0
    def test_success(self, client):
        user = get_user_model().objects.create_user(self.EMAIL)
        user.set_password(self.PASSWORD)
        user.save()

        res = run_query(
            client,
            self.LOGIN_MUTATION,
            {
                'email': self.EMAIL,
                'password': self.PASSWORD
            },
        )
        assert res['authLogin']['registered'] is False
        assert client.cookies['sessionid']
Example #18
0
 def test_no_credentials(self, client):
     data = run_query(
         client,
         """
     mutation Login {
       authLogin(input: {
         credentials: {}
         result: "cookie"
       }) {
         error
       }
     }
     """,
     )
     assert data['authLogin']['error'].startswith("One of `token`")
Example #19
0
 def test_send(self, client):
     res = run_query(
         client,
         """
         mutation SendMagicLink {
             authSendMagicLink(input: {
                 email: "*****@*****.**"
             }) {
                 ok
             }
         }
         """,
     )
     assert res['authSendMagicLink']['ok']
     assert len(mail.outbox) == 1
     assert mail.outbox[0].subject == 'Войти на сайт Кочерги'
Example #20
0
def test_list_by_staff(client, staff_user):
    client.force_login(staff_user)

    res = run_query(
        client,
        """
        query {
            shifts: watchmenShifts(from_date: "2019-03-01", to_date: "2019-03-15") {
                date
                shift
            }
        }
        """,
    )

    assert res['shifts'][0]['date'] == '2019-03-01'
    assert res['shifts'][-1]['date'] == '2019-03-15'
Example #21
0
 def test_no_password(self, client):
     res = run_query(
         client,
         """
             mutation LoginWithoutPassword {
                 authLogin(input: {
                     credentials: {
                         email: "*****@*****.**"
                     }
                     result: "cookie"
                 }) {
                     error
                 }
             }
         """,
     )
     assert res['authLogin']['error'].startswith("One of `token`")
Example #22
0
    def test_logout(self, client, basic_user):
        client.force_login(basic_user)

        assert client.session.get('_auth_user_id')

        res = run_query(
            client,
            """
            mutation Logout {
                authLogout {
                    ok
                }
            }
            """,
        )

        assert res['authLogout']['ok']
        assert not client.session.get('_auth_user_id')
Example #23
0
 def test_result_param(self, client):
     token = get_magic_token('*****@*****.**')
     data = run_query(
         client,
         """
     mutation Login {
       authLogin(input: {
         credentials: {
           token: """ + '"' + token + '"' + """
         }
         result: "unknown"
       }) {
         error
       }
     }
     """,
     )
     assert data['authLogin'][
         'error'] == "Only `cookie` result is supported"
Example #24
0
def test_update_invalid(client, manager_user):
    client.force_login(manager_user)
    member = Member.objects.create(
        user=manager_user,
        short_name='abc',
    )
    watchman = Watchman.objects.create(member=member)

    res = run_query(
        client,
        UPDATE_SHIFT_MUTATION,
        {'watchman_id': watchman.id, 'is_night': True},
    )

    assert res['watchmenUpdateShift']['__typename'] == 'ValidationError'
    assert (
        "watchman can't be set when is_night is set"
        in res['watchmenUpdateShift']['errors'][0]['messages'][0]
    )
Example #25
0
 def test_create_anon(self, client, public_event):
     with pytest.raises(QueryException) as excinfo:
         run_query(client, REGISTER_MUTATION,
                   {'event_id': public_event.uuid})
     assert 'Forbidden' in excinfo.value.errors[0]['message']
Example #26
0
 def test_list_by_admin(self, admin_client, public_event):
     res = run_query(admin_client, EVENT_WITH_TICKETS_QUERY,
                     {'event_id': public_event.uuid})
     assert len(res['event']['tickets']) == 0
Example #27
0
 def test_anon(self, client, public_event):
     with pytest.raises(QueryException) as excinfo:
         run_query(client, EVENT_WITH_TICKETS_QUERY,
                   {'event_id': public_event.uuid})
     assert 'Forbidden' in excinfo.value.errors[0][
         'message']  # anon users can't list tickets
Example #28
0
def test_empty_trainings(client, admin_user):
    client.force_login(admin_user)
    run_query(client, "{ ratioTrainings(first: 10) { edges { node { id } } } }")
Example #29
0
 def test_my_404(self, client, public_event, user1):
     client.force_login(user1)
     res = run_query(client, EVENT_WITH_MY_TICKET_QUERY,
                     {'event_id': public_event.uuid})
     assert res['event']['my_ticket'] is None
Example #30
0
 def test_my_anon(self, client, public_event):
     res = run_query(client, EVENT_WITH_MY_TICKET_QUERY,
                     {'event_id': public_event.uuid})
     assert res['event']['my_ticket'] is None