示例#1
0
    def test_mixed(self):

        aa = activity.ActiveArea({
            "start":
            "2014-05-25T17:00:00",
            "end":
            "2014-05-26T17:00:00",
            'specified_points': [{
                'area': 34,
                'lat': 45.0,
                'lng': -120.0
            }, {
                'area': 34,
                'lat': 44.0,
                'lng': -119.0
            }],
            'perimeter': {
                "polygon": [[-121.45, 47.43], [-121.39,
                                               47.43], [-121.39, 47.40],
                            [-121.45, 47.40], [-121.45, 47.43]]
            }
        })
        expected = [{
            'area': 34,
            'lat': 45.0,
            'lng': -120.0
        }, {
            'area': 34,
            'lat': 44.0,
            'lng': -119.0
        }]
        assert aa.locations == expected
        assert aa['locations'] == expected
示例#2
0
 def test_two_specified_points(self):
     aa = activity.ActiveArea({
         "start":
         "2014-05-25T17:00:00",
         "end":
         "2014-05-26T17:00:00",
         'specified_points': [{
             'area': 34,
             'lat': 45.0,
             'lng': -120.0
         }, {
             'area': 34,
             'lat': 44.0,
             'lng': -119.0
         }]
     })
     expected = [{
         'area': 34,
         'lat': 45.0,
         'lng': -120.0
     }, {
         'area': 34,
         'lat': 44.0,
         'lng': -119.0
     }]
     assert aa.locations == expected
     assert aa['locations'] == expected
示例#3
0
    def test_invalid_specified_points(self):
        # only point missing area
        aa = activity.ActiveArea({
            "start":
            "2014-05-25T17:00:00",
            "end":
            "2014-05-26T17:00:00",
            'specified_points': [
                {
                    'lat': 45.0,
                    'lng': -120.0
                },  # no area
            ]
        })
        with raises(ValueError) as e_info:
            aa.locations
        assert e_info.value.args[0] == activity.INVALID_LOCATION_MSGS[
            'specified_points']
        with raises(ValueError) as e_info:
            aa['locations']
        assert e_info.value.args[0] == activity.INVALID_LOCATION_MSGS[
            'specified_points']

        # one of two points missing area
        aa = activity.ActiveArea({
            "start":
            "2014-05-25T17:00:00",
            "end":
            "2014-05-26T17:00:00",
            'specified_points': [{
                'area': 34,
                'lat': 45.0,
                'lng': -120.0
            }, {
                'lat': 35.0,
                'lng': -121.0
            }]
        })
        with raises(ValueError) as e_info:
            aa.locations
        assert e_info.value.args[0] == activity.INVALID_LOCATION_MSGS[
            'specified_points']
        with raises(ValueError) as e_info:
            aa['locations']
        assert e_info.value.args[0] == activity.INVALID_LOCATION_MSGS[
            'specified_points']
示例#4
0
 def test_with_active_areas_but_no_locations(self):
     with raises(ValueError) as e_info:
         activity.ActivityCollection(active_areas=[
             activity.ActiveArea({
                 "start": "2014-05-25T17:00:00",
                 "end": "2014-05-26T17:00:00",
             })
         ]).locations
     assert e_info.value.args[
         0] == activity.ActiveArea.MISSING_LOCATION_INFO_MSG
示例#5
0
 def test_only_perimeter(self):
     aa = activity.ActiveArea({
         "start": "2014-05-27T17:00:00",
         "end": "2014-05-28T17:00:00",
         "perimeter": {
             "area":
             232,
             "polygon": [[-121.45, 47.43], [-121.39,
                                            47.43], [-121.39, 47.40],
                         [-121.45, 47.40], [-121.45, 47.43]]
         }
     })
     assert aa.total_area == 232
示例#6
0
 def test_one_specified_points(self):
     aa = activity.ActiveArea({
         "start":
         "2014-05-27T17:00:00",
         "end":
         "2014-05-28T17:00:00",
         'specified_points': [{
             'area': 34,
             'lat': 45.0,
             'lng': -120.0
         }]
     })
     assert aa.total_area == 34
示例#7
0
 def test_only_perimeter_no_area(self):
     with raises(ValueError) as e_info:
         activity.ActiveArea({
             "start": "2014-05-27T17:00:00",
             "end": "2014-05-28T17:00:00",
             "perimeter": {
                 "polygon": [[-121.45, 47.43], [-121.39, 47.43],
                             [-121.39, 47.40], [-121.45, 47.40],
                             [-121.45, 47.43]]
             }
         }).total_area
     assert e_info.value.args[
         0] == activity.ActiveArea.MISSING_OR_INVALID_AREA_FOR_PERIMIETER
示例#8
0
 def test_no_location_info(self):
     aa = activity.ActiveArea({
         "start": "2014-05-25T17:00:00",
         "end": "2014-05-26T17:00:00"
         # No location information
     })
     with raises(ValueError) as e_info:
         aa.locations
     assert e_info.value.args[
         0] == activity.ActiveArea.MISSING_LOCATION_INFO_MSG
     with raises(ValueError) as e_info:
         aa['locations']
     assert e_info.value.args[
         0] == activity.ActiveArea.MISSING_LOCATION_INFO_MSG
示例#9
0
 def test_specified_points_no_area(self):
     with raises(ValueError) as e_info:
         activity.ActiveArea({
             "start":
             "2014-05-25T17:00:00",
             "end":
             "2014-05-26T17:00:00",
             'specified_points': [
                 {
                     'lat': 45.0,
                     'lng': -120.0
                 },  # no area
             ]
         }).total_area
     assert e_info.value.args[
         0] == activity.ActiveArea.MISSING_OR_INVALID_AREA_FOR_SPECIFIED_POINT
示例#10
0
 def test_perimeter(self):
     aa = activity.ActiveArea({
         "start": "2014-05-25T17:00:00",
         "end": "2014-05-26T17:00:00",
         'perimeter': {
             "polygon": [[-121.45, 47.43], [-121.39,
                                            47.43], [-121.39, 47.40],
                         [-121.45, 47.40], [-121.45, 47.43]]
         }
     })
     expected = [{
         "polygon": [[-121.45, 47.43], [-121.39, 47.43], [-121.39, 47.40],
                     [-121.45, 47.40], [-121.45, 47.43]]
     }]
     assert aa.locations == expected
     assert aa['locations'] == expected
示例#11
0
 def test_invalid_perimeter(self):
     aa = activity.ActiveArea({
         "start": "2014-05-25T17:00:00",
         "end": "2014-05-26T17:00:00",
         'perimeter': {
             # missing polygon
             "foo": 123
         }
     })
     with raises(ValueError) as e_info:
         aa.locations
     assert e_info.value.args[0] == activity.INVALID_LOCATION_MSGS[
         'perimeter']
     with raises(ValueError) as e_info:
         aa['locations']
     assert e_info.value.args[0] == activity.INVALID_LOCATION_MSGS[
         'perimeter']
示例#12
0
 def test_one_specified_point(self):
     aa = activity.ActiveArea({
         "start":
         "2014-05-25T17:00:00",
         "end":
         "2014-05-26T17:00:00",
         'specified_points': [
             # Note that string area value will be cast to float
             {
                 'area': '34',
                 'lat': 45.0,
                 'lng': -120.0
             }
         ]
     })
     expected = [{'area': 34.0, 'lat': 45.0, 'lng': -120.0}]
     assert aa.locations == expected
     assert aa['locations'] == expected
示例#13
0
 def test_specified_points_and_perimeter(self):
     aa = activity.ActiveArea({
         "start":
         "2014-05-27T17:00:00",
         "end":
         "2014-05-28T17:00:00",
         'specified_points': [{
             'area': 34,
             'lat': 45.0,
             'lng': -120.0
         }, {
             'area': 20,
             'lat': 35.0,
             'lng': -121.0
         }],
         "perimeter": {
             "area":
             232,
             "polygon": [[-121.45, 47.43], [-121.39,
                                            47.43], [-121.39, 47.40],
                         [-121.45, 47.40], [-121.45, 47.43]]
         }
     })
     assert aa.total_area == 54