Exemple #1
0
 def test_uniqueness_of_user_id(self):
     """
     creates a user, creates a project, removes the user
     creates a different new user, checks for projects
     should not find anything
     """
     with self.app.app_context():
         response = mscolab_register_and_login(self.app, self.url,
                                               '*****@*****.**', 'abcdef',
                                               'alpha')
         assert response.status == '200 OK'
         data = json.loads(response.get_data(as_text=True))
         response = mscolab_create_content(self.app,
                                           self.url,
                                           data,
                                           path_name='owns_alpha')
         assert response.status == '200 OK'
         mscolab_delete_user(self.app, self.url, '*****@*****.**',
                             'abcdef')
         response = mscolab_register_and_login(self.app, self.url,
                                               '*****@*****.**', 'abcdef',
                                               'delta')
         assert response.status == '200 OK'
         data = json.loads(response.get_data(as_text=True))
         url = url_join(self.url, 'projects')
         response = self.app.test_client().get(url, data=data)
         response = json.loads(response.get_data(as_text=True))
         assert len(response['projects']) == 0
Exemple #2
0
 def test_uploads(self):
     with self.app.app_context():
         response = mscolab_register_and_login(self.app, MSCOLAB_URL_TEST, '*****@*****.**', 'abcdef', 'alpha')
         assert response.status == '200 OK'
         data, response = mscolab_create_project(self.app, MSCOLAB_URL_TEST, response,
                                                 path='f4', description='f4 test example')
         assert response.status == '200 OK'
         url = url_join(MSCOLAB_URL_TEST, 'projects')
         response = self.app.test_client().get(url, data=data)
         assert response.status == '200 OK'
         projects = json.loads(response.get_data(as_text=True))
         data['p_id'] = projects['projects'][0]['p_id']
         p_id = data['p_id']
         data["message_type"] = 0
         file_name = "fake-text-stream.txt"
         data["file"] = (io.BytesIO(b"some initial text data"), file_name)
         url = url_join(MSCOLAB_URL_TEST, 'message_attachment')
         response = self.app.test_client().post(url, data=data)
         assert response.status == '200 OK'
         data = json.loads(response.get_data(as_text=True))
         assert data['success'] is True
         fn = Path(data['path']).name
         url = "%s/uploads/%s/%s" % (MSCOLAB_URL_TEST, p_id, fn)
         response = self.app.test_client().get(url)
         data = response.get_data(as_text=True)
         assert data == "some initial text data"
         url = "%s/uploads/%s" % (MSCOLAB_URL_TEST, p_id)
         response = self.app.test_client().get(url)
         result = response.get_data(as_text=True)
         assert "404" in result
         url = "%s/uploads/" % (MSCOLAB_URL_TEST)
         response = self.app.test_client().get(url)
         result = response.get_data(as_text=True)
         assert "404" in result
Exemple #3
0
    def test_message_attachment(self):
        with self.app.app_context():
            response = mscolab_register_and_login(self.app, MSCOLAB_URL_TEST, '*****@*****.**', 'abcdef', 'alpha')
            assert response.status == '200 OK'
            data, response = mscolab_create_project(self.app, MSCOLAB_URL_TEST, response,
                                                    path='f3', description='f3 test example')
            assert response.status == '200 OK'
            url = url_join(MSCOLAB_URL_TEST, 'projects')
            response = self.app.test_client().get(url, data=data)
            assert response.status == '200 OK'
            projects = json.loads(response.get_data(as_text=True))
            assert projects == {'projects': [{'access_level': 'creator',
                                              'description': 'f3 test example',
                                              'p_id': 7,
                                              'path': 'f3'}]}

            data['p_id'] = projects['projects'][0]['p_id']
            data["message_type"] = 0
            file_name = "fake-text-stream.txt"
            data["file"] = (io.BytesIO(b"some initial text data"), file_name)

            url = url_join(MSCOLAB_URL_TEST, 'message_attachment')
            response = self.app.test_client().post(url, data=data)
            # Todo Example upload
            assert response.status == '200 OK'
            data = json.loads(response.get_data(as_text=True))
            assert data['success'] is True
Exemple #4
0
    def test_get_change_content(self):
        with self.app.app_context():
            response = mscolab_register_and_login(self.app, self.url,
                                                  '*****@*****.**', 'abcdef',
                                                  'alpha')
            assert response.status == '200 OK'
            data = json.loads(response.get_data(as_text=True))
            response = mscolab_create_content(self.app,
                                              self.url,
                                              data,
                                              path_name='f15')
            assert response.status == '200 OK'
            url = url_join(self.url, 'projects')
            response = self.app.test_client().get(url, data=data)
            assert response.status == '200 OK'
            response = json.loads(response.get_data(as_text=True))
            for p in response['projects']:
                if p['path'] == 'f15':
                    data['p_id'] = p['p_id']
                    break

            url = url_join(self.url, 'get_change_content')
            response = self.app.test_client().get(url, data=data)
            assert response.status == '200 OK'
            response = response.get_data(as_text=True)
            # ToDo add a test with two revisions
            assert response == 'False'
Exemple #5
0
 def test_delete_project(self):
     with self.app.app_context():
         response = mscolab_register_and_login(self.app, self.url, 'a', 'a',
                                               'a')
         data, response = mscolab_create_project(
             self.app,
             self.url,
             response,
             path='f3',
             description='f3 test example')
         p_id = get_recent_pid(self.fm, self.user)
         assert p_id == 7
         assert response.status == '200 OK'
         user2 = User.query.filter_by(id=9).first()
         assert self.fm.delete_file(p_id, user2) is False
         assert self.fm.delete_file(p_id, self.user) is True
         assert self.fm.delete_file(p_id, self.user) is False
         permissions = Permission.query.filter_by(p_id=p_id).all()
         assert len(permissions) == 0
         projects_db = Project.query.filter_by(id=p_id).all()
         assert len(projects_db) == 0
         changes = Change.query.filter_by(p_id=p_id).all()
         assert len(changes) == 0
         messages = Message.query.filter_by(p_id=p_id).all()
         assert len(messages) == 0
Exemple #6
0
    def test_get_users_with_permission(self):
        with self.app.app_context():
            response = mscolab_register_and_login(self.app, self.url,
                                                  '*****@*****.**', 'abcdef',
                                                  'alpha')
            assert response.status == '200 OK'
            data = json.loads(response.get_data(as_text=True))
            response = mscolab_create_content(self.app,
                                              self.url,
                                              data,
                                              path_name='f15')
            assert response.status == '200 OK'

            url = url_join(self.url, 'projects')
            response = self.app.test_client().get(url, data=data)
            assert response.status == '200 OK'
            response = json.loads(response.get_data(as_text=True))
            for p in response['projects']:
                if p['path'] == 'f15':
                    data['p_id'] = p['p_id']
                    break

            url = url_join(self.url, 'users_with_permission')
            response = self.app.test_client().get(url, data=data)
            assert response.status == '200 OK'
            response = json.loads(response.get_data(as_text=True))
            assert response['success'] is True
            assert response['users'] == []
Exemple #7
0
 def test_token_dependency_to_project(self):
     """
     creates a user, creates a project, checks that there is only 1 project
     fetches a valid token from an other user
     replaces the token by keeping the user information
     finds only projects related to the changed token
     """
     with self.app.app_context():
         response = mscolab_register_and_login(self.app, self.url,
                                               '*****@*****.**', 'user',
                                               'user')
         assert response.status == '200 OK'
         data_1 = json.loads(response.get_data(as_text=True))
         response = mscolab_create_content(self.app,
                                           self.url,
                                           data_1,
                                           path_name='data_1')
         assert response.status == '200 OK'
         url = url_join(self.url, 'projects')
         response = self.app.test_client().get(url, data=data_1)
         assert response.status == '200 OK'
         response = json.loads(response.get_data(as_text=True))
         assert len(response['projects']) == 1
         response = mscolab_login(self.app, self.url, 'a', 'a')
         data_a = json.loads(response.get_data(as_text=True))
         data_1['token'] = data_a['token']
         url = url_join(self.url, 'projects')
         response = self.app.test_client().get(url, data=data_1)
         response = json.loads(response.get_data(as_text=True))
         assert len(response['projects']) == 3
Exemple #8
0
    def test_import_permissions(self):
        with self.app.app_context():
            response = mscolab_register_and_login(self.app, self.url,
                                                  '*****@*****.**', 'abcdef',
                                                  'alpha')
            assert response.status == '200 OK'
            data = json.loads(response.get_data(as_text=True))
            response = mscolab_create_content(self.app,
                                              self.url,
                                              data,
                                              path_name='p1')
            assert response.status == '200 OK'
            response = mscolab_create_content(self.app,
                                              self.url,
                                              data,
                                              path_name='p2')
            assert response.status == '200 OK'

            url = url_join(self.url, 'projects')
            response = self.app.test_client().get(url, data=data)
            assert response.status == '200 OK'
            response = json.loads(response.get_data(as_text=True))
            for p in response['projects']:
                if p['path'] == 'p1':
                    data['import_p_id'] = p['p_id']
                if p['path'] == 'p2':
                    data['current_p_id'] = p['p_id']
            url = url_join(self.url, 'import_permissions')
            response = self.app.test_client().post(url, data=data)
            assert response.status == '200 OK'
            response = json.loads(response.get_data(as_text=True))
            assert response["success"] is True
Exemple #9
0
    def test_authorized_users(self):
        with self.app.app_context():
            response = mscolab_register_and_login(self.app, self.url,
                                                  '*****@*****.**', 'abcdef',
                                                  'alpha')
            assert response.status == '200 OK'
            data = json.loads(response.get_data(as_text=True))
            auth_data = data
            response = mscolab_create_content(self.app,
                                              self.url,
                                              data,
                                              path_name='f10')
            assert response.status == '200 OK'
            url = url_join(self.url, 'projects')
            response = self.app.test_client().get(url, data=data)
            assert response.status == '200 OK'
            response = json.loads(response.get_data(as_text=True))
            for p in response['projects']:
                if p['path'] == 'f10':
                    auth_data['p_id'] = p['p_id']
                    break

            url = url_join(self.url, 'authorized_users')
            response = self.app.test_client().get(url, data=auth_data)
            assert response.status == '200 OK'
            response = json.loads(response.get_data(as_text=True))
            assert response['users'] == [{
                'access_level': 'creator',
                'username': '******'
            }]
Exemple #10
0
 def test_get_project_details(self):
     with self.app.app_context():
         response = mscolab_register_and_login(self.app, self.url,
                                               '*****@*****.**', 'abcdef',
                                               'alpha')
         assert response.status == '200 OK'
         data = json.loads(response.get_data(as_text=True))
         auth_data = data
         response = mscolab_create_content(self.app,
                                           self.url,
                                           data,
                                           path_name='f13')
         assert response.status == '200 OK'
         url = url_join(self.url, 'projects')
         response = self.app.test_client().get(url, data=data)
         assert response.status == '200 OK'
         response = json.loads(response.get_data(as_text=True))
         for p in response['projects']:
             if p['path'] == 'f13':
                 auth_data['p_id'] = p['p_id']
                 break
         url = url_join(self.url, 'project_details')
         response = self.app.test_client().get(url, data=auth_data)
         assert response.status == '200 OK'
         response = json.loads(response.get_data(as_text=True))
         assert response == {
             'description': 'f13',
             'id': auth_data['p_id'],
             'path': 'f13'
         }
Exemple #11
0
 def test_create_project(self):
     with self.app.app_context():
         response = mscolab_register_and_login(self.app, MSCOLAB_URL_TEST, '*****@*****.**', 'abcdef', 'alpha')
         assert response.status == '200 OK'
         data, response = mscolab_create_project(self.app, MSCOLAB_URL_TEST, response,
                                                 path='f1', description='f1 test example')
         assert response.status == '200 OK'
         data = response.get_data(as_text=True)
         assert data == 'True'
Exemple #12
0
 def test_delete_user(self):
     with self.app.app_context():
         response = mscolab_register_and_login(self.app, self.url, '*****@*****.**', 'abcdef', 'alpha')
         assert response.status == '200 OK'
         data = json.loads(response.get_data(as_text=True))
         url = url_join(self.url, 'delete_user')
         response = self.app.test_client().post(url, data=data)
         assert response.status == '200 OK'
         data = json.loads(response.get_data(as_text=True))
         assert data["success"] is True
Exemple #13
0
 def test_messages(self):
     with self.app.app_context():
         response = mscolab_register_and_login(self.app, MSCOLAB_URL_TEST, '*****@*****.**', 'abcdef', 'alpha')
         assert response.status == '200 OK'
         data = json.loads(response.get_data(as_text=True))
         url = url_join(MSCOLAB_URL_TEST, 'messages')
         response = self.app.test_client().get(url, data=data)
         assert response.status == '200 OK'
         data = json.loads(response.get_data(as_text=True))
         assert data["messages"] == []
Exemple #14
0
    def test_get_projects(self):
        with self.app.app_context():
            response = mscolab_register_and_login(self.app, MSCOLAB_URL_TEST, '*****@*****.**', 'abcdef', 'alpha')
            assert response.status == '200 OK'
            data = json.loads(response.get_data(as_text=True))
            response = mscolab_create_content(self.app, MSCOLAB_URL_TEST, data, path_name='f7')
            assert response.status == '200 OK'
            response = mscolab_create_content(self.app, MSCOLAB_URL_TEST, data, path_name='f8')
            assert response.status == '200 OK'

            url = url_join(MSCOLAB_URL_TEST, 'projects')
            response = self.app.test_client().get(url, data=data)
            response = json.loads(response.get_data(as_text=True))
            assert len(response['projects']) == 2
Exemple #15
0
    def _create_user_data(self, emailid='*****@*****.**'):
        with self.app.app_context():
            self._connect_to_mscolab()
            response = mscolab_register_and_login(self.app, self.url, emailid,
                                                  'abcdef', 'alpha')

            assert response.status == '200 OK'
            data, response = mscolab_create_project(
                self.app,
                self.url,
                response,
                path='f3',
                description='f3 test example')
            assert response.status == '200 OK'
            self._login(emailid, 'abcdef')
            self._activate_project_at_index(0)
Exemple #16
0
 def test_update_project(self):
     with self.app.app_context():
         response = mscolab_register_and_login(self.app, self.url,
                                               '*****@*****.**', 'abcdef',
                                               'alpha')
         assert response.status == '200 OK'
         data = json.loads(response.get_data(as_text=True))
         response = mscolab_create_content(self.app,
                                           self.url,
                                           data,
                                           path_name='f16')
         assert response.status == '200 OK'
         url = url_join(self.url, 'projects')
         response = self.app.test_client().get(url, data=data)
         assert response.status == '200 OK'
         response = json.loads(response.get_data(as_text=True))
         for p in response['projects']:
             if p['path'] == 'f16':
                 data['p_id'] = p['p_id']
                 break
         data['attribute'] = 'path'
         data['value'] = 'example_flight_path'
         url = url_join(self.url, 'update_project')
         response = self.app.test_client().post(url, data=data)
         assert response.status == '200 OK'
         content = """\
                 <?xml version="1.0" encoding="utf-8"?>
                   <FlightTrack>
                     <Name>F14 test example</Name>
                     <ListOfWaypoints>
                       <Waypoint flightlevel="100.0" lat="55.15" location="A1" lon="-25.74">
                         <Comments>Takeoff</Comments>
                       </Waypoint>
                       <Waypoint flightlevel="350" lat="42.99" location="A2" lon="-12.1">
                         <Comments></Comments>
                       </Waypoint>
                       </ListOfWaypoints>
                   </FlightTrack>"""
         # not sure if the update API should do this
         # data['attribute'] = "content"
         # data['value'] = content
         # url = url_join(self.url, 'update_project')
         # response = self.app.test_client().post(url, data=data)
         # assert response.status == '200 OK'
         user = User.query.filter_by(emailid='*****@*****.**').first()
         self.fm.save_file(int(data['p_id']), content, user, "new")
    def test_delete_project(self):
        with self.app.app_context():
            response = mscolab_register_and_login(self.app, self.url, 'a', 'a',
                                                  'a')
            assert response.status == '200 OK'
            data, response = mscolab_create_project(
                self.app,
                self.url,
                response,
                path='f3',
                description='f3 test example')
            assert response.status == '200 OK'
            p_id = get_recent_pid(self.fm, self.user)

        # first free number after sseding
        assert p_id == 7
        data = {"token": self.token, "p_id": p_id}
        url = url_join(self.url, 'delete_project')
        res = requests.post(url, data=data).json()
        assert res["success"] is True
Exemple #18
0
    def test_get_project(self):
        with self.app.app_context():
            response = mscolab_register_and_login(self.app, self.url,
                                                  '*****@*****.**', 'abcdef',
                                                  'alpha')
            assert response.status == '200 OK'
            data = json.loads(response.get_data(as_text=True))
            content = """\
<?xml version="1.0" encoding="utf-8"?>
  <FlightTrack>
    <Name>F5 test example</Name>
    <ListOfWaypoints>
      <Waypoint flightlevel="0.0" lat="55.15" location="A1" lon="-23.74">
        <Comments>Takeoff</Comments>
      </Waypoint>
      <Waypoint flightlevel="350" lat="42.99" location="A2" lon="-12.1">
        <Comments></Comments>
      </Waypoint>
      </ListOfWaypoints>
  </FlightTrack>"""

            data["path"] = 'f5'
            data['description'] = 'f5 test example'
            data['content'] = content
            url = url_join(self.url, 'create_project')
            response = self.app.test_client().post(url, data=data)
            assert response.status == '200 OK'
            url = url_join(self.url, 'projects')
            response = self.app.test_client().get(url, data=data)
            assert response.status == '200 OK'
            response = json.loads(response.get_data(as_text=True))
            for p in response['projects']:
                if p['path'] == 'f5':
                    data['p_id'] = p['p_id']
                    break
            url = url_join(self.url, 'get_project_by_id')
            response = self.app.test_client().get(url, data=data)
            assert response.status == '200 OK'
            data = json.loads(response.get_data(as_text=True))
            assert 'F5 test example' in data['content']
Exemple #19
0
    def setup(self):
        self.process, self.url, self.app, self.sio, self.cm, self.fm = mscolab_start_server(
            PORTS)
        QtTest.QTest.qWait(500)
        self.application = QtWidgets.QApplication(sys.argv)
        self.window = MSSMscolabWindow(
            data_dir=mscolab_settings.MSCOLAB_DATA_DIR,
            mscolab_server_url=self.url)

        with self.app.app_context():
            response = mscolab_register_and_login(self.app, self.url,
                                                  'a1a@a1a', 'a1a', 'a1a')
            _ = mscolab_create_project(self.app,
                                       self.url,
                                       response,
                                       path='f3',
                                       description='f3 test example')
            self.user = User.query.filter_by(emailid="a1a@a1a").first()
            self.test_p_id = get_recent_pid(self.fm, self.user)
            self.test_sid = 25
            socket_storage = {'s_id': self.test_sid, 'u_id': self.user.id}
            self.sockets = [socket_storage]
Exemple #20
0
    def test_delete_project(self):
        with self.app.app_context():
            response = mscolab_register_and_login(self.app, MSCOLAB_URL_TEST, '*****@*****.**', 'abcdef', 'alpha')
            assert response.status == '200 OK'
            data = json.loads(response.get_data(as_text=True))
            auth_data = data
            response = mscolab_create_content(self.app, MSCOLAB_URL_TEST, data, path_name='f12')
            assert response.status == '200 OK'
            url = url_join(MSCOLAB_URL_TEST, 'projects')
            response = self.app.test_client().get(url, data=data)
            assert response.status == '200 OK'
            response = json.loads(response.get_data(as_text=True))
            for p in response['projects']:
                if p['path'] == 'f12':
                    auth_data['p_id'] = p['p_id']
                    break

            url = url_join(MSCOLAB_URL_TEST, 'delete_project')
            response = self.app.test_client().post(url, data=auth_data)
            assert response.status == '200 OK'
            response = json.loads(response.get_data(as_text=True))
            assert response['success'] is True
Exemple #21
0
    def test_get_all_changes(self):
        with self.app.app_context():
            response = mscolab_register_and_login(self.app, MSCOLAB_URL_TEST, '*****@*****.**', 'abcdef', 'alpha')
            assert response.status == '200 OK'
            data = json.loads(response.get_data(as_text=True))
            response = mscolab_create_content(self.app, MSCOLAB_URL_TEST, data, path_name='f14')
            assert response.status == '200 OK'
            url = url_join(MSCOLAB_URL_TEST, 'projects')
            response = self.app.test_client().get(url, data=data)
            assert response.status == '200 OK'
            response = json.loads(response.get_data(as_text=True))
            for p in response['projects']:
                if p['path'] == 'f14':
                    data['p_id'] = p['p_id']
                    break

            url = url_join(MSCOLAB_URL_TEST, 'get_all_changes')
            response = self.app.test_client().get(url, data=data)
            assert response.status == '200 OK'
            data = json.loads(response.get_data(as_text=True))
            assert data['success'] is True
            # ToDo check 2 changes
            assert data['changes'] == []