Пример #1
0
def test_get_block_schemas(app, test_communities):
    """"Test getting list of given community's schemas."""
    with app.app_context():
        community = Community.create_community('name1', 'desc1')
        community_id = community.id
        community_2 = Community.create_community('name2', 'desc2')
        community_id2 = community_2.id
        block_schema_1 = BlockSchema.create_block_schema(community_id, 'abc')
        block_schema_2 = BlockSchema.create_block_schema(community_id2, 'abc2')
        block_schema_3 = BlockSchema.create_block_schema(community_id2, 'abc3')
        with app.test_client() as client:
            headers = [('Content-Type', 'application/json'),
                       ('Accept', 'application/json')]
            res = client.get(
                url_for(
                    'b2share_schemas.block_schema_list',
                    community_id=community_id2
                ),
                headers=headers)
            assert res.status_code == 200
            response_data = json.loads(res.get_data(as_text=True))
            assert isinstance(response_data['schemas'], list)
            assert len(response_data['schemas']) == 2
            assert response_data['schemas'][0]['name'] == block_schema_2.name
            assert response_data['schemas'][1]['name'] == block_schema_3.name
Пример #2
0
def test_get_block_schemas(app, test_communities):
    """"Test getting list of given community's schemas."""
    with app.app_context():
        community = Community.create_community('name1', 'desc1')
        community_id = community.id
        community_2 = Community.create_community('name2', 'desc2')
        community_id2 = community_2.id
        block_schema_1 = BlockSchema.create_block_schema(community_id, 'abc')
        block_schema_2 = BlockSchema.create_block_schema(community_id2, 'abc2')
        block_schema_3 = BlockSchema.create_block_schema(community_id2, 'abc3')
        with app.test_client() as client:
            headers = [('Content-Type', 'application/json'),
                       ('Accept', 'application/json')]
            res = client.get(url_for('b2share_schemas.block_schema_list',
                                     community_id=community_id2),
                             headers=headers)
            assert res.status_code == 200
            response_data = json.loads(res.get_data(as_text=True))
            assert isinstance(response_data['schemas'], list)
            assert len(response_data['schemas']) == 2
            assert response_data['schemas'][0]['name'] == block_schema_2.name
            assert response_data['schemas'][1]['name'] == block_schema_3.name
Пример #3
0
def test_updating_block_schema(app, test_communities):
    """Test updating a block schema."""
    with app.app_context():
        community = Community.create_community('name1', 'desc1')
        community_id = community.id
        block_schema = BlockSchema.create_block_schema(community_id,
                                                       'original')
        with app.test_client() as client:
            headers = [('Content-Type', 'application/json'),
                       ('Accept', 'application/json')]
            res = client.patch(url_for('b2share_schemas.block_schema_item',
                                       schema_id=block_schema.id),
                               data=json.dumps({'name': 'abc'}),
                               headers=headers)
            assert res.status_code == 200