示例#1
0
    def test_single_site(self):
        """Ensure that single site info is returned"""
        user = add_user('mac', '*****@*****.**', '1234qwer')
        add_site('google.com', user_id=user.id)
        with self.client:
            resp_login = self.client.post(
                '/login',
                data=json.dumps({
                    'username': '******',
                    'password': '******'
                }),
                content_type='application/json'
            )
            token = json.loads(resp_login.data.decode())['auth_token']

            response = self.client.get(
                '/sites/google.com',
                content_type='application/json',
                headers={'Authorization': f'Bearer {token}'}
            )
            data = json.loads(response.data.decode())
            self.assertEqual(response.status_code, 200)
            self.assertEqual(len(data), 1)
            self.assertIn('google.com', data['site']['full_link'])
            self.assertIsNotNone(data['site']['short_link'])
示例#2
0
    def test_site_edit_fail(self):
        """Ensure PUT site fails correctly"""
        user = add_user('mac', '*****@*****.**', '1234qwer')
        add_site('google.com', user_id=user.id)
        with self.client:
            resp_login = self.client.post(
                '/login',
                data=json.dumps({
                    'username': '******',
                    'password': '******'
                }),
                content_type='application/json'
            )
            token = json.loads(resp_login.data.decode())['auth_token']

            response = self.client.put(
                '/sites/google.com',
                data=json.dumps({
                    'site': 'google.com',
                }),
                content_type='application/json',
                headers={'Authorization': f'Bearer {token}'}
            )

            data = json.loads(response.data.decode())
            self.assertEqual(response.status_code, 409)
            self.assertEqual(data['message'], "Site already exists")
 def test_add_site(self):
     user = add_user('mac', '*****@*****.**', '1234qwer')
     site = add_site('google.com', user_id=user.id)
     self.assertTrue(site.id)
     self.assertTrue(site.full_link, 'google.com')
     self.assertTrue(site.is_working, True)
     self.assertTrue(site.expired_date)
    def test_to_json_none(self):
        """
        Ensure that to json return None when no date
        """
        user = add_user('mac', '*****@*****.**', '1234qwer')
        add_site('google.com', user_id=user.id)

        site = SiteModel.query.filter_by(full_link="google.com").first()
        site.set_date(None)
        json_site = site.json()

        self.assertEqual(1, json_site['id'])
        self.assertEqual("google.com", json_site['full_link'])
        self.assertEqual(6, len(json_site['short_link']))
        self.assertEqual(True, json_site['working'])
        self.assertEqual(None, json_site['expiry_date'])
    def test_to_json(self):
        """
        Ensure that to json works
        """
        user = add_user('mac', '*****@*****.**', '1234qwer')
        add_site('google.com', user_id=user.id)

        site = SiteModel.query.filter_by(full_link="google.com").first()

        json_site = site.json()

        self.assertEqual(1, json_site['id'])
        self.assertEqual("google.com", json_site['full_link'])
        self.assertEqual(6, len(json_site['short_link']))
        self.assertEqual(True, json_site['working'])
        self.assertTrue(
            isinstance(
                datetime.strptime(json_site["expiry_date"],
                                  "%Y-%m-%d %H:%M:%S"), datetime))
示例#6
0
 def test_post_duplicate(self):
     user = add_user('mac', '*****@*****.**', '1234qwer')
     add_site("google.com", user_id=user.id)
     with self.client:
         resp_login = self.client.post(
             '/login',
             data=json.dumps({
                 'username': '******',
                 'password': '******'
             }),
             content_type='application/json'
         )
         token = json.loads(resp_login.data.decode())['auth_token']
         response = self.client.post(
             '/sites',
             data=json.dumps({
                 'site': 'google.com',
             }),
             content_type='application/json',
             headers={'Authorization': f'Bearer {token}'}
         )
         data = json.loads(response.data.decode())
         self.assertEqual(response.status_code, 409)
         self.assertIn("Site already exists", data['message'])
示例#7
0
    def test_site_delete(self):
        """Ensure that DELETE site works correctly"""
        user = add_user('mac', '*****@*****.**', '1234qwer')
        add_site('google.com', user_id=user.id)
        with self.client:
            resp_login = self.client.post(
                '/login',
                data=json.dumps({
                    'username': '******',
                    'password': '******'
                }),
                content_type='application/json'
            )
            token = json.loads(resp_login.data.decode())['auth_token']

            response = self.client.delete(
                '/sites/google.com',
                content_type='application/json',
                headers={'Authorization': f'Bearer {token}'}
            )

            data = json.loads(response.data.decode())
            self.assertEqual(response.status_code, 200)
            self.assertEqual(data['message'], "Item deleted")
示例#8
0
 def test_shortcut_redirect(self):
     """Ensure that short link redirect to another site"""
     user = add_user('mac', '*****@*****.**', '1234qwer')
     site = add_site('google.com', user_id=user.id)
     with self.client:
         resp_login = self.client.post('/login',
                                       data=json.dumps({
                                           'username':
                                           '******',
                                           'password':
                                           '******'
                                       }),
                                       content_type='application/json')
         token = json.loads(resp_login.data.decode())['auth_token']
         response = self.client.get(
             f'/{site.short_link}',
             content_type='application/json',
             headers={'Authorization': f'Bearer {token}'})
         self.assertEqual(response.status_code, 302)
示例#9
0
 def test_expiry_link(self):
     """Ensure that expiry site is not redirecting to another site"""
     user = add_user('mac', '*****@*****.**', '1234qwer')
     site = add_site('google.com', user_id=user.id)
     site.is_working = False
     with self.client:
         resp_login = self.client.post('/login',
                                       data=json.dumps({
                                           'username':
                                           '******',
                                           'password':
                                           '******'
                                       }),
                                       content_type='application/json')
         token = json.loads(resp_login.data.decode())['auth_token']
         response = self.client.get(
             f'/{site.short_link}',
             content_type='application/json',
             headers={'Authorization': f'Bearer {token}'})
         data = json.loads(response.data.decode())
         self.assertEqual(response.status_code, 405)
         self.assertEqual(data['message'], 'Link has expired')
    def test_find_by_fullLink(self):
        user = add_user('mac', '*****@*****.**', '1234qwer')
        site = add_site('google.com', user_id=user.id)

        result = SiteModel.find_by_fullLink(site.full_link)
        self.assertEqual(site.full_link, result.full_link)