def test_delete_auth_token(c): token = AuthTokens.get() response = c.get(f'/auth_tokens_d/{token.id}', follow_redirects=True) assert response.status == '200 OK' assert AuthTokens.get(token.id) is None
def test_add_auth_tokens(c): token_name = 'testing token' token_description = 'testing description' response = c.post('/auth_tokens_a', data={ 'name': token_name, 'description': token_description }, follow_redirects=True) assert response.status == '200 OK' assert AuthTokens.get(name=token_name) is not None assert AuthTokens.get(description=token_description) is not None
def test_update_auth_tokens(c): token = AuthTokens.get() token_name = 'new testing name' token_description = 'new testing description' response = c.post(f'/auth_tokens_u/{token.id}', data={ 'name': token_name, 'description': token_description }, follow_redirects=True) assert response.status == '200 OK' assert AuthTokens.get(token.id).name == token_name assert AuthTokens.get(token.id).description == token_description
def test_get_wrong_ticket(c): auth_token = AuthTokens.get() response = c.get(f'{BASE}/9191919', follow_redirects=True, headers={'Authorization': auth_token.token}) assert response.status == '404 NOT FOUND'
def test_delete_all_tickets(c): auth_token = AuthTokens.get() response = c.delete(f'{BASE}', follow_redirects=True, headers={'Authorization': auth_token.token}) assert response.status == '204 NO CONTENT' assert response.data == b'' assert Serial.all_clean().count() == 0
def test_delete_ticket(c): ticket = Serial.all_clean().first() auth_token = AuthTokens.get() response = c.delete(f'{BASE}/{ticket.id}', follow_redirects=True, headers={'Authorization': auth_token.token}) assert response.status == '204 NO CONTENT' assert response.data == b'' assert Serial.get(ticket.id) is None
def test_get_ticket(c): ticket = Serial.all_clean().first() auth_token = AuthTokens.get() response = c.get(f'{BASE}/{ticket.id}', follow_redirects=True, headers={'Authorization': auth_token.token}) assert response.status == '200 OK' assert Serial.get(response.json.get('id')).id == ticket.id assert all(p in response.json for p in get_module_columns(Serial)) is True
def test_pull_ticket(c): auth_token = AuthTokens.get() response = c.get(f'{BASE}/pull', follow_redirects=True, headers={'Authorization': auth_token.token}) ticket = Serial.get(response.json.get('id')) assert response.status == '200 OK' assert ticket is not None assert ticket.p is True assert all(p in response.json for p in get_module_columns(Serial)) is True
def test_update_ticket(c): ticket = Serial.all_clean().first() new_name = 'new testing name' auth_token = AuthTokens.get() response = c.put(f'{BASE}/{ticket.id}', follow_redirects=True, headers={'Authorization': auth_token.token}, json={'name': new_name}) assert response.status == '200 OK' assert Serial.get(response.json.get('id')).name == new_name assert all(p in response.json for p in get_module_columns(Serial)) is True
def test_list_tickets(c): auth_token = AuthTokens.get() response = c.get(BASE, follow_redirects=True, headers={'Authorization': auth_token.token}) assert response.status == '200 OK' assert len(response.json) > 0 assert LIMIT_PER_CHUNK > len(response.json) for t in response.json: assert Task.get(t.get('id')) is not None assert all(p in t for p in get_module_columns(Task)) is True
def decorator(*args, **kwargs): token = request.headers.get(AUTH_HEADER_KEY) token_chunks = token.split(' ') if token else [] if len(token_chunks) > 1: token = token_chunks[1] self.auth_token = AuthTokens.get(token=token) if not self.auth_token: return abort(code=self.auth_http_code, message=self.auth_message) return function(*args, **kwargs)
def decorator(*args, **kwargs): token = request.headers.get(AUTH_HEADER_KEY) token_chunks = token.split(' ') if token else [] if len(token_chunks) > 1: token = token_chunks[1] auth_token = AuthTokens.get(token=token) if not auth_token: return abort(code=HTTPStatus.UNAUTHORIZED, message='Authentication is required') try: setattr(args[0], 'auth_token', auth_token) except Exception: pass return function(*args, **kwargs)
def test_generate_ticket(c): name = 'new testing name' task = Task.get() office = task.offices[0] auth_token = AuthTokens.get() response = c.post(f'{BASE}', follow_redirects=True, headers={'Authorization': auth_token.token}, json={ 'name': name, 'task_id': task.id, 'office_id': office.id }) ticket = Serial.get(response.json.get('id')) assert response.status == '200 OK' assert ticket is not None assert ticket.name == name assert ticket.task_id == task.id assert ticket.office_id == office.id assert all(p in response.json for p in get_module_columns(Serial)) is True
def fill_tokens(entry_number=ENTRY_NUMBER): for i in range(entry_number): db.session.add(AuthTokens(choice(NAMES))) db.session.commit()
def test_delete_all_auth_tokens(c): response = c.get('/auth_tokens_da', follow_redirects=True) assert response.status == '200 OK' assert AuthTokens.get() is None