def test_vote_asset(self):
     req = FakeRequest()
     req.GET = {'session_id': self.session.id, 'asset_id': 1,
                'vote_type': 'like', 'value': 2}
     self.assertEqual({"success": True}, vote_asset(req))
     votes = Vote.objects.filter(asset__id__exact=1)
     self.assertTrue(len(votes) == 1)
 def test_get_asset_info(self):
     req = FakeRequest()
     req.GET = {'session_id': self.session.id, 'asset_id': self.asset1.id}
     expected = {"asset_id": 1,
                 "created": '2013-11-21T21:03:06.616402',
                 "duraton_in_ms": 5}
     self.assertEquals(expected, get_asset_info(req))
 def test_request_stream_listener_in_range(self):
     """ Make sure we get good stream data if listener is in range.
     Doesn't test actual stream being served.
     """
     req = FakeRequest()
     req.GET = {'session_id': '1', 'latitude': '0.1', 'longitude': '0.1'}
     expected = {'stream_url': 'http://rw.com:8000/stream1.ogg'}
     self.assertEquals(expected, request_stream(req))
 def test_request_stream_listener_in_range_no_lat_long_passed(self):
     """ Make sure we get good stream data if no lat/long passed
     Doesn't test actual stream being served.
     """
     req = FakeRequest()
     req.GET = {'session_id': '1'}
     expected = {'stream_url': 'http://rw.com:8000/stream1.ogg'}
     self.assertEquals(expected, request_stream(req))
    def test_get_current_streaming_asset(self):

        req = FakeRequest()
        req.GET = {'session_id': self.session.id}
        current = get_current_streaming_asset(req)
        self.assertEquals('dict', type(current).__name__)
        self.assertEquals(2, current['asset_id'])
        self.assertEquals('2013-11-21T17:29:44.610672', current['start_time'])
        self.assertEquals(6, current['duration_in_stream'])
 def test_request_stream_just_one_speaker_in_range_needed(self):
     speaker2 = mommy.make(Speaker, project=self.project1,
                           latitude=0.1, longitude=0.1,
                           maxdistance=2000000000000, activeyn=True)
     speaker2.save()
     req = FakeRequest()
     req.GET = {'session_id': '1'}
     expected = {'stream_url': 'http://rw.com:8000/stream1.ogg'}
     self.assertEquals(expected, request_stream(req))
 def test_get_current_streaming_asset_multi_audiotrack(self):
     """ must raise RoundException if project has more than one AudioTrack
     """
     req = FakeRequest()
     req.GET = {'session_id': self.session.id}
     track2 = mommy.make(Audiotrack, project=self.project1, id=2)
     with self.assertRaises(RoundException):
         current = get_current_streaming_asset(req)
         # delete extra track
         Audiotrack.objects.filter(id__exact=2).delete()
 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(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_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_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_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_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_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_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))
 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))
 def test_request_stream_demo_stream_enabled(self):
     """ Make sure we get the demo stream data if it's enabled for the 
     session, and the localized message in the correct language for the 
     session. Doesn't test actual stream being served.
     """
     req = FakeRequest()
     req.GET = {'session_id': '1'}
     self.session.demo_stream_enabled = True
     self.session.save()
     expected = {
         'stream_url': 'http://rw.com:8000/demo_stream.mp3',
         'demo_stream_message': 'Uno'
     }
     self.assertEquals(expected, request_stream(req))
     self.session.demo_stream_enabled = False
     self.session.save()
    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))
    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))
 def test_request_stream_listener_out_of_range(self):
     """ Make sure we get out of range message if listener is too far.
     Doesn't test actual stream being served.
     """
     req = FakeRequest()
     req.GET = {'session_id': '1', 'latitude': '0.1', 'longitude': '0.1'}
     expected = {
         'user_message': ('This application is designed to be used in '
                          'specific geographic locations. Apparently '
                          'your phone thinks you are not at one of those '
                          'locations, so you will hear a sample audio '
                          'stream instead of the real deal. If you think '
                          'your phone is incorrect, please restart Scapes '
                          'and it will probably work. Thanks for '
                          'checking it out!'),
         'stream_url': 'http://rw.com:8000/outofrange.mp3'}
     self.assertEquals(expected, request_stream(req))
    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))
 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))
 def test_request_stream_inactive_speakers_not_involved(self):
     """ Inactive speakers don't count for in-range
     """
     req = FakeRequest()
     req.GET = {'session_id': '1', 'latitude': '0.1', 'longitude': '0.1'}
     self.speaker1.activeyn = False
     self.speaker1.save()
     expected = {
         'user_message': ('This application is designed to be used in '
                          'specific geographic locations. Apparently '
                          'your phone thinks you are not at one of those '
                          'locations, so you will hear a sample audio '
                          'stream instead of the real deal. If you think '
                          'your phone is incorrect, please restart Scapes '
                          'and it will probably work. Thanks for '
                          'checking it out!'),
         'stream_url': 'http://rw.com:8000/outofrange.mp3'}
     self.assertEquals(expected, request_stream(req))
     self.speaker1.activeyn = True
     self.speaker1.save()
Exemple #25
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))