def test_cwd_internal(self): tmpdir = self.tmpfile.mkdtemp() set_cwd(tmpdir) p = cwd("conf", "socks5man.conf", internal=True) p2 = os.path.join( socks5man.__path__[0], "setupdata", "conf", "socks5man.conf" ) assert p == p2
def test_ipv4info_invalid(self): tmppath = self.tempfile.mkdtemp() set_cwd(tmppath) create_cwd(tmppath) geo = GeoInfo() res = geo.ipv4info("8adna87dasd87asd") assert res["country"] == "unknown" assert res["country_code"] == "unknown" assert res["city"] == "unknown"
def test_ipv4info_unknown(self): tmppath = self.tempfile.mkdtemp() set_cwd(tmppath) create_cwd(tmppath) geo = GeoInfo() res = geo.ipv4info("10.0.0.5") assert res["country"] == "unknown" assert res["country_code"] == "unknown" assert res["city"] == "unknown"
def test_ipv4info(self): tmppath = self.tempfile.mkdtemp() set_cwd(tmppath) create_cwd(tmppath) geo = GeoInfo() res = geo.ipv4info("93.184.216.34") assert res["country"] == "United States" assert res["country_code"] == "US" assert res["city"] == "Norwell"
def test_init_logger(my, mr): tmpdir = tempfile.mkdtemp() set_cwd(tmpdir) assert not os.path.exists(os.path.join(tmpdir, "socks5man.log")) init_loggers(logging.DEBUG) log.error("TEST") log.warning("TEST") assert os.path.isfile(os.path.join(tmpdir, "socks5man.log")) my.assert_called_once() mr.assert_called_once()
def test_create_cwd(self): tmpdir = self.tmpfile.mkdtemp() set_cwd(tmpdir) assert os.listdir(tmpdir) == [] create_cwd(tmpdir) assert os.path.isfile(os.path.join(tmpdir, "conf", "socks5man.conf")) assert os.path.isfile( os.path.join(tmpdir, "geodb", "extracted", "geodblite.mmdb") ) assert os.path.isfile(os.path.join(tmpdir, "geodb", ".version")) assert os.path.exists( os.path.join(tmpdir, "geodb", "geodblite.tar.gz") )
def test_unpack_mmdb(self): tmpdir = self.tempfile.mkdtemp() set_cwd(tmpdir) tar_p = cwd("geodb", "geodblite.tar.gz", internal=True) assert os.listdir(tmpdir) == [] os.mkdir(os.path.join(tmpdir, "geodb")) mmdb_p = os.path.join(tmpdir, "test.mmdb") unpack_mmdb(tarpath=tar_p, to=mmdb_p) assert os.path.isfile(mmdb_p) version_file = os.path.join(tmpdir, "geodb", ".version") assert os.path.isfile(version_file) assert md5(tar_p) == open(version_file, "rb").read() r = geodatabase.Reader(mmdb_p) geodata = r.city("8.8.8.8") assert geodata.country.name.lower() == "united states"
def setup(self): set_cwd(self.tempfile.mkdtemp())
def setup(self): set_cwd(self.tempfile.mkdtemp()) self.db = Database() self.db.connect(create=True)
def setup(self): set_cwd(self.tempfile.mkdtemp()) self.db = Database() self.db.connect(create=True) Config._cache = {} self.confbackup = copy.deepcopy(Config._conf)
def setup(self): set_cwd(self.tempfile.mkdtemp()) self.db = Database() self.db.connect(create=True)
def setup(self): set_cwd(self.tempfile.mkdtemp())
def test_cwd_nonexist(self, mc): tempdir = os.path.join(tempfile.gettempdir(), "UTvYHUvitYV") set_cwd(tempdir) cwd("test") mc.assert_called_once()
def test_cwd_normal(self): tmpdir = self.tmpfile.mkdtemp() set_cwd(tmpdir) assert cwd("conf") == os.path.join(tmpdir, "conf")
def test_set_cwd(self): tmpdir = self.tmpfile.mkdtemp() set_cwd(tmpdir) from socks5man.misc import _path assert _path == tmpdir