def term_create_test(api, client, sample_taxonomy): term = client.put('/api/2.0/taxonomies/test/aaa', data=json.dumps({'title': 'test aaa title'}), content_type='application/json') exp = { 'links': { 'self': 'http://localhost/api/2.0/taxonomies/test/aaa', }, 'title': 'test aaa title' } assert json.loads(term.data) == exp taxonomies = client.get('/api/2.0/taxonomies/test/aaa') assert json.loads(taxonomies.data) == exp term = client.put('/api/2.0/taxonomies/test/aaa/bbb', data=json.dumps({'title': 'test bbb title'}), content_type='application/json') exp = { 'ancestors': [{ 'links': { 'self': 'http://localhost/api/2.0/taxonomies/test/aaa' }, 'title': 'test aaa title' }], 'links': { 'self': 'http://localhost/api/2.0/taxonomies/test/aaa/bbb' }, 'title': 'test bbb title' } assert json.loads(term.data) == exp taxonomies = client.get('/api/2.0/taxonomies/test/aaa/bbb') assert json.loads(taxonomies.data) == exp
def taxonomy_update_test(api, client, test_taxonomy): taxonomy = client.put('/api/2.0/taxonomies/test', data=json.dumps({'title': 'test title updated'}), content_type='application/json') exp = { 'code': 'test', 'links': { 'self': 'http://localhost/api/2.0/taxonomies/test/' }, 'title': 'test title updated' } assert json.loads(taxonomy.data) == exp taxonomies = client.get('/api/2.0/taxonomies/test') assert json.loads(taxonomies.data) == exp
def get_excluded_title_descendants_test(api, client, excluded_title_sample_taxonomy): taxonomy = client.get( '/api/2.0/taxonomies/test?representation:include=dsc') if taxonomy.status_code != 200: print(taxonomy.data) assert taxonomy.status_code == 200 assert json.loads(taxonomy.data) == { 'code': 'test', 'links': { 'self': 'http://localhost/api/2.0/taxonomies/test/', }, 'children': [{ 'links': { 'self': 'http://localhost/api/2.0/taxonomies/test/a', }, 'children': [{ 'links': { 'self': 'http://localhost/api/2.0/taxonomies/test/a/aa', } }] }, { 'links': { 'self': 'http://localhost/api/2.0/taxonomies/test/b', } }] }
def get_taxonomy_descendants_level_slug_test(api, client, sample_taxonomy): taxonomy = client.get( '/api/2.0/taxonomies/test?representation:include=dsc,slug,lvl&representation:levels=1' ) if taxonomy.status_code != 200: print(taxonomy.data) assert taxonomy.status_code == 200 assert json.loads(taxonomy.data) == { 'code': 'test', 'level': 0, 'links': { 'self': 'http://localhost/api/2.0/taxonomies/test/', }, 'title': 'Test taxonomy', 'children': [{ 'title': 'A', 'slug': 'a', 'level': 1, 'links': { 'self': 'http://localhost/api/2.0/taxonomies/test/a', } }, { 'title': 'B', 'slug': 'b', 'level': 1, 'links': { 'self': 'http://localhost/api/2.0/taxonomies/test/b', } }] }
def taxonomy_list_selector_test(api, client, sample_taxonomy): taxonomies = client.get( '/api/2.0/taxonomies/', headers={'prefer': 'return=representation; select=; exclude=url drl'}) if taxonomies.status_code != 200: print(taxonomies.data) assert taxonomies.status_code == 200 assert json.loads(taxonomies.data) == [{'code': 'test'}]
def taxonomy_list_test(api, client, sample_taxonomy): taxonomies = client.get('/api/2.0/taxonomies/') if taxonomies.status_code != 200: print(taxonomies.data) assert taxonomies.status_code == 200 assert json.loads(taxonomies.data) == [{ 'code': 'test', 'title': 'Test taxonomy', 'links': { 'self': 'http://localhost/api/2.0/taxonomies/test/' } }]
def taxonomy_list_no_urls_in_query_test(api, client, sample_taxonomy): taxonomies = client.get( '/api/2.0/taxonomies/?representation:exclude=url,drl&representation:include=id' ) if taxonomies.status_code != 200: print(taxonomies.data) assert taxonomies.status_code == 200 assert json.loads(taxonomies.data) == [{ 'code': 'test', 'title': 'Test taxonomy', 'id': 1 }]
def get_taxonomy_term_parent_test(api, client, sample_taxonomy): taxonomy = client.get( '/api/2.0/taxonomies/test/a/aa?representation:include=par&representation:exclude=anc' ) if taxonomy.status_code != 200: print(taxonomy.data) assert taxonomy.status_code == 200 assert json.loads(taxonomy.data) == { 'title': 'AA', 'links': { 'self': 'http://localhost/api/2.0/taxonomies/test/a/aa', 'parent': 'http://localhost/api/2.0/taxonomies/test/a' } }
def taxonomy_list_no_urls_but_id_test(api, client, sample_taxonomy): taxonomies = client.get( '/api/2.0/taxonomies/', headers={ 'prefer': 'return=representation; exclude=url drl; include=id' }) if taxonomies.status_code != 200: print(taxonomies.data) assert taxonomies.status_code == 200 assert json.loads(taxonomies.data) == [{ 'code': 'test', 'title': 'Test taxonomy', 'id': 1 }]
def test_taxonomy_list(permission_client, taxonomy): client = permission_client taxonomies = client.get('/2.0/taxonomies/') assert taxonomies.status_code == 200 assert json.loads(taxonomies.data) == [{ 'code': 'test_taxonomy', 'links': { 'self': 'http://127.0.0.1:5000/2.0/taxonomies/test_taxonomy/' }, 'title': { 'cs': 'test_taxonomy', 'en': 'test_taxonomy' } }]
def get_taxonomy_term_ancestor_tag_test(api, client, sample_taxonomy): taxonomy = client.get( '/api/2.0/taxonomies/test/a/aa?representation:include=ant anl') if taxonomy.status_code != 200: print(taxonomy.data) assert taxonomy.status_code == 200 assert json.loads(taxonomy.data) == [{ 'title': 'A', 'links': { 'self': 'http://localhost/api/2.0/taxonomies/test/a', }, 'is_ancestor': True }, { 'title': 'AA', 'links': { 'self': 'http://localhost/api/2.0/taxonomies/test/a/aa', }, 'is_ancestor': False }]
def get_taxonomy_paginated_descendants_test(api, client, sample_taxonomy): taxonomy = client.get( '/api/2.0/taxonomies/test?representation:include=dsc,env&representation:exclude=url,drl&page=1&size=1' ) if taxonomy.status_code != 200: print(taxonomy.data) assert taxonomy.status_code == 200 assert json.loads(taxonomy.data) == { 'children': [{ 'data': { 'title': 'A' } }], 'code': 'test', 'data': { 'title': 'Test taxonomy' }, 'page': 1, 'size': 1, 'total': 3 } # second page - should keep 'A' to preserve the hierarchy taxonomy = client.get( '/api/2.0/taxonomies/test?representation:include=dsc,anh,env&representation:exclude=url,drl&page=2&size=1' ) if taxonomy.status_code != 200: print(taxonomy.data) assert taxonomy.status_code == 200 assert json.loads(taxonomy.data) == { 'children': [{ 'ancestor': True, 'children': [{ 'data': { 'title': 'AA' } }], 'data': { 'title': 'A' } }], 'code': 'test', 'data': { 'title': 'Test taxonomy' }, 'page': 2, 'size': 1, 'total': 3 } # third page - just B taxonomy = client.get( '/api/2.0/taxonomies/test?representation:include=dsc,anh,env&representation:exclude=url,drl&page=3&size=1' ) if taxonomy.status_code != 200: print(taxonomy.data) assert taxonomy.status_code == 200 assert json.loads(taxonomy.data) == { 'children': [{ 'data': { 'title': 'B' } }], 'code': 'test', 'data': { 'title': 'Test taxonomy' }, 'page': 3, 'size': 1, 'total': 3 }
def taxonomy_list_empty_test(api, client): taxonomies = client.get('/api/2.0/taxonomies/') assert json.loads(taxonomies.data) == []
def taxonomy_list_pagination_test(api, client, many_taxonomies): taxonomies = client.get( '/api/2.0/taxonomies/?page=2&size=10', headers={ 'prefer': 'return=representation; exclude=url drl; include=env' }) if taxonomies.status_code != 200: print(taxonomies.data) assert taxonomies.status_code == 200 assert json.loads(taxonomies.data) == { 'data': [{ 'code': 'test-11', 'data': { 'title': 'Test taxonomy #11' } }, { 'code': 'test-12', 'data': { 'title': 'Test taxonomy #12' } }, { 'code': 'test-13', 'data': { 'title': 'Test taxonomy #13' } }, { 'code': 'test-14', 'data': { 'title': 'Test taxonomy #14' } }, { 'code': 'test-15', 'data': { 'title': 'Test taxonomy #15' } }, { 'code': 'test-16', 'data': { 'title': 'Test taxonomy #16' } }, { 'code': 'test-17', 'data': { 'title': 'Test taxonomy #17' } }, { 'code': 'test-18', 'data': { 'title': 'Test taxonomy #18' } }, { 'code': 'test-19', 'data': { 'title': 'Test taxonomy #19' } }, { 'code': 'test-20', 'data': { 'title': 'Test taxonomy #20' } }], 'links': { 'self': 'http://localhost/api/2.0/taxonomies/?page=2&size=10' }, 'page': 2, 'size': 10, 'total': 100 } taxonomies = client.get( '/api/2.0/taxonomies/?page=2&size=10', headers={'prefer': 'return=representation; exclude=url drl'}) if taxonomies.status_code != 200: print(taxonomies.data) assert taxonomies.status_code == 200 assert json.loads(taxonomies.data) == [{ 'code': 'test-11', 'title': 'Test taxonomy #11' }, { 'code': 'test-12', 'title': 'Test taxonomy #12' }, { 'code': 'test-13', 'title': 'Test taxonomy #13' }, { 'code': 'test-14', 'title': 'Test taxonomy #14' }, { 'code': 'test-15', 'title': 'Test taxonomy #15' }, { 'code': 'test-16', 'title': 'Test taxonomy #16' }, { 'code': 'test-17', 'title': 'Test taxonomy #17' }, { 'code': 'test-18', 'title': 'Test taxonomy #18' }, { 'code': 'test-19', 'title': 'Test taxonomy #19' }, { 'code': 'test-20', 'title': 'Test taxonomy #20' }] # out of pages taxonomies = client.get( '/api/2.0/taxonomies/?page=11&size=10', headers={ 'prefer': 'return=representation; exclude=url drl; include=env' }) if taxonomies.status_code != 200: print(taxonomies.data) assert taxonomies.status_code == 200 assert json.loads(taxonomies.data) == { 'data': [], 'links': { 'self': 'http://localhost/api/2.0/taxonomies/?page=11&size=10' }, 'page': 11, 'size': 10, 'total': 100 } taxonomies = client.get( '/api/2.0/taxonomies/?page=11&size=10', headers={'prefer': 'return=representation; exclude=url drl'}) if taxonomies.status_code != 200: print(taxonomies.data) assert taxonomies.status_code == 200 assert json.loads(taxonomies.data) == []