def test_custom_config_loc_desnt_exist(self): with self.assertRaises(ConfigError) as em: config_loc = 'bla.ini' get_config(config_loc=config_loc) self.assertEqual( str(em.exception), "Config file doesn't exists {}".format(config_loc))
def test_invalid_api_url_schema(self): value = 'stf://localhost' self.write_config(conf={'api': value}) with self.assertRaises(ConfigError) as em: get_config() self.assertEqual(str(em.exception), "Only http and https are supported for api")
def test_field_not_int(self): value = 'adsads' for key in ['users', 'posts', 'likes']: self.write_config(conf={key: value}) with self.assertRaises(ConfigError) as em: get_config() self.assertEqual( str(em.exception), "{} value is not valid number: {}".format(key, value))
def test_field_not_in_range(self): value = 123123123 for key in ['users', 'posts', 'likes']: self.write_config(conf={key: value}) with self.assertRaises(ConfigError) as em: get_config() self.assertEqual( str(em.exception), "{} value should be in range 1-100, value: {}".format( key, value))
def test_default_config_loc(self): self.write_config() config = get_config() self.assertEqual(config.api, 'http://localhost') self.assertEqual(config.users, 3) self.assertEqual(config.posts, 5) self.assertEqual(config.likes, 1)
def test_custom_config_loc_exist(self): config_loc = 'bla.ini' self.write_config(config_loc) config = get_config(config_loc=config_loc) self.assertEqual(config.api, 'http://localhost') self.assertEqual(config.users, 3) self.assertEqual(config.posts, 5) self.assertEqual(config.likes, 1)
passwords.get(user.username)) posts = self.get_posts(user.id) logging.warning("There are %s posts with 0 vote user can like" % len(posts)) if not posts: logging.warning("Liking is finished") break for k in range(random.randint(1, int(self.max_likes_per_user))): current_post = random.choice(posts) res = RequestClient.authenticated_request(url=self.get_url( '{}{}{}'.format(self.options["CREATE_POST"], current_post.id, '/vote')), token=token) logging.warning("User liked post %s", current_post.id) posts.exclude(id=current_post.id) def run(self): passwords = self.start_activity() self.perform_likes(passwords) if __name__ == "__main__": path = "settings.ini" from bot.config import get_config bot = get_config() bot.run()