Exemplo n.º 1
0
  def Start(self):
    fase_database.FaseDatabaseInterface.Set(
        fase_database.MockFaseDatabase(
            service_prog_list=[],
            screen_prog_list=[],
            user_list=[
                fase.User(user_id='321',
                          phone_number='+13216549870',
                          first_name='Edward',
                          last_name='Igushev',
                          datetime_added=datetime.datetime.utcnow())]),
        overwrite=True)

    datetime_now = datetime.datetime.utcnow()
    self.note_1 = notes_model.Note(note_id='321_1',
                                   user_id='321',
                                   header='Note 1 Header',
                                   text='Note 1 text',
                                   datetime=datetime_now+datetime.timedelta(days=1),
                                   favourite=False)
    self.note_2 = notes_model.Note(note_id='321_2',
                                   user_id='321',
                                   header='Note 2 Header',
                                   text='Note 2 text',
                                   datetime=datetime_now-datetime.timedelta(days=1),
                                   favourite=True)
    self.note_3 = notes_model.Note(note_id='321_3',
                                   user_id='321',
                                   header='Note 3 Header',
                                   text='Note 3 text',
                                   datetime=datetime_now,
                                   favourite=False)  
    notes_database.NotesDatabaseInterface.Set(
        notes_database.MockNotesDatabase([self.note_1, self.note_2, self.note_3]),
        overwrite=True)

    # Create Service
    self.device = fase_model.Device(device_type='Python', device_id='DeviceID')
    response = fase_server.FaseServer.Get().GetService(self.device)
    version_info = response.version_info
    session_info = response.session_info
    screen_info = response.screen_info
    screen = response.screen
    # Check present of main elements.
    screen.GetElement(id_='notes_frame')
    
    return version_info, session_info, screen_info, screen
Exemplo n.º 2
0
  def testNotes_EmptyHeader(self):
    version_info, session_info, screen_info, screen = self.Start()
    self.AssertNotes([], screen)

    # Create a Note.
    note = notes_model.Note(note_id=None,
                            user_id=None,
                            header='',
                            text='',
                            datetime=None,
                            favourite=False)

    # Add Note.
    version_info, session_info, screen_info, screen = self.AddNote(version_info, session_info, screen_info, note)
    self.AssertNotes([note], screen)
Exemplo n.º 3
0
 def note(self,
          store=True,
          repo_id='haiti',
          person_id=None,
          record_id=None,
          **kwargs):
     if not record_id:
         record_id = '%s.%s/Note.%d' % (repo_id, const.HOME_DOMAIN,
                                        model.UniqueId.create_id())
     key_name = '%s:%s' % (repo_id, record_id)
     params = copy.deepcopy(TestDataGenerator._DEFAULT_NOTE_PARAMS)
     params.update(kwargs)
     note = model.Note(key_name=key_name,
                       repo=repo_id,
                       person_record_id=person_id,
                       **params)
     if store:
         note.put()
     return note
Exemplo n.º 4
0
    def post(self, group_id, *args, **kwargs):
        """
        @apiVersion 0.1.0
        @api {post} /groups/{group_id}/notes/ Create a note.
        @apiName CreateNote
        @apiGroup Notes
        @apiDescription Create a new Note.
        @apiUse TokenRequired
        @apiUse BadRequest
        @apiUse SuccessfullyCreated
        @apiParam {String} name The notes name.
        @apiParam {String} topic The notes topic.
        @apiParam {String} [content] The notes content.
        @apiParam {image} [file] An optional image.
        @apiUse NoSuchUserError
        @apiUse CouldNotBeSavedError
        """

        user_id = kwargs.get('user')['user_id']
        parser = self.post_parser()
        args = parser.parse_args()
        post_in_group = group_model.Group.query.get(group_id)
        parent_user = user_model.User.query.get(user_id)
        if not parent_user or not post_in_group:
            return response.simple_response('no such user or group',
                                            status=404)
        if not parent_user.is_member_of(post_in_group):
            return response.simple_response(
                'you must be a member of this group', status=401)
        new_note = model.Note(args['name'], args['topic'], args['content'])
        if 'file' in request.files:
            path_ = upload.get_uploaded_image_and_save(
                save_to=config.Config().UPLOAD_FOLDER_NOTES_IMAGES)
            new_note.image_path = path_
        new_note.creator = parent_user
        new_note.group = post_in_group
        db.session.add(new_note)
        db.session.commit()
        return response.simple_response('note created ' + str(new_note.id),
                                        status=201)
Exemplo n.º 5
0
  def testNotes_Start_SignIn_AddNote(self):
    version_info, session_info, screen_info, screen = self.Start()
    self.AssertNotes([], screen)

    # Sign In.
    version_info, session_info, screen_info, screen = (
        fase_sign_in_test_util.SignInProcedure(
            version_info, session_info, screen_info,
            sign_in_id_list=[fase.NAVIGATION_ID, 'sign_in_button'], sign_in=True, phone_number='+13216549870'))
    self.AssertNotes([self.note_1, self.note_2, self.note_3], screen)

    # Create a Note.
    note_4 = notes_model.Note(note_id=None,
                              user_id=None,
                              header='Note 4 Header',
                              text='Note 4 text',
                              datetime=None,
                              favourite=False)

    # Add Note.
    version_info, session_info, screen_info, screen = self.AddNote(version_info, session_info, screen_info, note_4)
    self.AssertNotes([self.note_1, self.note_2, self.note_3, note_4], screen)
Exemplo n.º 6
0
  def testNotes_Start_AddNote_SignUn(self):
    version_info, session_info, screen_info, screen = self.Start()
    self.AssertNotes([], screen)

    # Create a Note.
    note_4 = notes_model.Note(note_id=None,
                              user_id=None,
                              header='Note 4 Header',
                              text='Note 4 text',
                              datetime=None,
                              favourite=False)

    # Add Note.
    version_info, session_info, screen_info, screen = self.AddNote(version_info, session_info, screen_info, note_4)
    self.AssertNotes([note_4], screen)

    # Sign In.
    version_info, session_info, screen_info, screen = (
        fase_sign_in_test_util.SignInProcedure(
            version_info, session_info, screen_info,
            sign_in_id_list=[fase.NAVIGATION_ID, 'sign_in_button'], sign_in=False,
            phone_number='+19876543210', first_name='Edward Junior', last_name='Igushev'))
    self.AssertNotes([note_4], screen)
Exemplo n.º 7
0
 def OnSaveNote(self, screen, element):
     note_id = screen.GetStringVariable(id_='current_note_id').GetValue()
     user_id = self.GetUserId()
     datetime_now = datetime.datetime.utcnow()
     # If new note.
     if note_id is None:
         note_id_hash = hashlib.md5()
         note_id_hash.update(
             datetime_now.strftime(
                 fase.DATETIME_FORMAT_HASH).encode('utf-8'))
         note_id_hash.update(user_id.encode('utf-8'))
         note_id = note_id_hash.hexdigest()
     note_frame = screen.GetFrame(id_='note_frame')
     note = notes_model.Note(
         note_id=note_id,
         user_id=user_id,
         header=note_frame.GetElement(id_='header_text').GetText(),
         text=note_frame.GetElement(id_='text_text').GetText(),
         datetime=datetime_now,
         favourite=screen.GetStringVariable(
             id_='favourite_bool').GetValue())
     notes_database.NotesDatabaseInterface.Get().AddNote(note,
                                                         overwrite=True)
     return self._DisplayNotes(screen)
import random
import lorem
import model

import datetime

current_time = datetime.datetime.utcnow()

def get_time():
  global current_time
  delta = datetime.timedelta(seconds=random.randint(1,50))
  current_time += delta
  return current_time

# We're going to generate some data
notes = []

for n in range(0,250):
  note = model.Note(type=model.NoteType.Text)
  if(n < 10 or random.randint(0,100)>80):
    note.parent = None
  else:
    note.parent = random.choice(notes)
  note.data = {'value':lorem.paragraph()}
  note.created = get_time()
  notes.append(note)
  model.db.session.add(note)

model.db.session.commit()