def test_get_available_assets_pass_asset_id(self):
     """ ignore other filters and return single asset info
     """
     req = FakeRequest()
     req.GET = {'asset_id': '1', 'project_id': '2', 'tagids': '2,3'}
     expected = {
         'number_of_assets': {
             'audio': 1, 'photo': 0, 'text': 0, 'video': 0
         },
         'assets': [dict(self.ASSET_1.items() +
                         self.ASSET_1_TAGS_EN.items())]
     }
     self.assertEquals(expected, get_available_assets(req))
 def test_get_available_assets_kwargs_must_all_be_satisfied(self):
     """ assets returned must match all valid kwargs passed
     """
     req = FakeRequest()
     req.GET = {'project_id': '12', 'audiolength': '5000000',
                'volume': '1.0'}
     expected = {
         'number_of_assets': {
             'audio': 0, 'photo': 0, 'text': 0, 'video': 0
         },
         'assets': []
     }
     self.assertEquals(expected, get_available_assets(req))
 def test_get_available_assets_pass_extra_kwarg_with_asset_id(self):
     """ extra kwargs should get ignored if we ask for an asset_id
     """
     req = FakeRequest()
     req.GET = {'asset_id': '2', 'audiolength': '5000000'}
     expected = {
         'number_of_assets': {
             'audio': 1, 'photo': 0, 'text': 0, 'video': 0
         },
         'assets': [dict(self.ASSET_2.items() +
                         self.ASSET_2_TAGS_ES.items())]
     }
     self.assertEquals(expected, get_available_assets(req))
 def test_get_available_assets_pass_extra_kwarg(self):
     """ extra kwargs should provide extra filter 
     """
     req = FakeRequest()
     req.GET = {'project_id': '12', 'audiolength': '5000000'}
     expected = {
         'number_of_assets': {
             'audio': 1, 'photo': 0, 'text': 0, 'video': 0
         },
         'assets': [dict(self.ASSET_1.items() +
                         self.ASSET_1_TAGS_EN.items())]
     }
     self.assertEquals(expected, get_available_assets(req))
 def test_get_available_assets_pass_language(self):
     """make sure tag localized messages are returned in passed
        language
     """
     req = FakeRequest()
     req.GET = {'asset_id': '1', 'tagids': '2,3', 'language': 'es'}
     expected = {
         'number_of_assets': {
             'audio': 1, 'photo': 0, 'text': 0, 'video': 0
         },
         'assets': [dict(self.ASSET_1.items() +
                         self.ASSET_1_TAGS_ES.items())]
     }
     self.assertEquals(expected, get_available_assets(req))
 def test_get_available_assets_invalid_kwarg_does_no_harm(self):
     """ an extra kwarg in request that isn't a field on the Asset model
         doesn't have any effect
     """
     req = FakeRequest()
     req.GET = {'asset_id': '2', 'foo': 'bar'}
     expected = {
         'number_of_assets': {
             'audio': 1, 'photo': 0, 'text': 0, 'video': 0
         },
         'assets': [dict(self.ASSET_2.items() +
                         self.ASSET_2_TAGS_ES.items())]
     }
     self.assertEquals(expected, get_available_assets(req))
    def test_get_available_assets_pass_project_id(self):
        req = FakeRequest()
        req.GET = {'project_id': '12'}
        expected = {
            'number_of_assets': {
                'audio': 2, 'photo': 0, 'text': 0, 'video': 0
            },
            'assets': [dict(self.ASSET_1.items() +
                            self.ASSET_1_TAGS_EN.items()),

                       dict(self.ASSET_2.items() +
                            self.ASSET_2_TAGS_ES.items()),
                       ]
        }
        self.assertEquals(expected, get_available_assets(req))
    def test_get_available_assets_pass_lat_long_far(self):
        """ with mocked gpsmixer.distance_in_meters to always return a
        distance of 0 meters, we should get all assets when a latitude
        and longitude are specified
        """
        req = FakeRequest()
        req.GET = {'latitude': '0.1', 'longitude': '0.1', 'project_id': '12'}
        expected = {
            'number_of_assets': {
                'audio': 0, 'photo': 0, 'text': 0, 'video': 0

            },
            'assets': []
        }
        self.assertEquals(expected, get_available_assets(req))
 def test_request_language_trumps_asset_language(self):
     """ asset2 is in Spanish.  request for English returns tag
     localized message in English.
     """
     req = FakeRequest()
     req.GET = {'asset_id': '2', 'language': 'en'}
     expected = {
         'number_of_assets': {
             'audio': 1, 'photo': 0, 'text': 0, 'video': 0
         },
         'assets': [dict(self.ASSET_2.items() +
                         self.ASSET_2_TAGS_EN.items()),
                    ]
     }
     self.assertEquals(expected, get_available_assets(req))
示例#10
0
 def test_get_available_assets_pass_project_id(self):
     req = FakeRequest()
     req.GET = {'project_id': '12'}
     expected = {
         'number_of_assets': {
             'audio': 2,
             'photo': 0,
             'text': 0,
             'video': 0
         },
         'assets': [
             dict(self.ASSET_1.items() + self.ASSET_1_TAGS_EN.items()),
             dict(self.ASSET_2.items() + self.ASSET_2_TAGS_ES.items()),
         ]
     }
     self.assertEquals(expected, get_available_assets(req))
示例#11
0
 def test_get_available_assets_pass_tag_ids_with_and(self):
     """ test assets returned have both tags if no tagbool of 'or'
         passed.
     """
     req = FakeRequest()
     req.GET = {'tagids': '1,2', 'project_id': '12'}
     expected = {
         'number_of_assets': {
             'audio': 0,
             'photo': 0,
             'text': 0,
             'video': 0
         },
         'assets': []
     }
     self.assertEquals(expected, get_available_assets(req))
示例#12
0
 def test_get_available_assets_pass_extra_kwarg_with_asset_id(self):
     """ extra kwargs should get ignored if we ask for an asset_id
     """
     req = FakeRequest()
     req.GET = {'asset_id': '2', 'audiolength': '5000000'}
     expected = {
         'number_of_assets': {
             'audio': 1,
             'photo': 0,
             'text': 0,
             'video': 0
         },
         'assets':
         [dict(self.ASSET_2.items() + self.ASSET_2_TAGS_ES.items())]
     }
     self.assertEquals(expected, get_available_assets(req))
示例#13
0
 def test_get_available_assets_pass_extra_kwarg(self):
     """ extra kwargs should provide extra filter 
     """
     req = FakeRequest()
     req.GET = {'project_id': '12', 'audiolength': '5000000'}
     expected = {
         'number_of_assets': {
             'audio': 1,
             'photo': 0,
             'text': 0,
             'video': 0
         },
         'assets':
         [dict(self.ASSET_1.items() + self.ASSET_1_TAGS_EN.items())]
     }
     self.assertEquals(expected, get_available_assets(req))
示例#14
0
    def test_get_available_assets_pass_radius(self):
        """project's radius is bigger than the mock near distance.  
        should get no assets if we pass a radius of 0, overriding
        project radius.
        """
        req = FakeRequest()
        req.GET = {'radius': '0', 'project_id': '12',
                   'latitude': '0.1', 'longitude': '0.1'}
        expected = {
            'number_of_assets': {
                'audio': 0, 'photo': 0, 'text': 0, 'video': 0

            },
            'assets': []
        }
        self.assertEquals(expected, get_available_assets(req))
示例#15
0
 def test_get_available_assets_pass_tag_ids_with_and(self):
     """ test assets returned have both tags if no tagbool of 'or'
         passed.
     """
     req = FakeRequest()
     req.GET = {'tagids': '1,2', 'project_id': '12'}
     expected = {
         'number_of_assets': {
             'audio': 0,
             'photo': 0,
             'text': 0,
             'video': 0
         },
         'assets': []
     }
     self.assertEquals(expected, get_available_assets(req))
示例#16
0
 def test_get_available_assets_pass_asset_id(self):
     """ ignore other filters and return single asset info
     """
     req = FakeRequest()
     req.GET = {'asset_id': '1', 'project_id': '2', 'tagids': '2,3'}
     expected = {
         'number_of_assets': {
             'audio': 1,
             'photo': 0,
             'text': 0,
             'video': 0
         },
         'assets':
         [dict(self.ASSET_1.items() + self.ASSET_1_TAGS_EN.items())]
     }
     self.assertEquals(expected, get_available_assets(req))
示例#17
0
 def test_get_available_assets_invalid_kwarg_does_no_harm(self):
     """ an extra kwarg in request that isn't a field on the Asset model
         doesn't have any effect
     """
     req = FakeRequest()
     req.GET = {'asset_id': '2', 'foo': 'bar'}
     expected = {
         'number_of_assets': {
             'audio': 1,
             'photo': 0,
             'text': 0,
             'video': 0
         },
         'assets':
         [dict(self.ASSET_2.items() + self.ASSET_2_TAGS_ES.items())]
     }
     self.assertEquals(expected, get_available_assets(req))
示例#18
0
 def test_get_available_assets_pass_lat_long_far(self):
     """ with mocked gpsmixer.distance_in_meters to always return a
     distance of 0 meters, we should get all assets when a latitude
     and longitude are specified
     """
     req = FakeRequest()
     req.GET = {'latitude': '0.1', 'longitude': '0.1', 'project_id': '12'}
     expected = {
         'number_of_assets': {
             'audio': 0,
             'photo': 0,
             'text': 0,
             'video': 0
         },
         'assets': []
     }
     self.assertEquals(expected, get_available_assets(req))
示例#19
0
    def test_get_available_assets_pass_multiple_asset_ids(self):
        """ ignore other filters and return assets matching ids passed
        """
        req = FakeRequest()
        req.GET = {'asset_id': '1,2', 'project_id': '2', 'tagids': '2,3'}
        expected = {
            'number_of_assets': {
                'audio': 2, 'photo': 0, 'text': 0, 'video': 0
            },
            'assets': [dict(self.ASSET_1.items() +
                            self.ASSET_1_TAGS_EN.items()),

                       dict(self.ASSET_2.items() +
                            self.ASSET_2_TAGS_ES.items()),
                       ]
        }
        self.assertEquals(expected, get_available_assets(req))
示例#20
0
 def test_get_available_assets_pass_bad_envelope(self):
     """ ignore other filters and return asset info for 
         assets in envelopes, ignoring bad envelope id.
     """
     req = FakeRequest()
     req.GET = {'envelope_id': '1,2,3', 'project_id': '2', 'tagids': '2,3'}
     expected = {
         'number_of_assets': {
             'audio': 2, 'photo': 0, 'text': 0, 'video': 0
         },
         'assets': [dict(self.ASSET_1.items() +
                         self.ASSET_1_TAGS_EN.items()),
                    dict(self.ASSET_2.items() +
                         self.ASSET_2_TAGS_ES.items())
                    ]
     }
     self.assertEquals(expected, get_available_assets(req))
示例#21
0
 def test_get_available_assets_pass_language(self):
     """make sure tag localized messages are returned in passed
        language
     """
     req = FakeRequest()
     req.GET = {'asset_id': '1', 'tagids': '2,3', 'language': 'es'}
     expected = {
         'number_of_assets': {
             'audio': 1,
             'photo': 0,
             'text': 0,
             'video': 0
         },
         'assets':
         [dict(self.ASSET_1.items() + self.ASSET_1_TAGS_ES.items())]
     }
     self.assertEquals(expected, get_available_assets(req))
示例#22
0
    def test_get_available_assets_pass_tag_ids_with_or(self):
        """ test assets returned only need match one of passed tags 
        """
        req = FakeRequest()
        req.GET = {'tagids': '1,2', 'project_id': '12', 'tagbool': 'or'}
        expected = {
            'number_of_assets': {
                'audio': 2, 'photo': 0, 'text': 0, 'video': 0

            },
            'assets': [dict(self.ASSET_1.items() +
                            self.ASSET_1_TAGS_EN.items()),
                       dict(self.ASSET_2.items() +
                            self.ASSET_2_TAGS_ES.items())
                       ]
        }
        self.assertEquals(expected, get_available_assets(req))
示例#23
0
 def test_request_language_trumps_asset_language(self):
     """ asset2 is in Spanish.  request for English returns tag
     localized message in English.
     """
     req = FakeRequest()
     req.GET = {'asset_id': '2', 'language': 'en'}
     expected = {
         'number_of_assets': {
             'audio': 1,
             'photo': 0,
             'text': 0,
             'video': 0
         },
         'assets': [
             dict(self.ASSET_2.items() + self.ASSET_2_TAGS_EN.items()),
         ]
     }
     self.assertEquals(expected, get_available_assets(req))
示例#24
0
 def test_get_available_assets_pass_tag_ids_with_or(self):
     """ test assets returned only need match one of passed tags 
     """
     req = FakeRequest()
     req.GET = {'tagids': '1,2', 'project_id': '12', 'tagbool': 'or'}
     expected = {
         'number_of_assets': {
             'audio': 2,
             'photo': 0,
             'text': 0,
             'video': 0
         },
         'assets': [
             dict(self.ASSET_1.items() + self.ASSET_1_TAGS_EN.items()),
             dict(self.ASSET_2.items() + self.ASSET_2_TAGS_ES.items())
         ]
     }
     self.assertEquals(expected, get_available_assets(req))
示例#25
0
 def test_get_available_assets_pass_multiple_asset_ids(self):
     """ ignore other filters and return assets matching ids passed
     """
     req = FakeRequest()
     req.GET = {'asset_id': '1,2', 'project_id': '2', 'tagids': '2,3'}
     expected = {
         'number_of_assets': {
             'audio': 2,
             'photo': 0,
             'text': 0,
             'video': 0
         },
         'assets': [
             dict(self.ASSET_1.items() + self.ASSET_1_TAGS_EN.items()),
             dict(self.ASSET_2.items() + self.ASSET_2_TAGS_ES.items()),
         ]
     }
     self.assertEquals(expected, get_available_assets(req))
示例#26
0
 def test_get_available_assets_pass_bad_envelope(self):
     """ ignore other filters and return asset info for 
         assets in envelopes, ignoring bad envelope id.
     """
     req = FakeRequest()
     req.GET = {'envelope_id': '1,2,3', 'project_id': '2', 'tagids': '2,3'}
     expected = {
         'number_of_assets': {
             'audio': 2,
             'photo': 0,
             'text': 0,
             'video': 0
         },
         'assets': [
             dict(self.ASSET_1.items() + self.ASSET_1_TAGS_EN.items()),
             dict(self.ASSET_2.items() + self.ASSET_2_TAGS_ES.items())
         ]
     }
     self.assertEquals(expected, get_available_assets(req))
示例#27
0
 def test_get_available_assets_kwargs_must_all_be_satisfied(self):
     """ assets returned must match all valid kwargs passed
     """
     req = FakeRequest()
     req.GET = {
         'project_id': '12',
         'audiolength': '5000000',
         'volume': '1.0'
     }
     expected = {
         'number_of_assets': {
             'audio': 0,
             'photo': 0,
             'text': 0,
             'video': 0
         },
         'assets': []
     }
     self.assertEquals(expected, get_available_assets(req))
示例#28
0
 def test_get_available_assets_pass_radius(self):
     """project's radius is bigger than the mock near distance.  
     should get no assets if we pass a radius of 0, overriding
     project radius.
     """
     req = FakeRequest()
     req.GET = {
         'radius': '0',
         'project_id': '12',
         'latitude': '0.1',
         'longitude': '0.1'
     }
     expected = {
         'number_of_assets': {
             'audio': 0,
             'photo': 0,
             'text': 0,
             'video': 0
         },
         'assets': []
     }
     self.assertEquals(expected, get_available_assets(req))