Exemple #1
0
 def test_that_empty_request_is_not_valid(self, signature_mock):
     from swaglyrics_backend.issue_maker import app
     from swaglyrics_backend.utils import validate_request
     with app.test_client() as c:
         req = c.post()
         with self.assertRaises(ImATeapot):
             validate_request(req)
    def test_unsupported_not_trivial_case_does_make_issue(
            self, fake_issue, fake_check, another_fake_check):
        from swaglyrics_backend.issue_maker import app, limiter
        fake_issue.return_value = {
            "status_code":
            201,
            "link":
            "https://github.com/SwagLyrics/SwagLyrics-For-Spotify/issues/2443"  # fake issue creation
        }
        with app.test_client() as c:
            app.config['TESTING'] = True
            limiter.enabled = False  # disable rate limiting
            generate_fake_unsupported()
            resp = c.post('/unsupported',
                          data={
                              'version': '1.2.0',
                              'song': "Avatar's Love (braces not trivial)",
                              'artist': 'Rachel Clinton'
                          })

        with open('unsupported.txt') as f:
            data = f.readlines()

        assert "Avatar's Love (braces not trivial) by Rachel Clinton\n" in data
        assert resp.data == b"Lyrics for that song may not exist on Genius. Created issue on the GitHub repo for " \
                            b"Avatar's Love (braces not trivial) by Rachel Clinton to investigate further. " \
                            b"\nhttps://github.com/SwagLyrics/SwagLyrics-For-Spotify/issues/2443"
    def test_update(self):
        from swaglyrics import __version__
        from swaglyrics_backend.issue_maker import update
        from flask import Flask

        app = Flask(__name__)
        with app.test_request_context('/'):
            with app.test_client() as c:
                app.config['TESTING'] = True

                c.post('/unsupported',
                       data={
                           'version': '0.9.0',
                           'song': 'Miracle',
                           'artist': 'Caravan Palace'
                       })
                generate_fake_unsupported()
                # fix soon
                # self.assertEqual(
                #     update(), 'Please update SwagLyrics to the latest version to get better support :)')

                c.post('/unsupported',
                       data={
                           'version': str(__version__),
                           'song': 'Miracle',
                           'artist': 'Caravan Palace'
                       })
                """Test correct output given song and artist that exist in unsupported.txt"""
                self.assertEqual(
                    update(), "Issue already exists on the GitHub repo. "
                    "\nhttps://github.com/SwagLyrics/SwagLyrics-For-Spotify/issues"
                )
Exemple #4
0
 def test_that_request_is_valid(self, signature_mock):
     from swaglyrics_backend.issue_maker import app
     with app.test_client() as c:
         req = c.post(json=self.github_json)
         req.status_code = 200
         req.headers = self.github_headers
         from swaglyrics_backend.utils import validate_request
         self.assertIsNotNone(validate_request(req))
Exemple #5
0
 def test_that_not_valid_signature_aborts_code(self):
     from swaglyrics_backend.issue_maker import app
     from swaglyrics_backend.utils import validate_request
     with app.test_client() as c:
         req = c.post()
         req.headers = self.github_headers
         with self.assertRaises(ImATeapot):
             validate_request(req)
 def test_that_slow_is_rate_limited(self, fake_ip):
     from swaglyrics_backend.issue_maker import app, limiter
     with app.test_client() as c:
         limiter.enabled = True  # enable rate limiting
         resp = c.get('/slow')
         # the second one should be rate limited
         resp_again = c.get('/slow')
     assert resp.data == b'24'
     assert resp_again.status_code == 429
    def test_landing_page(self):
        from swaglyrics_backend.issue_maker import app
        generate_fake_unsupported()
        with app.test_client() as c:
            resp = c.get('/')

        assert b'The SwagLyrics Backend and API is housed here.' in resp.data
        assert b'Heroku' not in resp.data
        assert b'Miracle by Caravan Palace' in resp.data
 def test_that_delete_line_deletes_line_from_master_unsupported(self):
     from swaglyrics_backend.issue_maker import app
     with app.test_client() as c:
         generate_fake_unsupported()
         response = c.post('/delete_unsupported',
                           data={
                               'auth': '',
                               'song': 'Supersonics',
                               'artist': 'Caravan Palace'
                           })
         assert response.data == b"Removed 1 instances of Supersonics by Caravan " \
                                 b"Palace from unsupported.txt successfully."
    def test_that_delete_unsupported_auth_works(self):
        """
        This test doesn't test database behaviour! Only dealing with unsupported and parsing request
        """
        from swaglyrics_backend.issue_maker import app
        with app.test_client() as c:
            resp = c.post('/delete_unsupported',
                          data={
                              'auth': 'wrong auth',
                              'song': 'oui',
                              'artist': 'Jeremih'
                          })

        assert resp.status_code == 403
    def test_unsupported_old_version(self):
        from swaglyrics_backend.issue_maker import app, limiter

        with app.test_client() as c:
            app.config['TESTING'] = True
            limiter.enabled = False  # disable rate limiting
            resp = c.post('/unsupported',
                          data={
                              'version': '1.1.0',
                              'song': 'Miracle',
                              'artist': 'Caravan Palace'
                          })

            assert resp.data == b"Please update SwagLyrics to the latest version (v1.2.0), it contains a hotfix for " \
                                b"Genius A/B testing :)"
    def test_that_get_stripper_gets_genius_stripper(self, fake_db,
                                                    fake_stripper,
                                                    fake_logger):
        from swaglyrics_backend.issue_maker import app, limiter
        fake_db.query.filter.return_value.filter.return_value.first.return_value = None
        fake_stripper.return_value = "XXXTENTACION-bad-vibes-forever"
        with app.test_client() as c:
            limiter.enabled = False  # disable rate limiting
            resp = c.get('/stripper',
                         data={
                             'song': 'bad vibes forever',
                             'artist': 'XXXTENTACION'
                         })

        assert resp.data == b"XXXTENTACION-bad-vibes-forever"
    def test_that_get_stripper_returns_not_found_when_no_stripper_found(
            self, fake_db, fake_stripper, fake_logger):
        from swaglyrics_backend.issue_maker import app, limiter
        fake_db.query.filter.return_value.filter.return_value.first.return_value = None
        fake_stripper.return_value = None
        with app.test_client() as c:
            limiter.enabled = False  # disable rate limiting
            resp = c.get('/stripper',
                         data={
                             'song': 'bad vibes forever',
                             'artist': 'XXXTENTACION'
                         })

        assert resp.data == b""
        assert resp.status_code == 404
    def test_unsupported_trivial_case_does_not_make_issue(self):
        from swaglyrics_backend.issue_maker import app, limiter

        with app.test_client() as c:
            app.config['TESTING'] = True
            limiter.enabled = False  # disable rate limiting
            resp = c.post('/unsupported',
                          data={
                              'version': '1.2.0',
                              'song': 'Navajo',
                              'artist': 'Masego'
                          })

            assert resp.data == b"Lyrics for Navajo by Masego may not exist on Genius.\n" \
                                b"If you feel there's an error, open a ticket at " \
                                b"https://github.com/SwagLyrics/SwagLyrics-For-Spotify/issues"
 def test_that_add_stripper_adds_stripper(self, app_mock):
     """
     This test doesn't test database behaviour! Only dealing with unsupported and parsing request
     """
     from swaglyrics_backend.issue_maker import app
     with app.test_client() as c:
         generate_fake_unsupported()
         resp = c.post('/add_stripper',
                       data={
                           'auth': '',
                           'song': 'Miracle',
                           'artist': 'Caravan Palace',
                           'stripper': 'Caravan-palace-miracle'
                       })
         assert b"Added stripper for Miracle by Caravan Palace to server database successfully, " \
                b"deleted 1 instances from unsupported.txt" == resp.data
    def test_unsupported_fishy_requests_handling(self, fake_check,
                                                 another_fake_check):
        from swaglyrics_backend.issue_maker import app, limiter
        with app.test_client() as c:
            app.config['TESTING'] = True
            limiter.enabled = False  # disable rate limiting
            resp = c.post(
                '/unsupported',
                data={
                    'version': '1.2.0',
                    'song': "evbiurevbiuprvb",  # fake issue spam
                    'artist': 'bla$bla%bla'
                })  # special characters to trip the trivial case

        assert resp.data == b"That song doesn't seem to exist on Spotify or is instrumental. " \
                            b"\nIf you feel there's an error, open a ticket at " \
                            b"https://github.com/SwagLyrics/SwagLyrics-For-Spotify/issues"
    def test_unsupported_key_error(self):
        from swaglyrics_backend.issue_maker import app, limiter

        with app.test_client() as c:
            app.config['TESTING'] = True
            limiter.enabled = False  # disable rate limiting
            # fix soon
            # self.assertEqual(
            #     update(), 'Please update SwagLyrics to the latest version to get better support :)')

            resp = c.post('/unsupported',
                          data={
                              'song': 'Miracle',
                              'artist': 'Caravan Palace'
                          })

            assert resp.data == b"Please update SwagLyrics to the latest version (v1.2.0), it contains a hotfix for " \
                                b"Genius A/B testing :)"
    def test_that_get_stripper_gets_stripper_from_database(self, fake_db):
        class FakeLyrics:
            def __init__(self, song=None, artist=None, stripper=None):
                self.song = song
                self.artist = artist
                self.stripper = stripper

        from swaglyrics_backend.issue_maker import app
        fake_db.query.filter.return_value.filter.return_value.first.return_value = FakeLyrics(
            song='bad vibes forever',
            artist='XXXTENTACION',
            stripper="XXXTENTACION-bad-vibes-forever")
        with app.test_client() as c:
            resp = c.get('/stripper',
                         data={
                             'song': 'bad vibes forever',
                             'artist': 'XXXTENTACION'
                         })

        assert resp.data == b"XXXTENTACION-bad-vibes-forever"
    def test_update_unsupported(self):
        from swaglyrics import __version__
        from swaglyrics_backend.issue_maker import app, limiter
        with app.test_client() as c:
            app.config['TESTING'] = True
            limiter.enabled = False  # disable rate limiting
            generate_fake_unsupported()
            # fix soon
            # self.assertEqual(
            #     update(), 'Please update SwagLyrics to the latest version to get better support :)')

            resp = c.post('/unsupported',
                          data={
                              'version': str(__version__),
                              'song': 'Miracle',
                              'artist': 'Caravan Palace'
                          })
            # Test correct output given song and artist that exist in unsupported.txt
            assert resp.data == b"Issue already exists on the GitHub repo. " \
                                b"\nhttps://github.com/SwagLyrics/SwagLyrics-For-Spotify/issues"
    def test_unsupported_issue_making_error(self, fake_issue, fake_check,
                                            another_fake_check):
        from swaglyrics_backend.issue_maker import app, limiter
        fake_issue.return_value = {
            "status_code": 500,  # error
            "link": ""
        }
        with app.test_client() as c:
            app.config['TESTING'] = True
            limiter.enabled = False  # disable rate limiting
            generate_fake_unsupported()
            resp = c.post('/unsupported',
                          data={
                              'version': '1.2.0',
                              'song': "purple.laces [string%@*]",
                              'artist': 'lost spaces'
                          })
        with open('unsupported.txt') as f:
            data = f.readlines()

        assert "purple.laces [string%@*] by lost spaces\n" in data
        assert resp.data == b"Logged purple.laces [string%@*] by lost spaces in the server."
 def test_that_test_route_works(self):
     from swaglyrics_backend.issue_maker import app
     with app.test_client() as c:
         resp = c.get('/test')
     assert resp.data == b'69aaa69'
 def test_swaglyrics_version_route(self):
     from swaglyrics_backend.issue_maker import app
     from swaglyrics import __version__ as version
     with app.test_client() as c:
         resp = c.get('/version')
     assert resp.data == version.encode()
 def test_that_master_unsupported_reads_data(self):
     from swaglyrics_backend.issue_maker import app
     with app.test_client() as c:
         generate_fake_unsupported()
         req = c.get('/master_unsupported')
         self.assertIsNotNone(req.response)