Esempio n. 1
0
 def test_update(self):
     create_response = self.client.post(
         '/api/messages/',
         data=JsonUtility.to_json({
             'recipient':
             'test',
             'content':
             'hello world',
             'created':
             TimestampUtility.now().timestamp()
         }),
         content_type='application/json',
         headers={'Authorization': 'Bearer {}'.format(self.access_token)})
     self.assertTrue(create_response.status_code == 200)
     create_json = json.loads(create_response.data)
     update_response = self.client.put(
         '/api/messages/',
         data=JsonUtility.to_json({
             'identifier':
             create_json['result']['identifier'],
             'recipient_received':
             TimestampUtility.now().timestamp()
         }),
         content_type='application/json',
         headers={'Authorization': 'Bearer {}'.format(self.access_token)})
     self.assertTrue(update_response.status_code == 200)
     create_json = json.loads(update_response.data)
     self.assertTrue(create_json['operation'] == 'messages.update')
Esempio n. 2
0
def create():
    identifier = g.get('identifier', None)
    source_parameters = request.get_json()
    source_repository = SourceRepository()
    existing = source_repository.retrieve_source_by_value(
        source_parameters['value'])
    if len(existing) > 0:
        current = existing[0]
        updated = source_repository.update(
            Source(id=current.id,
                   value=current.value,
                   source_type=current.source_type,
                   verifications=current.verifications + 1,
                   created=current.created))
        result = Response(ResponseWrapper.wrap(identifier, 'sources.create',
                                               updated),
                          status=200,
                          mimetype='application/json')
        return result
    else:
        created = source_repository.create_source(
            Source(value=source_parameters['value'],
                   source_type=source_parameters['source_type'],
                   verifications=1,
                   created=TimestampUtility.now()))
        result = Response(ResponseWrapper.wrap(identifier, 'sources.create',
                                               created),
                          status=200,
                          mimetype='application/json')
        return result
 def test_retrieve_parameters(self):
     item = self.repository.create_parameters(
         Parameters(content="ParameterTest",
                    created=TimestampUtility.now()))
     self.assertEqual(item.content, 'ParameterTest')
     items = self.repository.retrieve_parameters()
     self.assertGreater(len(items), 1)
 def test_create_parameters(self):
     item = self.repository.create_source(
         Source(
             value='123-456-7890',
             source_type="blacklist",
             verifications=10,
             created=TimestampUtility.now()
         )
     )
     self.assertEqual(item.value, '123-456-7890')
 def test_retrieve_sources(self):
     item = self.repository.create_source(
         Source(
             value='123-456-7890',
             source_type="blacklist",
             verifications=10,
             created=TimestampUtility.now()
         )
     )
     self.assertEqual(item.value, '123-456-7890')
     items = self.repository.retrieve_sources()
     self.assertGreater(len(items), 1)
Esempio n. 6
0
def create():
    identifier = get_jwt_identity()
    telemetry_parameters = request.get_json()
    telemetry_repository = TelemetryRepository()
    result = telemetry_repository.create_telemetry(
        Telemetry(creator=identifier,
                  data_type=telemetry_parameters['data_type'],
                  content=telemetry_parameters['content'],
                  created=TimestampUtility.parse(
                      telemetry_parameters['created']),
                  received=TimestampUtility.now()))
    return Response(ResponseWrapper.wrap(identifier, 'telemetry.create',
                                         result),
                    status=200,
                    mimetype='application/json')
 def test_create(self):
     create_response = self.client.post(
         '/api/parameters/',
         data=JsonUtility.to_json({
             'content':
             'hello world',
             'created':
             TimestampUtility.now(),
             'key':
             'p4ZfOJxhXJOU5VE9mdPX8Mo5V8dveda1bCUQaQ4QzHo06nrklJxRvdNpUZSE4WnG'
         }),
         content_type='application/json')
     self.assertTrue(create_response.status_code == 200)
     create_json = json.loads(create_response.data)
     self.assertTrue(
         create_json['message'] == 'classifier parameters updated')
Esempio n. 8
0
def create():
    message_parameters = request.get_json()
    if message_parameters['key'] == PARAMETERS_KEY:
        parameters_repository = ParametersRepository()
        parameters_repository.create_parameters(
            Parameters(content=json.dumps(message_parameters['content']),
                       created=TimestampUtility.now()))
        result = Response(json.dumps(
            {'message': 'classifier parameters updated'}),
                          status=200,
                          mimetype='application/json')
        return result
    else:
        result = Response(json.dumps({'message': 'unknown'}),
                          status=401,
                          mimetype='application/json')
        return result
Esempio n. 9
0
def create():
    identifier = g.get('identifier', None)
    message_parameters = request.get_json()
    message_repository = MessageRepository()
    message = message_repository.create_message(
        Message(identifier=RandomUtility.random_string(32),
                sender=identifier,
                recipient=message_parameters['recipient'],
                content=message_parameters['content'],
                state=MessageState.PENDING,
                created=TimestampUtility.parse(message_parameters['created']),
                received=TimestampUtility.now(),
                recipient_received=None))
    result = Response(ResponseWrapper.wrap(identifier, 'messages.create',
                                           message),
                      status=200,
                      mimetype='application/json')
    return result
Esempio n. 10
0
    def test_register(self):
        register_data = {
            'identifier': 'test2_{}'.format(RandomUtility.random_string(6)),
            'secret': 'test2',
            'code':
            'yRK3LxunjCFrovCXKyG32nB3pyST7ddE40T8FlxK8CCn75EyGr5jTanGyMqJ',
            'profile': 'profile',
            'recovery': 'recovery'
        }
        response = requests.post(
            'https://eps-scams.appspot.com/api/authentication/register',
            json=register_data)
        self.assertTrue(response.status_code == 200)
        login_data = {
            'identifier': register_data['identifier'],
            'secret': register_data['secret']
        }
        response = requests.post(
            'https://eps-scams.appspot.com/api/authentication/login',
            json=login_data)
        self.assertTrue(response.status_code == 200)
        login_json = response.json()
        access_token = login_json['result']['access_token']
        self.assertTrue(access_token is not None)

        create_response = requests.post(
            'https://eps-scams.appspot.com/api/messages/',
            json={
                'recipient': 'test',
                'content': 'hello world',
                'created': TimestampUtility.now().timestamp()
            },
            headers={'Authorization': 'Bearer {}'.format(access_token)})
        self.assertTrue(create_response.status_code == 200)
        retrieve_response = requests.get(
            'https://eps-scams.appspot.com/api/messages/',
            headers={'Authorization': 'Bearer {}'.format(access_token)})
        self.assertTrue(retrieve_response.status_code == 200)
        retrieve_json = retrieve_response.json()
        self.assertTrue(retrieve_json['operation'] == 'messages.retrieve')
Esempio n. 11
0
 def test_retrieve(self):
     create_response = self.client.post(
         '/api/parameters/',
         data=JsonUtility.to_json({
             'content':
             'hello world',
             'created':
             TimestampUtility.now(),
             'key':
             'p4ZfOJxhXJOU5VE9mdPX8Mo5V8dveda1bCUQaQ4QzHo06nrklJxRvdNpUZSE4WnG'
         }),
         content_type='application/json')
     self.assertTrue(create_response.status_code == 200)
     create_json = json.loads(create_response.data)
     self.assertTrue(
         create_json['message'] == 'classifier parameters updated')
     retrieve_response = self.client.get(
         '/api/parameters/',
         content_type='application/json',
         headers={'Authorization': 'Bearer {}'.format(self.access_token)})
     self.assertTrue(retrieve_response.status_code == 200)
     retrieve_json = json.loads(retrieve_response.data)
     self.assertTrue(retrieve_json['operation'] == 'parameters.retrieve')
 def test_create_parameters(self):
     item = self.repository.create_parameters(
         Parameters(content="ParameterTest",
                    created=TimestampUtility.now()))
     self.assertEqual(item.content, 'ParameterTest')