-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
187 additions
and
58 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
# RandTalkBot Bot matching you with a random person on Telegram. | ||
# Copyright (C) 2018 quasiyoke | ||
# | ||
# You should have received a copy of the GNU Affero General Public License | ||
# along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
|
||
import datetime | ||
import logging | ||
import asynctest | ||
from asynctest.mock import patch, CoroutineMock | ||
from telepot_testing import assert_sent_message, receive_message | ||
from .helpers import assert_db, finalize, run, patch_telepot | ||
|
||
LOGGER = logging.getLogger('tests.test_chat_lifecycle') | ||
STRANGER1_2 = { | ||
'id': 12, | ||
'invitation': 'bar_invitation', | ||
'languages': '["en"]', | ||
'partner_sex': 'not_specified', | ||
'sex': 'not_specified', | ||
'telegram_id': 120, | ||
} | ||
STRANGER1_1 = { | ||
'id': 11, | ||
'invitation': 'foo_invitation', | ||
'languages': '["en"]', | ||
'partner_sex': 'not_specified', | ||
'sex': 'not_specified', | ||
'telegram_id': 110, | ||
} | ||
STRANGER2_1 = { | ||
'id': 21, | ||
'invitation': '21_invitation', | ||
'languages': '["en"]', | ||
'looking_for_partner_from': datetime.datetime(1970, 1, 1), | ||
'partner_sex': 'female', | ||
'sex': 'not_specified', | ||
'telegram_id': 210, | ||
} | ||
TALK1 = { | ||
'id': 1, | ||
'partner1_id': STRANGER1_1['id'], | ||
'partner1_sent': 0, | ||
'partner2_id': STRANGER1_2['id'], | ||
'partner2_sent': 1, | ||
'searched_since': datetime.datetime(1970, 1, 1) | ||
} | ||
|
||
class TestChatLifecycle(asynctest.TestCase): | ||
@patch_telepot | ||
def setUp(self): | ||
run(self, { | ||
'strangers': [STRANGER1_1, STRANGER1_2, STRANGER2_1], | ||
'talks': [], | ||
}) | ||
|
||
def tearDown(self): | ||
finalize(self) | ||
|
||
@patch('randtalkbot.stranger.StatsService') | ||
async def test_unsuccessful_search(self, stats_service_mock): | ||
from randtalkbot.stranger import asyncio as asyncio_mock | ||
stats_service_mock.get_instance \ | ||
.return_value \ | ||
.get_stats \ | ||
.return_value \ | ||
.get_sex_ratio \ | ||
.return_value = 0.9 | ||
|
||
with patch('randtalkbot.stranger.asyncio.sleep', CoroutineMock()): | ||
receive_message(STRANGER1_1['telegram_id'], '/begin') | ||
await assert_sent_message( | ||
STRANGER1_1['telegram_id'], | ||
'*Rand Talk:* Looking for a stranger for you 🤔', | ||
) | ||
assert_db({ | ||
'strangers': [ | ||
{ | ||
'id': STRANGER1_1['id'], | ||
'looking_for_partner_from': datetime.datetime.utcnow() | ||
}, | ||
], | ||
}) | ||
LOGGER.debug('Check calling %s', asyncio_mock.sleep) | ||
asyncio_mock.sleep.assert_called_once_with(30) | ||
|
||
await assert_sent_message( | ||
STRANGER1_1['telegram_id'], | ||
'*Rand Talk:* The search is going on. 2 users are looking for partner — change your' | ||
' preferences (languages, partner\'s sex) using /setup command to talk with' | ||
' them.\n' | ||
'Chat *lacks females!* Send the link to your friends and earn 3 bonuses for' | ||
' every invited female and 1 bonus for each male (the more bonuses you' | ||
' have → the faster partner\'s search will be):', | ||
disable_notification=True, | ||
) | ||
await assert_sent_message( | ||
STRANGER1_1['telegram_id'], | ||
'*Rand Talk:* Do[\u2009](http://randtalk.ml/static/img/logo-125x125.png) you want' | ||
' to talk with somebody, practice in foreign languages or you just' | ||
' want to have some fun? Rand Talk will help you! It\'s a bot matching you' | ||
' with a random stranger of desired sex speaking on your language. [Check it out!]' | ||
'(https://telegram.me/RandTalkBot?start=eyJpIjoiZm9vX2ludml0YXRpb24ifQ==)', | ||
disable_notification=True, | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters