How to use view_item method in locust

Best Python code snippet using locust

views_endpoint.py

Source:views_endpoint.py Github

copy

Full Screen

1from .endpoint import Endpoint, api2from .exceptions import MissingRequiredFieldError3from .resource_tagger import _ResourceTagger4from .permissions_endpoint import _PermissionsEndpoint5from .. import ViewItem, PaginationItem6from contextlib import closing7import logging8logger = logging.getLogger('tableau.endpoint.views')9class Views(Endpoint):10 def __init__(self, parent_srv):11 super(Views, self).__init__(parent_srv)12 self._resource_tagger = _ResourceTagger(parent_srv)13 self._permissions = _PermissionsEndpoint(parent_srv, lambda: self.baseurl)14 # Used because populate_preview_image functionaliy requires workbook endpoint15 @property16 def siteurl(self):17 return "{0}/sites/{1}".format(self.parent_srv.baseurl, self.parent_srv.site_id)18 @property19 def baseurl(self):20 return "{0}/views".format(self.siteurl)21 @api(version="2.2")22 def get(self, req_options=None, usage=False):23 logger.info('Querying all views on site')24 url = self.baseurl25 if usage:26 url += "?includeUsageStatistics=true"27 server_response = self.get_request(url, req_options)28 pagination_item = PaginationItem.from_response(server_response.content, self.parent_srv.namespace)29 all_view_items = ViewItem.from_response(server_response.content, self.parent_srv.namespace)30 return all_view_items, pagination_item31 @api(version="2.0")32 def populate_preview_image(self, view_item):33 if not view_item.id or not view_item.workbook_id:34 error = "View item missing ID or workbook ID."35 raise MissingRequiredFieldError(error)36 def image_fetcher():37 return self._get_preview_for_view(view_item)38 view_item._set_preview_image(image_fetcher)39 logger.info('Populated preview image for view (ID: {0})'.format(view_item.id))40 def _get_preview_for_view(self, view_item):41 url = "{0}/workbooks/{1}/views/{2}/previewImage".format(self.siteurl,42 view_item.workbook_id,43 view_item.id)44 server_response = self.get_request(url)45 image = server_response.content46 return image47 @api(version="2.5")48 def populate_image(self, view_item, req_options=None):49 if not view_item.id:50 error = "View item missing ID."51 raise MissingRequiredFieldError(error)52 def image_fetcher():53 return self._get_view_image(view_item, req_options)54 view_item._set_image(image_fetcher)55 logger.info("Populated image for view (ID: {0})".format(view_item.id))56 def _get_view_image(self, view_item, req_options):57 url = "{0}/{1}/image".format(self.baseurl, view_item.id)58 server_response = self.get_request(url, req_options)59 image = server_response.content60 return image61 @api(version="2.7")62 def populate_pdf(self, view_item, req_options=None):63 if not view_item.id:64 error = "View item missing ID."65 raise MissingRequiredFieldError(error)66 def pdf_fetcher():67 return self._get_view_pdf(view_item, req_options)68 view_item._set_pdf(pdf_fetcher)69 logger.info("Populated pdf for view (ID: {0})".format(view_item.id))70 def _get_view_pdf(self, view_item, req_options):71 url = "{0}/{1}/pdf".format(self.baseurl, view_item.id)72 server_response = self.get_request(url, req_options)73 pdf = server_response.content74 return pdf75 @api(version="2.7")76 def populate_csv(self, view_item, req_options=None):77 if not view_item.id:78 error = "View item missing ID."79 raise MissingRequiredFieldError(error)80 def csv_fetcher():81 return self._get_view_csv(view_item, req_options)82 view_item._set_csv(csv_fetcher)83 logger.info("Populated csv for view (ID: {0})".format(view_item.id))84 def _get_view_csv(self, view_item, req_options):85 url = "{0}/{1}/data".format(self.baseurl, view_item.id)86 with closing(self.get_request(url, request_object=req_options, parameters={"stream": True})) as server_response:87 csv = server_response.iter_content(1024)88 return csv89 @api(version='3.2')90 def populate_permissions(self, item):91 self._permissions.populate(item)92 @api(version='3.2')93 def update_permissions(self, resource, rules):94 return self._permissions.update(resource, rules)95 @api(version='3.2')96 def delete_permission(self, item, capability_item):97 return self._permissions.delete(item, capability_item)98 # Update view. Currently only tags can be updated99 def update(self, view_item):100 if not view_item.id:101 error = "View item missing ID. View must be retrieved from server first."102 raise MissingRequiredFieldError(error)103 self._resource_tagger.update_tags(self.baseurl, view_item)104 # Returning view item to stay consistent with datasource/view update functions...

Full Screen

Full Screen

test_model.py

Source:test_model.py Github

copy

Full Screen

1from uuid import uuid42import pytest3from mock import patch4from app.mixins.view.enums import ViewedStatus, ViewType5from app.models.post.enums import PostType6@pytest.fixture7def user(user_manager, cognito_client):8 user_id, username = str(uuid4()), str(uuid4())[:8]9 cognito_client.create_user_pool_entry(user_id, username, verified_email=f'{username}@real.app')10 yield user_manager.create_cognito_only_user(user_id, username)11user2 = user12user3 = user13@pytest.fixture14def post(post_manager, user):15 yield post_manager.add_post(user, str(uuid4()), PostType.TEXT_ONLY, text='t')16@pytest.fixture17def chat(chat_manager, user, user2):18 with patch.object(chat_manager, 'validate_dating_match_chat', return_value=True):19 yield chat_manager.add_direct_chat(str(uuid4()), user.id, user2.id)20@pytest.fixture21def screen(screen_manager):22 yield screen_manager.init_screen(f'screen-name-{uuid4()}')23@pytest.mark.parametrize('model', pytest.lazy_fixture(['post', 'chat'])) # screens have no owner24def test_owner_cant_record_views_has_always_alread_viewed(model, user2):25 # check owner has always viewed it26 assert model.get_viewed_status(model.user_id) == ViewedStatus.VIEWED27 model.record_view_count(model.user_id, 5)28 assert model.get_viewed_status(model.user_id) == ViewedStatus.VIEWED29@pytest.mark.parametrize('model', pytest.lazy_fixture(['post', 'chat', 'screen']))30def test_record_and_get_views(model, user2, user3):31 # check users have not viewed it32 assert model.get_viewed_status(user2.id) == ViewedStatus.NOT_VIEWED33 assert model.get_viewed_status(user3.id) == ViewedStatus.NOT_VIEWED34 # record some views by the rando, check recorded to dynamo35 model.record_view_count(user2.id, 5)36 assert model.get_viewed_status(user2.id) == ViewedStatus.VIEWED37 view_item = model.view_dynamo.get_view(model.id, user2.id)38 assert view_item['viewCount'] == 539 assert user2.id in view_item['sortKey']40 assert view_item['firstViewedAt']41 assert view_item['firstViewedAt'] == view_item['lastViewedAt']42 first_viewed_at = view_item['firstViewedAt']43 # record some more views by the rando, check recorded to dynamo44 model.record_view_count(user2.id, 3)45 assert model.get_viewed_status(user2.id) == ViewedStatus.VIEWED46 view_item = model.view_dynamo.get_view(model.id, user2.id)47 assert view_item['viewCount'] == 848 assert view_item['firstViewedAt'] == first_viewed_at49 assert view_item['lastViewedAt'] > first_viewed_at50 # record views by the other user too, check their viewed status also changed51 model.record_view_count(user3.id, 3)52 assert model.get_viewed_status(user3.id) == ViewedStatus.VIEWED53 assert model.view_dynamo.get_view(model.id, user3.id)54def test_record_view_count_with_view_type(post, user2, user3):55 # check starting state56 assert post.get_viewed_status(user2.id) == ViewedStatus.NOT_VIEWED57 assert post.get_viewed_status(user3.id) == ViewedStatus.NOT_VIEWED58 assert post.view_dynamo.get_view(post.id, user2.id) is None59 assert post.view_dynamo.get_view(post.id, user3.id) is None60 # record views with focus view type, verify61 post.record_view_count(user3.id, 3, None, ViewType.FOCUS)62 assert post.get_viewed_status(user3.id) == ViewedStatus.VIEWED63 view_item = post.view_dynamo.get_view(post.id, user3.id)64 assert view_item['viewCount'] == 365 assert view_item['focusViewCount'] == 366 assert view_item.get('thumbnailViewCount', 0) == 067 # record views with thumbnail view type, verify68 post.record_view_count(user2.id, 3, None, ViewType.THUMBNAIL)69 assert post.get_viewed_status(user2.id) == ViewedStatus.VIEWED70 view_item = post.view_dynamo.get_view(post.id, user2.id)71 assert view_item['viewCount'] == 372 assert view_item['thumbnailViewCount'] == 3...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run locust automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful