File: test_GeoIP.py

package info (click to toggle)
weakforced 3.0.0-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 3,040 kB
  • sloc: cpp: 20,397; python: 2,002; sh: 700; makefile: 432
file content (36 lines) | stat: -rw-r--r-- 1,082 bytes parent folder | download
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
32
33
34
35
36
import requests
import socket
import time
import json
import os
from test_helper import ApiTestCase

class TestGeoIP(ApiTestCase):
    def setUp(self):
        super(TestGeoIP, self).setUp()
        
    def test_geoIP(self):
        # don't allow IPs from Japan (arbitrary)
        r = self.allowFunc('baddie', '112.78.112.20', "1234")
        j = r.json()
        self.assertEqual(j['status'], -1)
        self.assertRegex(json.dumps(j), "Japan")
        r.close()

    def test_geoIP2City(self):
        attrs = dict()
        attrs['ip'] = '128.243.1.1'
        r = self.customFuncWithName("geoip2", attrs)
        j = r.json()
        self.assertRegex(json.dumps(j), "Nottingham")
        r.close()

    def test_geoIP2LookupVals(self):
        attrs = dict()
        attrs['ip'] = '128.243.21.1'
        r = self.customFuncWithName("geoip2_lookupValue", attrs)
        j = r.json()
        print(json.dumps(j))
        self.assertRegex(json.dumps(j['r_attrs']['city']), "Nottingham")
        self.assertRegex(json.dumps(j['r_attrs']['latitude']), "52.9044")
        r.close()