Skip to content

Commit 0289e10

Browse files
committed
working test!
wordpress unmanaged models needs django_use_model marker see pytest-dev/pytest-django#310
1 parent 519d3a1 commit 0289e10

File tree

3 files changed

+37
-1
lines changed

3 files changed

+37
-1
lines changed

medios_libres/medios_libres/settings.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,8 @@
8888
'default': {
8989
'ENGINE': 'django.db.backends.sqlite3',
9090
'NAME': 'site.db',
91-
}
91+
'TEST': { 'NAME': 'test.db', }
92+
},
9293
}
9394

9495
# Password validation
@@ -128,3 +129,4 @@
128129
# https://docs.djangoproject.com/en/1.11/howto/static-files/
129130

130131
STATIC_URL = '/static/'
132+
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)