123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200 |
- # -*- coding: utf-8 -*-
- #!/usr/bin/env python
- """
- 测试广告报表功能
- 需要展现的业务
- * 折线图
- * 粉丝总数
- * 每日新粉丝
- * 展现
- * 点击量
- """
- import pytest
- from django.conf import settings
- from faker import Factory
- fake = Factory.create('zh_CN')
- from apps.web.ad.models import AdRecord, Advertisement
- from .base import pluck
- from common import url_fn
- #pytestmark = pytest.mark.skip(reason='the ad system needs to be refactored')
- def test_get_ad_fans_trend():
- pass
- def test_set_directed_ad_to_device(mocker, mocked_redis):
- pass
- def test_get_directed_ad_by_device(mocker, mocked_redis):
- pass
- @pytest.mark.parametrize("query, expected", [
- #: nothing selected
- (
- {"devCondition":[{"agentIdList":[],"dealerIdList":[],"groupIdList":[]}],
- "addressTypeList":[],"devTypeList":[]},
- []
- ),
- #: only devTypeList is offered
- #: 纸巾机
- (
- {"devCondition":[{"agentIdList":[],"dealerIdList":[],"groupIdList":[]}],
- "addressTypeList":[], "devTypeList":["5abe2e0a8732d6644d6e4435"]},
- []
- ),
- #: only addressTypeList is offered
- #: school
- (
- {"devCondition": [{"agentIdList": [], "dealerIdList": [], "groupIdList": []}],
- "addressTypeList": ["school"], "devTypeList": []},
- []
- ),
- #: only devTypeList and addressTypeList are offered
- #: school & 纸巾机
- (
- {"devCondition": [{"agentIdList": [], "dealerIdList": [], "groupIdList": []}],
- "addressTypeList": ["school"], "devTypeList": ["5abe2e0a8732d6644d6e4435"]},
- []
- ),
- #: only devCondition is offered
- (
- {"devCondition": [{"agentIdList": [], "dealerIdList": [], "groupIdList": []}],
- "addressTypeList": ["school"], "devTypeList": []},
- []
- )
- ])
- def test_getAdPreAllocatedDevice(manager_client, query, expected):
- url = '/ad/getAdPreAllocatedDevice'
- # assert manager_client.get(url).status_code == 405
- # assert json.loads(manager_client.post(url, '').content)['description'] == u'系统错误'
- #
- # assert pluck(manager_client.post_json(url, query), 'payload.dataList') == expected
- pass
- def test_getAdList(manager_client):
- url = '/ad/getAdList'
- assert manager_client.post(url).status_code == 405
- assert pluck(manager_client.get(url), 'payload.dataList') == []
- def test_addAd(manager_client):
- """
- 需要生成 mongodb entry
- 添加 adProxy
- 初始化 adProxy {状态更新, 刷新各类映射表}
- :return:
- """
- from apps.web.ad.views import addAd
- url = url_fn(addAd)
- test_payload = {
- u'adType': u'init',
- u'addressTypeList': [u'school', u'apartment', u'workshop', u'others'],
- u'agentPrice': 0,
- u'dealerPrice': 0,
- u'devCondition': [],
- u'devList': [],
- u'devTypeList': [u'5abe2e0a8732d6644d6e4435'],
- u'fansType': u'person',
- u'name': u'dsadas',
- u'offlineFansNumber': 0,
- u'phoneOS': [u'iOS', u'Android'],
- u'price': 0,
- u'status': True,
- u'word': u'23232'
- }
- already_existed_ad = Advertisement.objects(name=test_payload['name']).first()
- if already_existed_ad: already_existed_ad.delete()
- assert manager_client.get(url).status_code == 405
- assert pluck(manager_client.post_json(url, data=test_payload), 'result') == 1
- Advertisement.objects(name=test_payload['name']).delete()
- def test_editAd(manager_client):
- """
- 更新 mongodb entry
- 更新 adProxy {状态更新, 刷新各类映射表}
- :return:
- """
- from apps.web.ad.views import editAd
- url = url_fn(editAd)
- assert manager_client.get(url).status_code == 405
- def test_deleteAd(manager_client):
- """
- 删除不作真正的删除,而是标记为删除
- 要同样注意 {状态更新, 刷新各类映射表}
- :return:
- """
- from apps.web.ad.views import deleteAd
- url = url_fn(deleteAd)
- assert manager_client.get(url).status_code == 405
- def test_taskList():
- pass
- test_ad_proxy_payload = {
- 'adId': 'dsafasf',
- 'adName': 'fsadsad',
- 'agentPrice': 0,
- 'dealerPrice': 0,
- 'price': 0,
- 'agentName': u'未命名代理商',
- 'dealerName': u'未知经销商',
- 'logicalCode': '18518',
- 'nickname': u'用户昵称',
- 'sex': u'男',
- 'openId': 'an open id',
- 'devType': u'洗衣机',
- 'address': u'地址',
- 'groupName': u'组名',
- #: filters
- 'groupId' : '34343dssffdf',
- 'dealerId' : '3224eo3jofo3o4o',
- 'agentId' : 'dsad2342423oe4jof',
- 'devNo' : '2321432rfdf',
- #: user actions
- 'clicks' : 1,
- 'shows' : 1,
- }
- def test_getBannerAd(banner_ad, device, wechat_user_client):
- from apps.web.ad.views import getBannerAd
- url = url_fn(getBannerAd)
- assert wechat_user_client.get(url(logicalCode=device['logicalCode'])).json()['payload'] == banner_ad.banner_config
|