1
1
import requests
2
2
import json
3
3
import codecs
4
+ import docker
4
5
5
- IP = "192.168.178.70"
6
+
7
+ def get_ip_from_container (container_name , network ):
8
+ """
9
+ returns the ip of docker container
10
+ """
11
+
12
+ client = docker .DockerClient ()
13
+ container = client .containers .get (container_name )
14
+ return container .attrs ['NetworkSettings' ]['Networks' ][network ]['IPAddress' ]
15
+
16
+
17
+ API_IP = get_ip_from_container ("api" , "accesspointfingerprintapi_frontend" )
6
18
PORT = 5000
7
19
ENDPOINT = "fingerprint"
8
- URI = "http://" + IP + ":" + str (PORT ) + "/" + ENDPOINT
20
+ URI = "http://" + API_IP + ":" + str (PORT ) + "/" + ENDPOINT
9
21
HEADERS = {'Content-Type' : 'application/json' }
10
22
11
23
12
24
###########
13
- # GET #
25
+ # POST #
14
26
###########
15
27
16
28
17
- def test_get_fingerprint_should_return_200 ():
18
- assert requests .get (URI + "/test" ).status_code == 200
29
+ def test_post_fingerprint_should_return_201 ():
30
+ with codecs .open ('tests/test_fp.json' , 'r' , 'utf-8-sig' ) as json_file :
31
+ data = json .load (json_file )
19
32
33
+ assert requests .post (URI , json = data , headers = HEADERS ).status_code == 201
20
34
21
- def test_get_fingerprint_should_return_404 ():
22
- assert requests .get (URI + "/invalid" ).status_code == 404
23
35
36
+ def test_post_fingerprint_should_return_400 ():
37
+ assert requests .post (URI , json = {'some' : 'Data' }, headers = HEADERS ).status_code == 400
24
38
25
39
###########
26
- # POST #
40
+ # GET #
27
41
###########
28
42
29
43
30
- def test_post_fingerprint_should_return_201 ():
31
- with codecs .open ('test_fp.json' , 'r' , 'utf-8-sig' ) as json_file :
32
- data = json .load (json_file )
33
-
34
- assert requests .post (URI , data = json .dumps (data ), headers = HEADERS ).status_code == 201
44
+ def test_get_fingerprint_should_return_200 ():
45
+ assert requests .get (URI + "/test_id" ).status_code == 200
35
46
36
47
37
- def test_post_fingerprint_should_return_400 ():
38
- assert requests .post (URI , data = json . dumps ({ 'some' : 'Data' }), headers = HEADERS ) .status_code == 400
48
+ def test_get_fingerprint_should_return_404 ():
49
+ assert requests .get (URI + "/invalid" ) .status_code == 404
39
50
40
51
41
52
###########
@@ -44,27 +55,28 @@ def test_post_fingerprint_should_return_400():
44
55
45
56
46
57
def test_put_fingerprint_should_return_400 ():
47
- assert requests .post (URI + "/test_id" , data = json . dumps ( {'some' : 'Data' }) , headers = HEADERS ).status_code == 400
58
+ assert requests .put (URI + "/test_id" , json = {'some' : 'Data' }, headers = HEADERS ).status_code == 400
48
59
49
60
50
61
def test_put_fingerprint_should_return_404 ():
51
- assert requests .post (URI + "/invalid" , data = json . dumps ( {'some' : 'Data' }) , headers = HEADERS ).status_code == 400
62
+ assert requests .put (URI + "/invalid" , json = {'some' : 'Data' }, headers = HEADERS ).status_code == 404
52
63
53
64
54
- def test_put_fingerprint_should_return_200 ():
55
- with codecs .open ('test_fp.json' , 'r' , 'utf-8-sig' ) as json_file :
65
+ def test_put_fingerprint_should_return_201 ():
66
+ with codecs .open ('tests/ test_fp.json' , 'r' , 'utf-8-sig' ) as json_file :
56
67
data = json .load (json_file )
57
68
58
- assert requests .post (URI + "/test_id" , data = json .dumps (data ), headers = HEADERS ).status_code == 200
69
+ assert requests .put (URI + "/test_id" , json = data , headers = HEADERS ).status_code == 201
70
+
59
71
60
72
#############
61
73
# DELETE #
62
74
#############
63
75
64
76
65
- def test_delete_fingerprint_should_return_200 ():
66
- assert requests .post (URI + "/test_id" , data = json . dumps ({ 'some' : 'Data' }), headers = HEADERS ) .status_code == 200
77
+ def test_delete_fingerprint_should_return_201 ():
78
+ assert requests .delete (URI + "/test_id" ) .status_code == 201
67
79
68
80
69
81
def test_delete_fingerprint_should_return_404 ():
70
- assert requests .post (URI + "/test_id" , data = json . dumps ({ 'some' : 'Data' }), headers = HEADERS ).status_code == 404
82
+ assert requests .delete (URI + "/invalid" ).status_code == 404
0 commit comments