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
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']
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
def test_index(admin_client): run_query( admin_client, """ { zadarmaPbxCalls(first: 10) { nodes { pbx_call_id } } } """)
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
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'
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'
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
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']
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)
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']
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 } } } }")
def test_list(admin_client): res = run_query( admin_client, """ { imageTemplatesAll { name } } """ ) assert type(res['imageTemplatesAll']) == list
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] == 'Пароль не указан.'
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'
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']
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']
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`")
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 == 'Войти на сайт Кочерги'
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'
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`")
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')
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"
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] )
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']
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
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
def test_empty_trainings(client, admin_user): client.force_login(admin_user) run_query(client, "{ ratioTrainings(first: 10) { edges { node { id } } } }")
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
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