3
3
from src .main .python .preponderous .viron .services .locationService import (
4
4
LocationService
5
5
)
6
+ from src .main .python .preponderous .viron .models .location import Location
6
7
7
8
service = LocationService ("http://localhost" , 9999 )
8
9
@@ -20,29 +21,26 @@ def test_get_base_url():
20
21
def test_get_all_locations (mock_get ):
21
22
mock_response = Mock ()
22
23
mock_response .json .return_value = [
23
- {'id ' : 1 },
24
- {'id ' : 2 }
24
+ {'location_id ' : 1 , 'x' : 10 , 'y' : 20 },
25
+ {'location_id ' : 2 , 'x' : 30 , 'y' : 40 }
25
26
]
26
27
mock_response .raise_for_status = Mock ()
27
28
mock_get .return_value = mock_response
28
29
29
30
locations = service .get_all_locations ()
30
31
31
32
assert len (locations ) == 2
32
- assert locations [0 ]['id' ] == 1
33
- assert locations [1 ]['id' ] == 2
34
33
mock_get .assert_called_with ("http://localhost:9999/api/v1/locations" )
35
34
36
35
@patch ('requests.get' )
37
36
def test_get_location_by_id (mock_get ):
38
37
mock_response = Mock ()
39
- mock_response .json .return_value = {'id ' : 1 }
38
+ mock_response .json .return_value = {'location_id ' : 1 , 'x' : 10 , 'y' : 20 }
40
39
mock_response .raise_for_status = Mock ()
41
40
mock_get .return_value = mock_response
42
41
43
42
location = service .get_location_by_id (1 )
44
43
45
- assert location ['id' ] == 1
46
44
mock_get .assert_called_with ("http://localhost:9999/api/v1/locations/1" )
47
45
48
46
@patch ('requests.get' )
@@ -58,46 +56,41 @@ def test_get_location_by_id_not_found(mock_get):
58
56
def test_get_locations_in_environment (mock_get ):
59
57
mock_response = Mock ()
60
58
mock_response .json .return_value = [
61
- {'id ' : 1 },
62
- {'id ' : 2 }
59
+ {'location_id ' : 1 , 'x' : 10 , 'y' : 20 },
60
+ {'location_id ' : 2 , 'x' : 30 , 'y' : 40 }
63
61
]
64
62
mock_response .raise_for_status = Mock ()
65
63
mock_get .return_value = mock_response
66
64
67
65
locations = service .get_locations_in_environment (1 )
68
66
69
67
assert len (locations ) == 2
70
- assert locations [0 ]['id' ] == 1
71
- assert locations [1 ]['id' ] == 2
72
68
mock_get .assert_called_with ("http://localhost:9999/api/v1/locations/environment/1" )
73
69
74
70
@patch ('requests.get' )
75
71
def test_get_locations_in_grid (mock_get ):
76
72
mock_response = Mock ()
77
73
mock_response .json .return_value = [
78
- {'id ' : 1 },
79
- {'id ' : 2 }
74
+ {'location_id ' : 1 , 'x' : 10 , 'y' : 20 },
75
+ {'location_id ' : 2 , 'x' : 30 , 'y' : 40 }
80
76
]
81
77
mock_response .raise_for_status = Mock ()
82
78
mock_get .return_value = mock_response
83
79
84
80
locations = service .get_locations_in_grid (1 )
85
81
86
82
assert len (locations ) == 2
87
- assert locations [0 ]['id' ] == 1
88
- assert locations [1 ]['id' ] == 2
89
83
mock_get .assert_called_with ("http://localhost:9999/api/v1/locations/grid/1" )
90
84
91
85
@patch ('requests.get' )
92
86
def test_get_location_of_entity (mock_get ):
93
87
mock_response = Mock ()
94
- mock_response .json .return_value = {'id ' : 1 }
88
+ mock_response .json .return_value = {'location_id ' : 1 , 'x' : 10 , 'y' : 20 }
95
89
mock_response .raise_for_status = Mock ()
96
90
mock_get .return_value = mock_response
97
91
98
92
location = service .get_location_of_entity (1 )
99
93
100
- assert location ['id' ] == 1
101
94
mock_get .assert_called_with ("http://localhost:9999/api/v1/locations/entity/1" )
102
95
103
96
@patch ('requests.put' )
0 commit comments