X Tutup
Skip to content

Commit 61ef876

Browse files
committed
Much better, such wow Contact tests
1 parent 060442e commit 61ef876

File tree

1 file changed

+78
-0
lines changed

1 file changed

+78
-0
lines changed

tests/test_contact.py

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
#!/usr/bin/env python
2+
#
3+
# A library that provides a Python interface to the Telegram Bot API
4+
# Copyright (C) 2015 Leandro Toledo de Souza <leandrotoeldodesouza@gmail.com>
5+
#
6+
# This program is free software: you can redistribute it and/or modify
7+
# it under the terms of the GNU General Public License as published by
8+
# the Free Software Foundation, either version 3 of the License, or
9+
# (at your option) any later version.
10+
#
11+
# This program is distributed in the hope that it will be useful,
12+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
13+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14+
# GNU General Public License for more details.
15+
#
16+
# You should have received a copy of the GNU General Public License
17+
# along with this program. If not, see [http://www.gnu.org/licenses/].
18+
19+
"""This module contains a object that represents Tests for Telegram Contact"""
20+
21+
import os
22+
import unittest
23+
import sys
24+
sys.path.append('.')
25+
26+
import telegram
27+
from tests.base import BaseTest
28+
29+
30+
class ContactTest(BaseTest, unittest.TestCase):
31+
"""This object represents Tests for Telegram Contact."""
32+
33+
def setUp(self):
34+
self.phone_number = '+11234567890'
35+
self.first_name = 'Leandro Toledo'
36+
self.last_name = ''
37+
self.user_id = 0
38+
39+
self.json_dict = {
40+
'phone_number': self.phone_number,
41+
'first_name': self.first_name,
42+
'last_name': self.last_name,
43+
'user_id': self.user_id
44+
}
45+
46+
def test_contact_de_json(self):
47+
"""Test Contact.de_json() method"""
48+
print('Testing Contact.de_json()')
49+
50+
contact = telegram.Contact.de_json(self.json_dict)
51+
52+
self.assertEqual(contact.phone_number, self.phone_number)
53+
self.assertEqual(contact.first_name, self.first_name)
54+
self.assertEqual(contact.last_name, self.last_name)
55+
self.assertEqual(contact.user_id, self.user_id)
56+
57+
def test_contact_to_json(self):
58+
"""Test Contact.to_json() method"""
59+
print('Testing Contact.to_json()')
60+
61+
contact = telegram.Contact.de_json(self.json_dict)
62+
63+
self.assertTrue(self.is_json(contact.to_json()))
64+
65+
def test_contact_to_dict(self):
66+
"""Test Contact.to_dict() method"""
67+
print('Testing Contact.to_dict()')
68+
69+
contact = telegram.Contact.de_json(self.json_dict)
70+
71+
self.assertTrue(self.is_dict(contact.to_dict()))
72+
self.assertEqual(contact['phone_number'], self.phone_number)
73+
self.assertEqual(contact['first_name'], self.first_name)
74+
self.assertEqual(contact['last_name'], self.last_name)
75+
self.assertEqual(contact['user_id'], self.user_id)
76+
77+
if __name__ == '__main__':
78+
unittest.main()

0 commit comments

Comments
 (0)
X Tutup