test_ad.py 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  1. # -*- coding: utf-8 -*-
  2. #!/usr/bin/env python
  3. """
  4. 测试广告报表功能
  5. 需要展现的业务
  6. * 折线图
  7. * 粉丝总数
  8. * 每日新粉丝
  9. * 展现
  10. * 点击量
  11. """
  12. import pytest
  13. from django.conf import settings
  14. from faker import Factory
  15. fake = Factory.create('zh_CN')
  16. from apps.web.ad.models import AdRecord, Advertisement
  17. from .base import pluck
  18. from common import url_fn
  19. #pytestmark = pytest.mark.skip(reason='the ad system needs to be refactored')
  20. def test_get_ad_fans_trend():
  21. pass
  22. def test_set_directed_ad_to_device(mocker, mocked_redis):
  23. pass
  24. def test_get_directed_ad_by_device(mocker, mocked_redis):
  25. pass
  26. @pytest.mark.parametrize("query, expected", [
  27. #: nothing selected
  28. (
  29. {"devCondition":[{"agentIdList":[],"dealerIdList":[],"groupIdList":[]}],
  30. "addressTypeList":[],"devTypeList":[]},
  31. []
  32. ),
  33. #: only devTypeList is offered
  34. #: 纸巾机
  35. (
  36. {"devCondition":[{"agentIdList":[],"dealerIdList":[],"groupIdList":[]}],
  37. "addressTypeList":[], "devTypeList":["5abe2e0a8732d6644d6e4435"]},
  38. []
  39. ),
  40. #: only addressTypeList is offered
  41. #: school
  42. (
  43. {"devCondition": [{"agentIdList": [], "dealerIdList": [], "groupIdList": []}],
  44. "addressTypeList": ["school"], "devTypeList": []},
  45. []
  46. ),
  47. #: only devTypeList and addressTypeList are offered
  48. #: school & 纸巾机
  49. (
  50. {"devCondition": [{"agentIdList": [], "dealerIdList": [], "groupIdList": []}],
  51. "addressTypeList": ["school"], "devTypeList": ["5abe2e0a8732d6644d6e4435"]},
  52. []
  53. ),
  54. #: only devCondition is offered
  55. (
  56. {"devCondition": [{"agentIdList": [], "dealerIdList": [], "groupIdList": []}],
  57. "addressTypeList": ["school"], "devTypeList": []},
  58. []
  59. )
  60. ])
  61. def test_getAdPreAllocatedDevice(manager_client, query, expected):
  62. url = '/ad/getAdPreAllocatedDevice'
  63. # assert manager_client.get(url).status_code == 405
  64. # assert json.loads(manager_client.post(url, '').content)['description'] == u'系统错误'
  65. #
  66. # assert pluck(manager_client.post_json(url, query), 'payload.dataList') == expected
  67. pass
  68. def test_getAdList(manager_client):
  69. url = '/ad/getAdList'
  70. assert manager_client.post(url).status_code == 405
  71. assert pluck(manager_client.get(url), 'payload.dataList') == []
  72. def test_addAd(manager_client):
  73. """
  74. 需要生成 mongodb entry
  75. 添加 adProxy
  76. 初始化 adProxy {状态更新, 刷新各类映射表}
  77. :return:
  78. """
  79. from apps.web.ad.views import addAd
  80. url = url_fn(addAd)
  81. test_payload = {
  82. u'adType': u'init',
  83. u'addressTypeList': [u'school', u'apartment', u'workshop', u'others'],
  84. u'agentPrice': 0,
  85. u'dealerPrice': 0,
  86. u'devCondition': [],
  87. u'devList': [],
  88. u'devTypeList': [u'5abe2e0a8732d6644d6e4435'],
  89. u'fansType': u'person',
  90. u'name': u'dsadas',
  91. u'offlineFansNumber': 0,
  92. u'phoneOS': [u'iOS', u'Android'],
  93. u'price': 0,
  94. u'status': True,
  95. u'word': u'23232'
  96. }
  97. already_existed_ad = Advertisement.objects(name=test_payload['name']).first()
  98. if already_existed_ad: already_existed_ad.delete()
  99. assert manager_client.get(url).status_code == 405
  100. assert pluck(manager_client.post_json(url, data=test_payload), 'result') == 1
  101. Advertisement.objects(name=test_payload['name']).delete()
  102. def test_editAd(manager_client):
  103. """
  104. 更新 mongodb entry
  105. 更新 adProxy {状态更新, 刷新各类映射表}
  106. :return:
  107. """
  108. from apps.web.ad.views import editAd
  109. url = url_fn(editAd)
  110. assert manager_client.get(url).status_code == 405
  111. def test_deleteAd(manager_client):
  112. """
  113. 删除不作真正的删除,而是标记为删除
  114. 要同样注意 {状态更新, 刷新各类映射表}
  115. :return:
  116. """
  117. from apps.web.ad.views import deleteAd
  118. url = url_fn(deleteAd)
  119. assert manager_client.get(url).status_code == 405
  120. def test_taskList():
  121. pass
  122. test_ad_proxy_payload = {
  123. 'adId': 'dsafasf',
  124. 'adName': 'fsadsad',
  125. 'agentPrice': 0,
  126. 'dealerPrice': 0,
  127. 'price': 0,
  128. 'agentName': u'未命名代理商',
  129. 'dealerName': u'未知经销商',
  130. 'logicalCode': '18518',
  131. 'nickname': u'用户昵称',
  132. 'sex': u'男',
  133. 'openId': 'an open id',
  134. 'devType': u'洗衣机',
  135. 'address': u'地址',
  136. 'groupName': u'组名',
  137. #: filters
  138. 'groupId' : '34343dssffdf',
  139. 'dealerId' : '3224eo3jofo3o4o',
  140. 'agentId' : 'dsad2342423oe4jof',
  141. 'devNo' : '2321432rfdf',
  142. #: user actions
  143. 'clicks' : 1,
  144. 'shows' : 1,
  145. }
  146. def test_getBannerAd(banner_ad, device, wechat_user_client):
  147. from apps.web.ad.views import getBannerAd
  148. url = url_fn(getBannerAd)
  149. assert wechat_user_client.get(url(logicalCode=device['logicalCode'])).json()['payload'] == banner_ad.banner_config