-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathtests.py
31 lines (24 loc) · 948 Bytes
/
tests.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
from unittest import TestCase
from nineapi.client import Client, APIException
import os
import sys
for var in ('NINEGAG_USERNAME', 'NINEGAG_PASSWORD'):
if var not in os.environ:
sys.stderr.write('ERROR: Environment variable {} is required for the tests to run.\n'.format(
var
))
sys.exit(1)
class APITest(TestCase):
def setUp(self):
self.client = Client()
self.username = os.environ['NINEGAG_USERNAME']
self.password = os.environ['NINEGAG_PASSWORD']
def test_log_in_good(self):
response = self.client.log_in(self.username, self.password)
self.assertEqual(response, True)
def test_log_in_bad(self):
self.assertRaises(APIException, lambda: self.client.log_in(self.username, self.password + 'wrong'))
def test_get_posts(self):
self.test_log_in_good()
posts = self.client.get_posts()
self.assertEqual(len(posts), 10)