def test_create_booking(requests_mock, device, user, event):

    mock_responses = (('POST', 'https://' + TEST_API_DOMAIN + '/v4/bookings',
                       'mock_responses/ls_api/create_booking.json', 200), )
    configure_mock_responses(requests_mock, mock_responses, FIXTURES_DIR,
                             CONTENT_TYPE)

    resource_client = LiveStyledResourceClient(TEST_API_DOMAIN, 'bar')
    resource_client.create_booking(
        Booking.create_new(type='manual',
                           device=device,
                           user=user,
                           event=event,
                           action='going'))

    assert len(requests_mock.request_history) == 1
    assert requests_mock.request_history[0].method == 'POST'
    assert requests_mock.request_history[
        0].url == 'https://' + TEST_API_DOMAIN + '/v4/bookings'
    assert json.loads(requests_mock.request_history[0].body) == {
        'action': 'going',
        'event': '/v4/events/8888',
        'device': '/v4/devices/1234',
        'type': 'manual',
        'user': '******'
    }
def test_create_news(requests_mock):
    mock_responses = (
        ('POST', 'https://' + TEST_API_DOMAIN + '/v4/news', 'mock_responses/ls_api/news_1234.json', 200),
    )
    configure_mock_responses(requests_mock, mock_responses, FIXTURES_DIR, CONTENT_TYPE)

    resource_client = LiveStyledResourceClient(TEST_API_DOMAIN, 'bar')
    resource_client.create_news(
        News.create_new(
            external_id='test',
            title='This is a test article',
            headline='Test headline',
            media=None,
            author='Tester',
            url='https://news.com/1',
            image_url='https://images.news.com/1',
            published_at=datetime(2020, 10, 1, 9, 30, 0),
            updated_at=datetime(2020, 10, 1, 9, 30, 0)
        )
    )
    assert requests_mock.request_history[0].method == 'POST'
    assert requests_mock.request_history[0].url == 'https://' + TEST_API_DOMAIN + '/v4/news'
    assert json.loads(requests_mock.request_history[0].body) == {
        'author': 'Tester',
        'externalId': 'test',
        'headline': 'Test headline',
        'imageUrl': 'https://images.news.com/1',
        'publishedAt': '2020-10-01T09:30:00',
        'title': 'This is a test article',
        'url': 'https://news.com/1'
    }
Пример #3
0
def test_create_device_reality(requests_mock):
    mock_responses = (
        ('POST',
         'https://' + TEST_API_DOMAIN + '/v4/user_management/device_realities',
         'mock_responses/ls_api/user_management/new_device_reality.json',
         200), )
    configure_mock_responses(requests_mock, mock_responses, FIXTURES_DIR,
                             CONTENT_TYPE)

    resource_client = LiveStyledResourceClient(TEST_API_DOMAIN, 'bar')
    device_reality = DeviceReality.create_new(
        device=Device.placeholder(id=1),
        reality=Reality.placeholder(id=9),
        value='is this the real reality')
    resource_client.create_device_reality(device_reality)

    assert len(requests_mock.request_history) == 1
    assert requests_mock.request_history[0].method == 'POST'
    assert requests_mock.request_history[
        0].url == 'https://test.livestyled.com/v4/user_management/device_realities'
    assert json.loads(requests_mock.request_history[0].body) == {
        'value': 'is this the real reality',
        'device': '/user_management/devices/1',
        'reality': '/user_management/realities/9'
    }
Пример #4
0
def test_get_products(requests_mock):
    mock_responses = (('GET',
                       'https://' + TEST_API_DOMAIN + '/v4/sell/products',
                       'mock_responses/ls_api/products.json', 200), )
    configure_mock_responses(requests_mock, mock_responses, FIXTURES_DIR,
                             CONTENT_TYPE)

    resource_client = LiveStyledResourceClient(TEST_API_DOMAIN, 'bar')
    products = list(resource_client.get_products())
    assert len(products) == 30
    products.sort(key=lambda o: o.id)
    product = products[2]

    assert isinstance(product, Product)
    assert product.id == 3
    assert product.status == 'ACTIVE'
    assert product.reference == "Men's Tank"
    assert len(product.images) == 1
    assert isinstance(product.images[0], dict)
    assert product.images[0] == {
        'external_id': '6N6H3B3IZVGBK3OMFOCFNGE2',
        'image_url':
        'https://apiv3.s3.eu-west-1.amazonaws.com/productimage/original-2.jpeg',
        'position': 1
    }
    assert len(product.translations) == 1
    assert product.translations[0]['title'] == "Men's Tank"
    assert product.translations[0]['description'] is None
    assert product.translations[0]['language'] == 'en'
Пример #5
0
def test_user_diff(requests_mock):
    mock_responses = (('GET', 'https://' + TEST_API_DOMAIN +
                       '/v4/user_management/users/1234',
                       'mock_responses/ls_api/user_1234.json', 200), )
    configure_mock_responses(requests_mock, mock_responses, FIXTURES_DIR,
                             CONTENT_TYPE)

    resource_client = LiveStyledResourceClient(TEST_API_DOMAIN, 'bar')
    user1 = resource_client.get_user(1234)
    user2 = resource_client.get_user(1234)

    user2.user_info.first_name = 'Bobby'

    differences = user2.diff(user1)
    assert differences
    assert 'user_info' in differences

    serialised_differences = UserSchema(only=['user_info']).dump(differences)
    assert serialised_differences
    assert serialised_differences == {
        'userInfo': {
            'id': 37,
            'dob': '1992-12-06T00:00:00+00:00',
            'firstName': 'Bobby',
            'gender': 'MALE',
            'lastName': 'Bobberson',
            'phone': None
        }
    }
def test_update_team(requests_mock):
    team = Team(
        id=1,
        external_id='testteam1',
        name='Test Team',
        short_name='TT',
        light_crest_url='http://www.images.com/image1.jpg',
        dark_crest_url='http://www.images.com/image2.jpg',
    )

    resource_client = LiveStyledResourceClient(TEST_API_DOMAIN, 'bar')
    mock_responses = (
        ('PATCH', 'https://' + TEST_API_DOMAIN + '/v4/teams/1', 'mock_responses/ls_api/updated_team.json', 200),
    )
    configure_mock_responses(requests_mock, mock_responses, FIXTURES_DIR, CONTENT_TYPE)

    updated_team = resource_client.update_team(team, {'name': 'New Name'})

    for request in requests_mock.request_history:
        if request.method.upper() == 'PATCH' and request.url == 'https://' + TEST_API_DOMAIN + '/v4/teams/1':
            actual_payload = request.json()

            assert actual_payload == {
                'name': 'New Name'
            }

    assert updated_team.name == 'New Name'
    assert updated_team.id == 1
    assert updated_team.external_id == 'testteam1'
    assert updated_team.short_name == 'TT'
    assert updated_team.light_crest_url == 'http://www.images.com/image1.jpg'
    assert updated_team.dark_crest_url == 'http://www.images.com/image2.jpg'
def test_create_team(requests_mock):
    team = Team.create_new(
        external_id='testteam1',
        name='Test Team',
        short_name='TT',
        light_crest_url='http://www.images.com/image1.jpg',
        dark_crest_url='http://www.images.com/image2.jpg'
    )
    mock_responses = (
        ('POST', 'https://' + TEST_API_DOMAIN + '/v4/teams', 'mock_responses/ls_api/create_team.json', 200),
    )
    configure_mock_responses(requests_mock, mock_responses, FIXTURES_DIR, CONTENT_TYPE)

    resource_client = LiveStyledResourceClient(TEST_API_DOMAIN, 'bar')
    created_team = resource_client.create_team(team)
    assert created_team
    assert created_team.id == 999

    for request in requests_mock.request_history:
        if request.method.upper() == 'POST' and request.url == 'https://' + TEST_API_DOMAIN + '/v4/teams':
            actual_payload = request.json()

            assert actual_payload == {
                'name': 'Test Team',
                'shortName': 'TT',
                'lightCrestUrl': 'http://www.images.com/image1.jpg',
                'darkCrestUrl': 'http://www.images.com/image2.jpg',
                'externalId': 'testteam1'
            }
Пример #8
0
def test_get_ticket_auths_filtering(requests_mock):
    mock_responses = ((
        'GET', 'https://' + TEST_API_DOMAIN +
        '/v4/ticket_auths?userEmail.email=amy.keane%2Bverificatintest%40livestyled.com',
        'mock_responses/ls_api/ticket_auth_list_filtered.json', 200), )
    configure_mock_responses(requests_mock, mock_responses, FIXTURES_DIR,
                             CONTENT_TYPE)

    resource_client = LiveStyledResourceClient(TEST_API_DOMAIN, 'bar')
    ticket_auths = list(
        resource_client.get_ticket_auths(
            user_email_address='*****@*****.**'))
    assert ticket_auths
    assert isinstance(ticket_auths[0], TicketAuth)
    assert ticket_auths[0].id == 1038
    assert isinstance(ticket_auths[0].user_email, UserEmail)
    assert ticket_auths[0].user_email.id == 330325
    assert ticket_auths[0].user_email.valid is True
    assert ticket_auths[
        0].user_email.email == '*****@*****.**'
    assert isinstance(ticket_auths[0].ticket_integration, TicketIntegration)
    assert ticket_auths[0].ticket_integration.id == 40
    assert ticket_auths[
        0].client_email == '*****@*****.**'
    assert ticket_auths[0].client_id == '129494829'
def test_get_events(requests_mock):
    mock_responses = (
        ('GET', 'https://' + TEST_API_DOMAIN + '/v4/events', 'mock_responses/ls_api/events_page1.json', 200),
        ('GET', 'https://' + TEST_API_DOMAIN + '/v4/events?page=2', 'mock_responses/ls_api/events_page2.json', 200),
    )
    configure_mock_responses(requests_mock, mock_responses, FIXTURES_DIR, CONTENT_TYPE)

    resource_client = LiveStyledResourceClient(TEST_API_DOMAIN, 'bar')
    events = list(resource_client.get_events())
    assert events
    assert len(events) == 31
    event = events[0]
    assert isinstance(event, Event)
    assert event.title == 'SABATON'
    assert event.status == 'ACTIVE'
    assert event.description == "Thirty-three drivers. 200 laps. 500 miles. One bottle of cold milk. The only thing missing from this magical Indianapolis 500 mix is you. Don't miss out on another incredible edition of \"The Greatest Spectacle in Racing.\""
    assert event.image_url == 'http://d255vb63773d25.cloudfront.net/-/media/IMS/events/schedule-images/indy-500/2020/Indy500.png?vs=1&d=20200326T144925Z'
    assert event.promoted is False
    assert event.created_at == datetime(2015, 7, 22, 17, 53, 56, tzinfo=timezone(timedelta(0), '+0000'))
    assert event.updated_at == datetime(2020, 4, 9, 15, 0, 42, tzinfo=timezone(timedelta(0), '+0000'))
    assert len(event.event_dates) == 1
    assert event.event_dates[0].id == 5448
    assert event.event_dates[0].start_at == datetime(2017, 3, 29, 16, 0, tzinfo=timezone(timedelta(0), '+0000'))
    assert event.event_dates[0].end_at == datetime(2017, 3, 29, 19, 0, tzinfo=timezone(timedelta(0), '+0000'))
    assert event.event_dates[0].general_ticket_url == 'https://www.ticketmaster.co.uk/Blue-tickets/artist/1843366'
    assert event.translations is None
    assert len(event.venues) == 1
    assert event.venues[0].id == 10000994
Пример #10
0
def test_get_fulfilment_points(requests_mock):
    mock_responses = (('GET', 'https://' + TEST_API_DOMAIN +
                       '/v4/sell/fulfilment_points',
                       'mock_responses/ls_api/fulfilment_points.json', 200), )
    configure_mock_responses(requests_mock, mock_responses, FIXTURES_DIR,
                             CONTENT_TYPE)

    resource_client = LiveStyledResourceClient(TEST_API_DOMAIN, 'bar')
    fps = list(resource_client.get_fulfilment_points())
    assert len(fps) == 30
    fps.sort(key=lambda o: o.id)
    fp = fps[0]
    assert isinstance(fp, FulfilmentPoint)
    assert fp.id == 1
    assert fp.status == 'ACTIVE'
    assert fp.reference == 'kartiks Collection point'
    assert fp.image_url == 'https://apiv3.s3.eu-west-1.amazonaws.com/fulfilmentpoint/German-Shepherd-Puppy-Fetch.jpg'
    assert fp.map_image_url == 'https://apiv3.s3.eu-west-1.amazonaws.com/fulfilmentpoint/british_summer_time_map_bigger.jpg'
    assert fp.lat == '38.026641'
    assert fp.lat == '38.026641'
    assert fp.type == 'VIRTUAL_QUEUE'
    assert fp.position == 0
    assert isinstance(fp.translations, list)
    assert isinstance(fp.translations[0], FulfilmentPointTranslation)
    assert fp.translations[0].language == 'en'
    assert fp.translations[0].title == 'Fulfilment point 1'
    assert fp.translations[0].description == 'Description'
    assert fp.translations[0].collection_note == 'Fulfillment note 1'
    assert isinstance(fp.categories, list)
    assert isinstance(fp.categories[0], FulfilmentPointCategory)
    assert isinstance(fp.audiences, list)
    assert isinstance(fp.audiences[0], Audience)
    assert isinstance(fp.audiences[1], Audience)
    assert fp.audiences[0].id == 1
    assert fp.audiences[1].id == 2
Пример #11
0
def test_get_widgets(requests_mock):
    mock_responses = (('GET', REQUEST_BASE_URL.format('canvas/widgets'),
                       'mock_responses/ls_api/canvas/widgets.json', 200), )
    configure_mock_responses(requests_mock, mock_responses, FIXTURES_DIR,
                             CONTENT_TYPE)

    resource_client = LiveStyledResourceClient(TEST_API_DOMAIN, 'bar')
    widgets = resource_client.get_widgets()
    assert isinstance(next(widgets), Widget)
Пример #12
0
def test_get_widget_item(requests_mock):
    item_endpoint = REQUEST_BASE_URL.format('canvas/widgets/1')
    mock_responses = (('GET', item_endpoint,
                       'mock_responses/ls_api/canvas/item_widget.json', 200), )

    configure_mock_responses(requests_mock, mock_responses, FIXTURES_DIR,
                             CONTENT_TYPE)

    resource_client = LiveStyledResourceClient(TEST_API_DOMAIN, 'bar')
    widget = resource_client.get_widget(id=1)
    assert isinstance(widget, Widget)
Пример #13
0
def test_create_product_modifier_list(requests_mock):
    resource_client = LiveStyledResourceClient(TEST_API_DOMAIN, 'bar')
    mock_responses = (
        ('POST',
         'https://' + TEST_API_DOMAIN + '/v4/sell/product_modifier_lists',
         'mock_responses/ls_api/sell/new_product_modifier_list.json', 200), )
    configure_mock_responses(requests_mock, mock_responses, FIXTURES_DIR,
                             CONTENT_TYPE)

    modifier_item = ProductModifierItem(id=35,
                                        external_id='item1',
                                        additional_price=150,
                                        translations=[{
                                            'language': 'en',
                                            'title': 'test'
                                        }],
                                        modifier_list=None)

    resource_client.create_product_modifier_list(
        ProductModifierList.create_new(external_id='list1',
                                       reference='reference',
                                       status='ACTIVE',
                                       multiple_select=True,
                                       mandatory_select=True,
                                       translations=[{
                                           'language': 'en',
                                           'title': 'test'
                                       }],
                                       items=[modifier_item]))

    assert len(requests_mock.request_history) == 1
    assert requests_mock.request_history[0].method == 'POST'
    assert requests_mock.request_history[
        0].url == 'https://' + TEST_API_DOMAIN + '/v4/sell/product_modifier_lists'
    assert json.loads(requests_mock.request_history[0].body) == {
        'externalId':
        'list1',
        'items':
        ['/sell/product_modifier_items/35', '/sell/product_modifier_items/35'],
        'multipleSelect':
        True,
        'mandatorySelect':
        True,
        'reference':
        'reference',
        'status':
        'ACTIVE',
        'translations': [{
            'language': 'en',
            'title': 'test'
        }]
    }
Пример #14
0
def test_get_banner(requests_mock):
    mock_file = 'mock_responses/ls_api/content_management/item_banner.json'
    collection_endpoint = REQUEST_BASE_URL.format(
        'content_management/banners/1')
    mock_responses = (('GET', collection_endpoint, mock_file, 200), )

    configure_mock_responses(requests_mock, mock_responses, FIXTURES_DIR,
                             CONTENT_TYPE)

    resource_client = LiveStyledResourceClient(TEST_API_DOMAIN, 'bar')
    banner = resource_client.get_banner(id=1)
    assert isinstance(banner, Banner)
    assert isinstance(banner.translations, List)
def test_get_news(requests_mock):
    mock_responses = (
        ('GET', 'https://' + TEST_API_DOMAIN + '/v4/news', 'mock_responses/ls_api/news.json', 200),
    )
    configure_mock_responses(requests_mock, mock_responses, FIXTURES_DIR, CONTENT_TYPE)

    resource_client = LiveStyledResourceClient(TEST_API_DOMAIN, 'bar')
    news = resource_client.get_news_articles()
    news = [n for n in news]
    assert len(news) == 2
    news.sort(key=lambda n: n.id)
    assert news[0].id == 1234
    assert news[1].id == 1235
Пример #16
0
def test_get_device_by_id(requests_mock):
    mock_responses = (('GET', 'https://' + TEST_API_DOMAIN +
                       '/v4/user_management/devices/1234',
                       'mock_responses/ls_api/device_1234.json', 200), )
    configure_mock_responses(requests_mock, mock_responses, FIXTURES_DIR,
                             CONTENT_TYPE)

    resource_client = LiveStyledResourceClient(TEST_API_DOMAIN, 'bar')
    device = resource_client.get_device(1234)
    assert device
    assert isinstance(device, Device)
    assert device.id == 1234
    assert device.push_consents == []
def test_get_team_by_id(requests_mock):
    mock_responses = (
        ('GET', 'https://' + TEST_API_DOMAIN + '/v4/teams/6', 'mock_responses/ls_api/team_6.json', 200),
    )
    configure_mock_responses(requests_mock, mock_responses, FIXTURES_DIR, CONTENT_TYPE)

    resource_client = LiveStyledResourceClient(TEST_API_DOMAIN, 'bar')
    team = resource_client.get_team(6)
    assert team.name == 'LiveStyled'
    assert team.short_name == 'LS'
    assert team.light_crest_url == 'https://apiv3.s3.eu-west-1.amazonaws.com/team/Logo_White_nontext.png'
    assert team.dark_crest_url == 'https://apiv3.s3.eu-west-1.amazonaws.com/team/Logo_Purple_notext.png'
    assert team.external_id is None
Пример #18
0
def test_create_product(requests_mock):
    resource_client = LiveStyledResourceClient(TEST_API_DOMAIN, 'bar')
    mock_responses = (('POST',
                       'https://' + TEST_API_DOMAIN + '/v4/sell/products',
                       'mock_responses/ls_api/sell/new_product.json', 200), )
    configure_mock_responses(requests_mock, mock_responses, FIXTURES_DIR,
                             CONTENT_TYPE)

    resource_client.create_product(
        Product.create_new(
            external_id='testproduct1',
            categories=None,
            status='ACTIVE',
            reference='Test Product 1',
            translations=[{
                'language': 'en',
                'title': 'Test Product 1',
                'description': 'This is a Test Product'
            }],
            price=100,
            fulfilment_points=[],
            core_product_category=None,
            holding_time=None,
            images=None,
            modifier_lists=None,
            reconciliation_group=None,
            variants=None,
        ))

    assert len(requests_mock.request_history) == 1
    assert requests_mock.request_history[0].method == 'POST'
    assert requests_mock.request_history[
        0].url == 'https://' + TEST_API_DOMAIN + '/v4/sell/products'
    assert json.loads(requests_mock.request_history[0].body) == {
        'externalId':
        'testproduct1',
        'reference':
        'Test Product 1',
        'status':
        'ACTIVE',
        'translations': [{
            'description': 'This is a Test Product',
            'language': 'en',
            'title': 'Test Product 1'
        }],
        'images': [],
        'categories': [],
        'fulfilmentPoints': [],
        'modifierLists': [],
        'variants': []
    }
def test_get_device_preferences(requests_mock):
    mock_responses = (
        ('GET', 'https://' + TEST_API_DOMAIN + '/v4/device_preferences',
         'mock_responses/ls_api/device_preferences_page1.json', 200),
        ('GET', 'https://' + TEST_API_DOMAIN + '/v4/device_preferences?page=2',
         'mock_responses/ls_api/device_preferences_page2.json', 200),
    )
    configure_mock_responses(requests_mock, mock_responses, FIXTURES_DIR,
                             CONTENT_TYPE)

    resource_client = LiveStyledResourceClient(TEST_API_DOMAIN, 'bar')
    device_preferences = list(resource_client.get_device_preferences())
    assert device_preferences
    assert len(device_preferences) == 31
    device_preference = device_preferences[0]
    assert isinstance(device_preference, DevicePreference)
    assert device_preference.venue
    assert isinstance(device_preference.venue, Venue)
    assert device_preference.venue.id == 10000918
    assert device_preference.id == 1
    assert device_preference.device
    assert isinstance(device_preference.device, Device)
    assert device_preference.device.id == 1620610
    assert not device_preference.event
    assert device_preference.created_at == datetime(2019,
                                                    2,
                                                    12,
                                                    15,
                                                    12,
                                                    46,
                                                    tzinfo=timezone(
                                                        timedelta(0), '+0000'))

    device_preference = device_preferences[3]
    assert isinstance(device_preference, DevicePreference)
    assert device_preference.id == 4
    assert not device_preference.venue
    assert device_preference.device
    assert isinstance(device_preference.device, Device)
    assert device_preference.device.id == 1748339
    assert device_preference.event
    assert isinstance(device_preference.event, Event)
    assert device_preference.event.id == 100015921
    assert device_preference.created_at == datetime(2019,
                                                    8,
                                                    27,
                                                    17,
                                                    19,
                                                    6,
                                                    tzinfo=timezone(
                                                        timedelta(0), '+0000'))
Пример #20
0
def test_get_banners(requests_mock):
    mock_file = 'mock_responses/ls_api/content_management/banners.json'
    mock_responses = (('GET',
                       REQUEST_BASE_URL.format('content_management/banners'),
                       mock_file, 200), )
    configure_mock_responses(requests_mock, mock_responses, FIXTURES_DIR,
                             CONTENT_TYPE)

    resource_client = LiveStyledResourceClient(TEST_API_DOMAIN, 'bar')
    banners = resource_client.get_banners()
    current_banner = next(banners)
    assert isinstance(current_banner, Banner)
    assert isinstance(current_banner.translations, List)
    assert isinstance(current_banner.translations[0], BannerTranslation)
def test_create_team_with_id(requests_mock):
    team = Team(
        id=1,
        external_id='testteam1',
        name='Test Team',
        short_name='TT',
        light_crest_url='http://www.images.com/image1.jpg',
        dark_crest_url='http://www.images.com/image2.jpg',
    )

    resource_client = LiveStyledResourceClient(TEST_API_DOMAIN, 'bar')

    with pytest.raises(ValueError, match='Cannot create a Team with an ID'):
        resource_client.create_team(team)
def test_get_locations(requests_mock):
    mock_responses = (('GET', 'https://' + TEST_API_DOMAIN +
                       '/v4/user_management/locations',
                       'mock_responses/ls_api/user_management/locations.json',
                       200), )
    configure_mock_responses(requests_mock, mock_responses, FIXTURES_DIR,
                             CONTENT_TYPE)

    resource_client = LiveStyledResourceClient(TEST_API_DOMAIN, 'bar')
    locations = list(resource_client.get_locations())
    assert locations
    assert len(locations) == 19
    assert isinstance(locations[0], Location)
    assert locations[0].id == 1
    assert locations[0].listed is True
    assert locations[0].name == 'Berlin'
    assert locations[0].coordinates.lat == 52.5200
    assert locations[0].coordinates.lon == 13.4050
    assert locations[0].polygon is None
    assert locations[0].sort_id == 10
    assert locations[0].external_id == ''

    assert locations[2].id == 3
    assert locations[2].status == 'active'
    assert locations[2].listed is True
    assert locations[2].name == 'London'
    assert locations[2].coordinates.lat == 51.5074
    assert locations[2].coordinates.lon == 0.1278
    assert locations[2].polygon.coordinates == [
        LocationCoordinates(51.687030937462666, -0.1373291015625),
        LocationCoordinates(51.7151177895987, -0.27191162109374994),
        LocationCoordinates(51.72022261695929, -0.416107177734375),
        LocationCoordinates(51.62142713341988, -0.536956787109375),
    ]

    assert locations[3].id == 4
    assert locations[3].status == 'active'
    assert locations[3].listed is False
    assert locations[3].name == 'LS Office CO'
    assert locations[3].coordinates.lat == 51.5413393
    assert locations[3].coordinates.lon == -0.09543170000000001
    assert locations[3].polygon.coordinates == [
        LocationCoordinates(51.543792920127274, -0.10062575340270996),
        LocationCoordinates(51.542838751511205, -0.10001420974731445),
        LocationCoordinates(51.54066343916916, -0.09590506553649901),
        LocationCoordinates(51.543586074083876, -0.09056210517883301),
        LocationCoordinates(51.54612821344662, -0.09384512901306152),
        LocationCoordinates(51.543792920127274, -0.10062575340270996),
    ]
    assert locations[3].external_id is None
Пример #23
0
def test_update_ticket_auth(requests_mock):
    mock_responses = (('PATCH',
                       'https://' + TEST_API_DOMAIN + '/v4/ticket_auths/1038',
                       'mock_responses/ls_api/ticket_auth_updated.json',
                       200), )
    configure_mock_responses(requests_mock, mock_responses, FIXTURES_DIR,
                             CONTENT_TYPE)

    resource_client = LiveStyledResourceClient(TEST_API_DOMAIN, 'bar')
    resource_client.update_ticket_auth(TicketAuth.placeholder(1038),
                                       {'client_id': '99999'})
    assert requests_mock.request_history[0].method == 'PATCH'
    assert json.loads(requests_mock.request_history[0].body) == {
        'clientId': '99999'
    }
def test_get_team_by_external_id(requests_mock):
    mock_responses = (
        ('GET', 'https://' + TEST_API_DOMAIN + '/v4/teams?externalId=t3', 'mock_responses/ls_api/teams_external_id_t3.json', 200),
    )
    configure_mock_responses(requests_mock, mock_responses, FIXTURES_DIR, CONTENT_TYPE)

    resource_client = LiveStyledResourceClient(TEST_API_DOMAIN, 'bar')
    teams = list(resource_client.get_teams(external_id='t3'))
    assert teams
    team = teams[0]
    assert team.name == 'Arsenal'
    assert team.short_name == 'ARS'
    assert team.light_crest_url == 'https://apiv3-dev.s3.eu-west-1.amazonaws.com/27/team/arsenal-300x300.png'
    assert team.dark_crest_url == 'https://apiv3-dev.s3.eu-west-1.amazonaws.com/27/team/arsenal-300x300.png'
    assert team.external_id == 't3'
def test_get_device_preferences_default_ordering(requests_mock):
    mock_responses = (
        ('GET', 'https://' + TEST_API_DOMAIN + '/v4/device_preferences',
         'mock_responses/ls_api/device_preferences_page1.json', 200),
        ('GET', 'https://' + TEST_API_DOMAIN + '/v4/device_preferences?page=2',
         'mock_responses/ls_api/device_preferences_page2.json', 200),
    )
    configure_mock_responses(requests_mock, mock_responses, FIXTURES_DIR,
                             CONTENT_TYPE)

    resource_client = LiveStyledResourceClient(TEST_API_DOMAIN, 'bar')
    list(resource_client.get_device_preferences())

    assert len(requests_mock.request_history) == 2
    assert requests_mock.request_history[
        0].url == 'https://test.livestyled.com/v4/device_preferences?order%5BcreatedAt%5D=desc'
Пример #26
0
def test_get_screens_widget_by_audience(requests_mock):
    collection_endpoint = REQUEST_BASE_URL.format(
        'canvas/screens/1/widgets_by_audience?audience=1')
    mock_responses = (('GET', collection_endpoint,
                       'mock_responses/ls_api/canvas/widgets_by_audience.json',
                       200), )

    configure_mock_responses(requests_mock, mock_responses, FIXTURES_DIR,
                             CONTENT_TYPE)

    resource_client = LiveStyledResourceClient(TEST_API_DOMAIN, 'bar')
    widgets = resource_client.get_widgets_by_audience(screen_id=1,
                                                      audience_id=1,
                                                      timestamp=time.time())
    current_widget = next(widgets)
    assert isinstance(current_widget, Widget)
    assert isinstance(current_widget.variation, WidgetVariation)
def test_get_form_data(requests_mock):
    mock_responses = (('GET',
                       'https://' + TEST_API_DOMAIN + '/v4/engage/form_data',
                       'mock_responses/ls_api/engage/form_data.json', 200), )
    configure_mock_responses(requests_mock, mock_responses, FIXTURES_DIR,
                             CONTENT_TYPE)

    resource_client = LiveStyledResourceClient(TEST_API_DOMAIN, 'bar')
    form_data = list(resource_client.get_form_data())
    assert len(form_data) == 30
    form_data.sort(key=lambda o: o.id)
    form_data_1 = form_data[0]
    assert isinstance(form_data_1, DeviceFormData)
    assert form_data_1.id == 1
    assert isinstance(form_data_1.data, list)
    assert isinstance(form_data_1.device, Device)
    assert isinstance(form_data_1.form, Form)
Пример #28
0
def test_get_widget_variations(requests_mock):
    item_endpoint = REQUEST_BASE_URL.format('canvas/widget_variations')
    mock_responses = (
        ('GET', item_endpoint,
         'mock_responses/ls_api/canvas/widget_variations.json', 200),
        ('GET', REQUEST_BASE_URL.format('canvas/widgets/1'),
         'mock_responses/ls_api/canvas/item_widget.json', 200),
    )

    configure_mock_responses(requests_mock, mock_responses, FIXTURES_DIR,
                             CONTENT_TYPE)

    resource_client = LiveStyledResourceClient(TEST_API_DOMAIN, 'bar')
    widget_variations = resource_client.get_widget_variations()
    current_widget_variation = next(widget_variations)
    assert isinstance(current_widget_variation, WidgetVariation)
    assert isinstance(current_widget_variation.widget, Widget)
def test_get_news_by_id(requests_mock):
    mock_responses = (
        ('GET', 'https://' + TEST_API_DOMAIN + '/v4/news/1234', 'mock_responses/ls_api/news_1234.json', 200),
    )
    configure_mock_responses(requests_mock, mock_responses, FIXTURES_DIR, CONTENT_TYPE)

    resource_client = LiveStyledResourceClient(TEST_API_DOMAIN, 'bar')
    news = resource_client.get_news_article(1234)
    assert isinstance(news, News)
    assert news.id == 1234
    assert news.title == 'Things happened'
    assert news.external_id == '50990'
    assert news.published_at == datetime(2020, 2, 23, 4, 56, 59, tzinfo=timezone(timedelta(0), '+0000'))
    assert news.headline == 'Some news'
    assert news.author is None
    assert news.updated_at == datetime(2020, 3, 18, 1, 15, 7, tzinfo=timezone(timedelta(0), '+0000'))
    assert news.media == {
        'type': 'EXTERNALVIDEO',
        'url': 'https://www.thenews.com/video',
        'thumbnail_url': None,
    }
Пример #30
0
def test_get_user_by_id(requests_mock):
    mock_responses = (('GET', 'https://' + TEST_API_DOMAIN +
                       '/v4/user_management/users/1234',
                       'mock_responses/ls_api/user_1234.json', 200), )
    configure_mock_responses(requests_mock, mock_responses, FIXTURES_DIR,
                             CONTENT_TYPE)

    resource_client = LiveStyledResourceClient(TEST_API_DOMAIN, 'bar')
    user = resource_client.get_user(1234)
    assert user
    assert isinstance(user, User)
    assert user.id == 1234
    assert user.email == '*****@*****.**'
    assert user.auth_type == 'LOCAL'
    assert user.first_name == 'Bob'
    assert user.last_name == 'Bobberson'
    assert user.password is None
    assert set(user.cohorts) == {
        Cohort.placeholder(1),
        Cohort.placeholder(2),
        Cohort.placeholder(8)
    }
    assert user.user_info.first_name == 'Bob'
    assert user.user_info.last_name == 'Bobberson'
    assert user.user_info.dob == datetime.datetime(1992,
                                                   12,
                                                   6,
                                                   0,
                                                   0,
                                                   tzinfo=datetime.timezone(
                                                       datetime.timedelta(0),
                                                       '+0000'))
    assert user.user_info.gender == 'MALE'
    assert len(user.magic_fields) == 1
    assert user.magic_fields[0].key == 'rtest'
    assert user.magic_fields[0].value == 'foobar'
    assert user.magic_fields[0].id == 52
    assert len(user.devices) == 1
    assert user.devices[0].id == 1753940