def tearDownClass(cls): setting = Setting.instance() setting.delete_user('test_username') try: shutil.rmtree('./sessions') except: # already deleted in delete_user pass Setting.destroy_instance()
def test_save_setting(self): settings = Setting.instance() settings.set_active_user('test_username') settings.set('account_id', 'test_account_id') settings.set('devicestring', 'test_devicestring') loaded_settings = settings.load_user_settings() self.assertEqual(loaded_settings['account_id'], 'test_account_id') self.assertEqual(loaded_settings['devicestring'], 'test_devicestring')
def test_setting_with_invalid_options(self): with self.assertRaises(SettingsException): Setting.create_instance('file', {})
def test_setting_with_no_handler(self): with self.assertRaises(SettingsException): Setting.instance()
def test_delete_user(self): Setting.create_instance('file', { 'base_directory': './sessions', }) settings = Setting.instance() settings.delete_user('test_username')
def test_save_invalid_key(self): settings = Setting.instance() settings.set_active_user('test_username') with self.assertRaises(SettingsException): settings.set('invalid_key', 'invalid_value')
def test_call_load_user_setting_before_set_active_user(self): settings = Setting.instance() with self.assertRaises(SettingsException): settings.set('some_key', 'some value')
def test_new_setting(self): setting = Setting.instance() setting.set_active_user('test_username') self.assertIsNotNone(setting)
def test_illegal_way_to_make_instance(self): with self.assertRaises(SettingsException): Setting()
def setUpClass(cls): Setting.create_instance('file', { 'base_directory': './sessions', })
""" make a settings.py file. # filename: settings.py username = '******' password = '******' """ from __future__ import unicode_literals, print_function from pyinstagram.instagram import Instagram from pyinstagram.setting import Setting from settings import username, password Setting.create_instance('file', {'base_directory': './sessions'}) instagram = Instagram(Setting.instance()) instagram.set_user(username, password) instagram.login() print('instagram', instagram)
def setUp(self): # a new Instagram instance for every test methods self.instagram = Instagram(Setting.instance())
def tearDownClass(cls): Setting.instance().delete_user('testuser') os.removedirs('./sessions')