Skip to content

Commit be64e77

Browse files
committed
working test!
wordpress unmanaged models needs django_use_model marker see pytest-dev/pytest-django#310
1 parent 89a37e1 commit be64e77

File tree

3 files changed

+35
-0
lines changed

3 files changed

+35
-0
lines changed

medios_libres/medios_libres/settings.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,3 +123,4 @@
123123
# https://docs.djangoproject.com/en/1.11/howto/static-files/
124124

125125
STATIC_URL = '/static/'
126+
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import os
2+
import django
3+
from django.conf import settings
4+
5+
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'medios_libres.settings')
6+
7+
def pytest_configure():
8+
# settings.DEBUG = False
9+
settings.IS_TESTING = True
10+
django.setup()
11+
12+
# FIXTURES
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import pytest
2+
import telebot
3+
from telebot import types
4+
from medios_libres.models import MediosBot, WpPosts
5+
6+
class TestMediosBot:
7+
8+
@pytest.mark.django_db(transaction=True)
9+
@pytest.mark.django_use_model(model=WpPosts)
10+
def test_receive_text_message(self):
11+
medios = MediosBot('')
12+
cmd = self.create_text_message('/publicar algo')
13+
medios.bot.process_new_messages([cmd])
14+
assert WpPosts.objects.count() == 1
15+
16+
# HELPERS
17+
18+
def create_text_message(self, text):
19+
params = {'text': text}
20+
chat = types.User(11, False, 'test')
21+
#(self, message_id, from_user, date, chat, content_type, options, json_string)
22+
return types.Message(1, None, None, chat, 'text', params)

0 commit comments

Comments
 (0)