11import pytest
2- import sqlite3
32import unittest
43import requests
54
6- from pygmy .config import config
75from pygmyui .restclient .base import Client
86
97
@@ -22,14 +20,14 @@ def teardown_class(cls):
2220 pass
2321
2422 def teardown_method (self , _ ):
23+ # self.conn = sqlite3.connect(config.database['url'])
24+ # self.cur = self.conn.cursor()
25+ # tables = ['clickmeta', 'link', 'user']
26+ # for table in tables:
27+ # self.cur.execute('DELETE FROM {}'.format(table))
28+ # self.conn.commit()
29+ # self.conn.close()
2530 return
26- self .conn = sqlite3 .connect (config .database ['url' ])
27- self .cur = self .conn .cursor ()
28- tables = ['clickmeta' , 'link' , 'user' ]
29- for table in tables :
30- self .cur .execute ('DELETE FROM {}' .format (table ))
31- self .conn .commit ()
32- self .conn .close ()
3331
3432 def setup_method (self , _ ):
3533 self ._token = None
@@ -235,13 +233,34 @@ def test_non_loggedin_dashboard(self):
235233
236234 def test_check_link_availability (self ):
237235 custom_code = 'logo'
238- requests .get (self .url + '/check?custom_code={}' .format (custom_code ), 200 )
236+ response = requests .get (self .url + '/check?custom_code={}' .format (custom_code ))
237+ self .assertEqual (response .status_code , 200 )
238+ self .assertTrue (response .json ().get ('ok' ))
239239
240240 def test_custom_taken_link_availability (self ):
241- pass
241+ custom_code = 'logo'
242+ response = requests .get (self .url + '/check?custom_code={}' .format (custom_code ))
243+ self .assertTrue (response .json ().get ('ok' ))
244+ data = self .data
245+ data ['custom_url' ] = custom_code
246+ requests .post (self .url + '/shorten' , data = data , headers = self .headers )
247+ response = requests .get (self .url + '/check?custom_code={}' .format (custom_code ))
248+ self .assertFalse (response .json ().get ('ok' ))
242249
243250 def test_custom_taken_link_shorten (self ):
244- pass
251+ custom_code = 'go'
252+ response = requests .get (self .url + '/check?custom_code={}' .format (custom_code ))
253+ self .assertTrue (response .json ().get ('ok' ))
254+
255+ data = self .data
256+ data ['custom_url' ] = custom_code
257+ requests .post (self .url + '/shorten' , data = data , headers = self .headers )
258+
259+ response = requests .get (self .url + '/check?custom_code={}' .format (custom_code ))
260+ self .assertFalse (response .json ().get ('ok' ))
261+
262+ response = requests .post (self .url + '/shorten' , data = data , headers = self .headers )
263+ self .assertEqual (response .status_code , 400 )
245264
246265 def test_custom_links (self ):
247266 data = self .data
0 commit comments