Example #1
0
    def test_client_has_dataset_returns_true(self):
        client = Client(name='Client', ip_address=IP_ADDRESS)
        dataset = Dataset(filename=FILENAME)
        client.datasets = [dataset]

        result = DbHelper.client_has_dataset(client, dataset)
        self.assertTrue(result)
Example #2
0
 def test_json(self):
     client = Client(name=self.name, ip_address=self.ip_address, id=self.id)
     self.assertDictEqual(client.json(), {
         'name': self.name,
         'ip_address': self.ip_address,
         'id': self.id
     })
Example #3
0
def create_client():
    """Create a client"""
    name = request.json.get("name", '')
    if not name:
        return bad_request(405)
    client = Client(name=name)
    client.save()
    return jsonify(client.to_dict()), 201
    def save(**kwargs):
        client = Client()
        client.name = kwargs['name']
        client.email = kwargs['email']

        save_command = SaveCommand()
        result = save_command.execute(client)

        return render_template('insert.html', message=result.result)
Example #5
0
def create_client():
    try:
        session = current_app.db.session

        body = request.get_json()

        error_list = []

        if not Client.query.filter_by(email=body["email"]).first():
            email = body["email"]
        else:
            error_list.append("email")

        if not Client.query.filter_by(phone_number=body["phone_number"]).first():
            phone_number = body["phone_number"]
        else:
            error_list.append("phone_number")

        if error_list:
            raise NameError(error_list)

        name = body["name"]
        password = body["password"]
        user_type = "client"

        new_client = Client(
            name=name,
            email=email,
            phone_number=phone_number,
            user_type=user_type,
        )

        new_client.password = password

        session.add(new_client)
        session.commit()

        return {
            "id": new_client.id,
            "name": new_client.name,
            "email": new_client.email,
        }, HTTPStatus.CREATED

    except KeyError:
        return {"msg": "Verify BODY content"}, HTTPStatus.BAD_REQUEST

    except DataError:
        return {"msg": "Verify BODY content"}, HTTPStatus.BAD_REQUEST

    except NameError as e:
        unique = e.args[0]
        errors = ""
        for error in unique:
            errors = errors + f"{error}, "

        return {"msg": f"{errors}already registered"}, HTTPStatus.BAD_REQUEST
    def test_get_client_successfully(self):
        client = Client(name='TestClient', ip_address='172.0.15.3')
        db.session.add(client)
        db.session.commit()

        response = self.client.get('/clients/1')

        assert_success(response)
        response_json = response.get_json()
        self.assertEqual(response_json, client.details_json())
    def update(**kwargs):
        client = Client()
        client.id = kwargs['id']
        client.name = kwargs['name']
        client.email = kwargs['email']

        update_command = UpdateCommand()
        result = update_command.execute(client)

        return render_template('index.html', message=result.result)
    def test_get_one_element_clients_list(self):
        client = Client(name='Foo', ip_address='127.0.0.1')
        db.session.add(client)
        db.session.commit()

        response = self.client.get('/clients')
        response_json = response.get_json()
        assert_success(response)
        self.assertEqual(len(response_json), 1)
        self.assertDictEqual(response_json[0], client.json())
    def test_dataset_not_created_because_already_exists(self):
        filename = 'test.txt'
        client = Client(name='Client', ip_address='127.0.0.1')
        db.session.add(client)
        client.datasets = [Dataset(filename=filename)]
        db.session.commit()

        response = self.client.post('/datasets', data=json.dumps({'client': client.id, 'filename': filename}),
                                    content_type='application/json')

        assert_status_code_equal(response, status.HTTP_409_CONFLICT)
    def test_get_multiple_clients(self):
        db.session.add_all([
            Client(name='Foo', ip_address='172.10.0.2'),
            Client(name='Bar', ip_address='127.0.0.1')
        ])
        db.session.commit()

        response = self.client.get('/clients')
        response_json = response.get_json()
        assert_success(response)
        self.assertEqual(len(response_json), 2)
Example #11
0
    def test_cannot_patch_changing_owner_because_not_exists(self):
        client = Client(name='Client1', ip_address='127.0.0.1')
        dataset = Dataset(filename='test.txt')
        client.datasets = [dataset]
        db.session.add(client)
        db.session.commit()

        response = self.client.patch('/datasets/' + str(dataset.id),
                                     data=json.dumps({'client': 42}),
                                     content_type='application/json')

        assert_status_code_equal(response, status.HTTP_400_BAD_REQUEST)
        self.assertEqual(client.datasets, [dataset])
Example #12
0
 def test_details_json(self):
     client = Client(name=self.name, ip_address=self.ip_address, id=self.id)
     client.datasets = [
         Dataset(filename='foo.bar', id=1),
         Dataset(filename='test', id=3)
     ]
     self.assertDictEqual(
         client.details_json(), {
             'name': self.name,
             'ip_address': self.ip_address,
             'id': self.id,
             'datasets': [1, 3]
         })
    def test_get_nonempty_datasets_list(self):
        client = Client(name='Client', ip_address='127.0.0.1')
        first_dataset = Dataset(filename='test.mp3')
        second_dataset = Dataset(filename='movie.mp4')
        client.datasets = [first_dataset, second_dataset]
        db.session.add(client)
        db.session.commit()

        response = self.client.get('/datasets')
        response_json = response.get_json()

        assert_success(response)
        self.assertEqual(len(response_json), 2)
        self.assertDictEqual(response_json[0], first_dataset.json())
        self.assertDictEqual(response_json[1], second_dataset.json())
Example #14
0
def dbcreate():
    db.create_all()

    client = Client("Placeholder Client")
    category = Category("Placeholder Category")

    client.save()
    category.save()

    client_id = client.id
    category_id = category.id

    feature = Feature("Demo Feature", "Demo Feature Description", 1, client_id,
                      category_id, datetime(2018, 1, 1))
    feature.save()
 def search(client_id=None):
     client = Client()
     search_command = SearchCommand()
     result = search_command.execute(client, client_id)
     if not client_id:
         return render_template('index.html', clients=result.result)
     return result.result
 def create(self, client_create: ClientCreate) -> Client:
     data = client_create.dict()
     _, doc_ref = self.collection_ref.add(data)
     doc = doc_ref.get()
     if doc.exists:
         client = Client(id=doc.id, **doc.to_dict())
         return client
Example #17
0
def run():
    load_dotenv()

    # session = create_database()
    # user = User('UserName', '{discord_id}')
    #
    # session.add(user)

    TOKEN = os.getenv('DISCORD_TOKEN')

    intents = discord.Intents.default()  # All but the two privileged ones
    intents.members = True  # Subscribe to the Members intent

    asyncio.set_event_loop(asyncio.new_event_loop())
    client = Client(command_prefix='!', intents=intents)
    client.run(TOKEN)
Example #18
0
def create_client():
    client = Client.from_args('client', 'ui',
                              get_random_alpha_numeric_string(), 'ui',
                              '127.1.0.0', 'user_info')

    db.session.add(client)
    db.session.commit()
Example #19
0
    def test_patch_changing_owner_of_dataset(self):
        client1 = Client(name='Client1', ip_address='127.0.0.1')
        client2 = Client(name='Client2', ip_address='127.0.0.2')
        dataset = Dataset(filename='test.txt')
        client1.datasets = [dataset]
        db.session.add_all([client1, client2])
        db.session.commit()

        response = self.client.patch('/datasets/' + str(dataset.id),
                                     data=json.dumps({'client': client2.id}),
                                     content_type='application/json')

        assert_status_code_equal(response, status.HTTP_204_NO_CONTENT)
        self.assertEqual(client1.datasets, [])
        self.assertEqual(client2.datasets, [dataset])
        self.assertEqual(dataset.client, client2)
Example #20
0
    def post(self):
        input_data = request.get_json()
        self._validate_data(input_data)

        new_client = Client(name=input_data['name'], ip_address=input_data['ip_address'])
        if DbHelper.client_exists(new_client):
            abort(status.HTTP_409_CONFLICT, "Could not overwrite existing client. "
                                            "Use PATCH to modify resource or DELETE to remove it")

        return self._add_client(new_client)
Example #21
0
 def create(self, db: Session, *, obj_in: ClientCreate) -> Client:
     db_obj = Client(
         email=obj_in.email,
         hashed_password=get_password_hash(obj_in.password),
         full_name=obj_in.full_name,
     )
     db.add(db_obj)
     db.commit()
     db.refresh(db_obj)
     return db_obj
    def test_add_dataset(self):
        client = Client(name='Client', ip_address='127.0.0.1')
        db.session.add(client)
        db.session.commit()

        filename = 'foo.bar'
        response = self.client.post('/datasets', data=json.dumps({'client': client.id, 'filename': filename}),
                                    content_type='application/json')
        assert_successfully_created(response)

        self.assertEqual(Dataset.query.count(), 1)
        dataset = Dataset.query.first()
        self.assertEqual(dataset.client_id, client.id)
        self.assertEqual(dataset.client, client)
        self.assertEqual(dataset.filename, filename)
Example #23
0
    def new_client(
        self,
        institution_name,
        institution_url,
        institution_city,
        institution_country,
        institution_size,
        status,
        start_date,
        is_deleted=False,
    ):
        client = Client(
            institution_name=institution_name,
            institution_url=institution_url,
            institution_city=institution_city,
            institution_country=institution_country,
            institution_size=institution_size,
            status=status,
            start_date=start_date,
            is_deleted=is_deleted,
        )

        client.save()
        return client
    def test_add_two_datasets_for_same_client_successfully(self):
        filename1 = 'foo.txt'
        filename2 = 'bar.txt'
        client = Client(name='Client', ip_address='127.0.0.1')
        db.session.add(client)
        db.session.commit()

        response = self.client.post('/datasets', data=json.dumps({'client': client.id, 'filename': filename1}),
                                    content_type='application/json')
        assert_successfully_created(response)
        response = self.client.post('/datasets', data=json.dumps({'client': client.id, 'filename': filename2}),
                                    content_type='application/json')
        assert_successfully_created(response)

        self.assertEqual(len(client.datasets), 2)
        self.assertEqual(client.datasets[0].filename, filename1)
        self.assertEqual(client.datasets[1].filename, filename2)
Example #25
0
    def run():
        """
        Create clients seeder
        """
        data = [
            {
                'app_name': "password_grant",
                'client_secret': "sup3rs3cr3t",
                'client_id': "sup3rs3cr3t"
            },
            {
                'app_name':
                "google",
                'client_secret':
                "ZdbNXvmMTy9dcAK8oW-3QPOj",
                'client_id':
                "1091376735288-sgpfaq0suha3qakagrsig7bee58enkqr.apps.googleusercontent.com"
            },
            {
                'app_name': "facebook",
                'client_secret': "0463ed52bd8a400dd48d8e9cc246acc4",
                'client_id': "216608565531165"
            },
            {
                'app_name': "twitter",
                'client_secret':
                "eJBRnVvE0YplptEelYJOuHYw2YLdOf9v39YNnfdM6Rkv3kNShC",
                'client_id': "iJoptl48l8j5OseOI1lrS3r9N"
            },
            {
                # SET THIS ALSO IN android/app/src/main/res/values/string.xml
                'app_name': "mobile",
                'client_secret': "de6a4f2b416bca74714745f4372ad6e4",
                'client_id': "1429376450515465"
            }
        ]

        for _data in data:
            new_client = Client()
            new_client.app_name = _data['app_name']
            new_client.client_secret = _data['client_secret']
            new_client.client_id = _data['client_id']
            new_client.created_at = datetime.datetime.now()
            new_client.updated_at = datetime.datetime.now()
            db.session.add(new_client)
            db.session.commit()
    def test_create_dataset_with_userdefined_metadata(self):
        key = 'someKey'
        value = 'someValue'
        second_key ='key2'
        second_value = 'val'
        client = Client(name='Client', ip_address='127.0.0.1')
        db.session.add(client)
        db.session.commit()

        response = self.client.post('/datasets',
                                    data=json.dumps({'client': client.id, 'filename': 'foo.txt',
                                                     key: value, second_key: second_value}),
                                    content_type='application/json')

        assert_successfully_created(response)
        dataset = Dataset.query.first()
        assert_unordered_list_equal(dataset.get_keys(), [key, second_key])
        self.assertEqual(dataset.get_value(key), value)
        self.assertEqual(dataset.get_value(second_key), second_value)
Example #27
0
 def create(
     self, db: Session, *, obj_in: QueueCreate
 ) -> Queue:
     client_obj = Client(client_name=obj_in.client.client_name,
                         client_system=obj_in.client.client_system,
                         platform=obj_in.client.platform,
                         locale=obj_in.client.locale,
                         o2_status=obj_in.client.o2_status,
                         odyssey=obj_in.client.odyssey)
     db.add(client_obj)
     db.commit()
     db.refresh(client_obj)
     db_obj = Queue(client=client_obj,
                    arrival_time=datetime.utcnow(),
                    uuid=str(uuid.uuid4()),
                    pending=False,
                    in_progress=False)
     db.add(db_obj)
     db.commit()
     db.refresh(db_obj)
     return db_obj
 def list(self) -> List[Client]:
     clients = []
     for doc in self.collection_ref.stream():
         client = Client(id=doc.id, **doc.to_dict())
         clients.append(client)
     return clients
 def get(self, id: str) -> Client:
     doc_ref = self.collection_ref.document(id)
     doc = doc_ref.get()
     if doc.exists:
         return Client(id=doc.id, **doc.to_dict())
Example #30
0
def addClient(userInformation):

    client = Client()
    client.first_name = userInformation["first-name"]
    client.last_name = userInformation["last-name"]
    client.role = userInformation["role"]
    client.belonging = userInformation["belonging"]
    client.finance = userInformation["finance"]
    client.work_code = userInformation["work-code"]
    client.e_mail = userInformation["e-mail"]
    client.password = myhash(userInformation["password"])
    client.reference_list = userInformation["reference-list"]
    client.admin = userInformation["admin"]

    client.first_name_reading = userInformation["first-name-reading"]
    client.last_name_reading = userInformation["last-name-reading"]
    client.gender = userInformation["gender"]
    client.nationality = userInformation["nationality"]
    client.birthday = userInformation["birthday"]

    db.session.add(client)
    db.session.commit()