示例#1
0
def create_entries(factory):
    author = UserFactory()
    entries = []
    date1 = datetime.datetime(2012, 8, 12, 11, 0, 0)
    delta = datetime.timedelta(hours=4)
    date2 = datetime.datetime(2012, 10, 12, 11, 1, 0)
    if settings.USE_TZ:
        date1 = pytz.timezone(settings.TIME_ZONE).localize(date1, is_dst=None)
        date2 = pytz.timezone(settings.TIME_ZONE).localize(date2, is_dst=None)

    entries.append(
        factory.create(
            pk=1,
            author=author,
            title='Entry 1',
            published_on=date1,
            last_changed=date1 + delta,
            slug='entry-1',
            language='en',
        ))
    entries.append(
        factory.create(
            pk=2,
            author=author,
            title='Eintrag 1',
            published_on=date2,
            last_changed=date2 + delta,
            slug='eintrag-1',
            language='en',
        ))
    return entries
def create_entries(factory):
    author = UserFactory()
    entries = []
    date1 = datetime.datetime(2012, 8, 12, 11, 0, 0)
    delta = datetime.timedelta(hours=4)
    date2 = datetime.datetime(2012, 10, 12, 11, 1, 0)
    if settings.USE_TZ:
        date1 = pytz.timezone(settings.TIME_ZONE).localize(date1, is_dst=None)
        date2 = pytz.timezone(settings.TIME_ZONE).localize(date2, is_dst=None)

    entries.append(factory.create(
        pk=1,
        author=author,
        title='Entry 1',
        published_on=date1,
        last_changed=date1+delta,
        slug='entry-1',
        language='en',
    ))
    entries.append(factory.create(
        pk=2,
        author=author,
        title='Eintrag 1',
        published_on=date2,
        last_changed=date2+delta,
        slug='eintrag-1',
        language='en',
    ))
    return entries
示例#3
0
def pause_in_progress_with_ongoing_pomodoro(task_instance):
    pomodoro_in_progress = factory.create(klass=DateFrameFactory,
                                          task=task_instance,
                                          end=None,
                                          frame_type=0)
    pause_in_progress = factory.create(klass=DateFrameFactory,
                                       task=task_instance,
                                       end=None,
                                       frame_type=2)
    return pause_in_progress, pomodoro_in_progress
示例#4
0
def pomodoro_in_progress_with_breaks_and_pauses(task_instance):
    pomodoro_date_frame = factory.create(klass=DateFrameFactory,
                                         task=task_instance,
                                         end=None,
                                         frame_type=0)
    factory.create(klass=InnerDateFrameFactory,
                   task=task_instance,
                   frame_type=1,
                   start=get_time_delta({'minutes': 2}),
                   end=get_time_delta({'minutes': 4}))
    factory.create(klass=InnerDateFrameFactory,
                   task=task_instance,
                   frame_type=1,
                   start=get_time_delta({'minutes': 5}),
                   end=get_time_delta({'minutes': 7}))
    factory.create(klass=InnerDateFrameFactory,
                   task=task_instance,
                   frame_type=2,
                   start=get_time_delta({'minutes': 10}),
                   end=get_time_delta({'minutes': 12}))
    factory.create(klass=InnerDateFrameFactory,
                   task=task_instance,
                   frame_type=2,
                   start=get_time_delta({'minutes': 15}),
                   end=get_time_delta({'minutes': 19}))
    return pomodoro_date_frame
示例#5
0
def date_frame_in_progress_for_yesterday(task_instance):
    date_frame_instance = factory.create(klass=DateFrameFactory,
                                         task=task_instance,
                                         start=get_time_delta({'days': 1},
                                                              ahead=False),
                                         end=None)
    return date_frame_instance
示例#6
0
def duplicate_task_instance_in_second_project(task_instance,
                                              second_project_instance,
                                              priority_instance,
                                              project_instance):
    return factory.create(klass=TaskFactory,
                          priority=priority_instance,
                          project=second_project_instance,
                          name=task_instance.name)
示例#7
0
def completed_repeatable_task_instance(task_model, priority_instance,
                                       project_instance):
    return factory.create(klass=TaskFactory,
                          priority=priority_instance,
                          project=project_instance,
                          due_date=timezone.now(),
                          repeat_duration=timedelta(days=random.randint(1, 5)),
                          status=task_model.status_completed)
示例#8
0
    def test_view_one_resource(self):
        new_resource = create(ResourceFactory)
        url = f'/api/v1/resources/{new_resource.guid}/'

        response = self.client.get(url)
        self.assertEqual(response.status_code, status.HTTP_200_OK)
        self.assertEqual(response.data['title'], new_resource.title)
        self.assertEqual(response.data['description'],
                         new_resource.description)
示例#9
0
def create_chinese_entries(factory):
    entries = create_entries(factory)
    author = entries[0].author
    factory.create(pk=3,
                   author=author,
                   title='Entry 2 chinese traditional',
                   language='zh-hans',
                   translation_of=entries[0],
                   published_on=datetime.datetime(2012, 10, 12, 12, 0, 0),
                   last_changed=datetime.datetime(2012, 10, 12, 16, 0, 0),
                   slug='entry-2-cn')
    factory.create(pk=4,
                   author=author,
                   title='Entry 2 chinese simplified',
                   language='zh-hant',
                   translation_of=entries[0],
                   published_on=datetime.datetime(2012, 10, 12, 12, 0, 0),
                   last_changed=datetime.datetime(2012, 10, 12, 16, 0, 0),
                   slug='entry-2-tw')
示例#10
0
    def seed(self, source, file_location, who):
        db = self._get_db(who)

        programs = self._parse_source_args(source)

        for program in programs:
            seederClass = factory.create(program)

            seeder = seederClass(db, file_location=file_location)
            seeder.seed()
示例#11
0
def create_entries(factory):
    author = UserFactory()
    entries = []
    entries.append(factory.create(
        pk=1,
        author=author,
        title=u'Entry 1',
        published_on=datetime.datetime(2012,8,12, 11,0,0),
        last_changed=datetime.datetime(2012,8,12, 15,0,0),
        slug='entry-1'
    ))
    entries.append(factory.create(
        pk=2,
        author=author,
        title=u'Eintrag 1',
        published_on=datetime.datetime(2012,10,12, 11,0,0),
        last_changed=datetime.datetime(2012,10,12, 15,0,0),
        slug='eintrag-1'
    ))
    return entries
示例#12
0
def obsolete_date_frames(task_instance):
    obsolete_pomodoro = factory.create(klass=DateFrameFactory,
                                       task=task_instance,
                                       start=get_time_delta({'days': 8},
                                                            ahead=False),
                                       frame_type=0,
                                       end=None)
    obsolete_break = factory.create(klass=DateFrameFactory,
                                    task=task_instance,
                                    start=get_time_delta({'days': 8},
                                                         ahead=False),
                                    frame_type=1,
                                    end=None)
    obsolete_pause = factory.create(klass=DateFrameFactory,
                                    task=task_instance,
                                    start=get_time_delta({'days': 8},
                                                         ahead=False),
                                    frame_type=2,
                                    end=None)
    return obsolete_pomodoro, obsolete_break, obsolete_pause
示例#13
0
def create_entries(factory):
    author = UserFactory()
    entries = []
    entries.append(factory.create(
        pk=1,
        author=author,
        title=u'Entry 1',
        published_on=datetime.datetime(2012, 8, 12, 11, 0, 0),
        last_changed=datetime.datetime(2012, 8, 12, 15, 0, 0),
        slug='entry-1'
    ))
    entries.append(factory.create(
        pk=2,
        author=author,
        title=u'Eintrag 1',
        published_on=datetime.datetime(2012, 10, 12, 11, 0, 0),
        last_changed=datetime.datetime(2012, 10, 12, 15, 0, 0),
        slug='eintrag-1'
    ))
    return entries
示例#14
0
def _generate_many_to_many_list(factory):
    """Helper function to help generate a list of related objects."""
    # Generate a list of elements with an emphasis on 0- and
    # 1-length lists
    length = random.randint(0, 2)
    if length == 2:
        length = random.randint(2, 30)

    lst = [factory.create() for i in range(length)]

    return lst
示例#15
0
    def update(self, source, who):
        db = self._get_db(who)

        programs = self._parse_source_args(source)

        for program in programs:
            seederClass = factory.create(program)

            seeder = seederClass(db)
            seeder.update()

        self._update_params_table(who)
示例#16
0
    def test_delete_one_resource(self):
        records = create_batch(ResourceFactory, 10)
        new_resource = create(ResourceFactory)
        url = f'/api/v1/resources/{new_resource.guid}/'

        response = self.client.delete(url)
        self.assertEqual(response.status_code, status.HTTP_204_NO_CONTENT)

        subsequent_response = self.client.get(url)
        self.assertEqual(subsequent_response.status_code,
                         status.HTTP_404_NOT_FOUND)

        count_check = self.client.get('/api/v1/resources/')
        self.assertEqual(count_check.data['count'], 10)
def create_chinese_entries(factory):
    entries = create_entries(factory)
    author = entries[0].author
    factory.create(
        pk=3,
        author=author,
        title='Entry 2 chinese traditional',
        language='zh-cn',
        translation_of=entries[0],
        published_on=datetime.datetime(2012, 10, 12, 12, 0, 0),
        last_changed=datetime.datetime(2012, 10, 12, 16, 0, 0),
        slug='entry-2-cn'
    )
    factory.create(
        pk=4,
        author=author,
        title='Entry 2 chinese simplified',
        language='zh-tw',
        translation_of=entries[0],
        published_on=datetime.datetime(2012, 10, 12, 12, 0, 0),
        last_changed=datetime.datetime(2012, 10, 12, 16, 0, 0),
        slug='entry-2-tw'
    )
示例#18
0
    def get_points(self, query, count=10, scope='*'):
        # type: (str, int, str) -> osisoftpy.structures.TypedList[Point]
        """

        :param query: 
        :param count: 
        :param scope: 
        :return: 
        """
        payload = {'q': query, 'count': count, 'scope': scope}
        log.debug(
            'Executing Query against PI Web WebAPI Indexed Search with '
            'the following parameters: Query: "%s", Count: "%s". Payload: %s',
            query, count, payload)
        r = self.session.get(self.url + '/search/query', params=payload)
        if r.status_code != requests.codes.ok:
            r.raise_for_status()
        else:
            data = r.json()
            log.debug('HTTP %s - Instantiating %s PI points', r.status_code,
                      get_count(data.get('Items', None)))
            factory = Factory(Point)
            items = list(map(lambda x: create(factory, x),
                             data.get('Items', None)))
            points = TypedList(Point)
            for point in items:
                points.append(point)
            log.debug('PI Point retrieval success! %s PI '
                      'point(s) were '
                      'found and instantiated.', get_count(points))

            if len(data['Errors']) != 0:
                for error in data['Errors']:
                    try:
                        log.warning('The PI Web WebAPI returned the '
                                    'following error while instantiating '
                                    'PI points. '
                                    'ErrorCode: {0}, Source: {1}, '
                                    'Message {2}'.format(
                            error['ErrorCode'], error['Source'],
                            error['Message']))
                    except Exception as e:
                        log.error('Exception encounted while '
                                  'instantiating '
                                  'PI points!', exc_info=True)

            return points
示例#19
0
    def test_patch_one_resource(self):
        new_resource = create(ResourceFactory)
        url = f'/api/v1/resources/{new_resource.guid}/'

        data = {
            "description":
            "A _diabolically irresponsible_ talk in which I celebrate modern Python coding by **abandoning all backwards compatibility** THE END",
            "author": "David Beazley",
            "tags": ["test tags", "testing", "python"]
        }

        response = self.client.patch(url, data, format='json')
        self.assertEqual(response.status_code, status.HTTP_200_OK)
        self.assertEqual(response.data['description'], data['description'])
        self.assertEqual(response.data['author'], data['author'])
        self.assertEqual(
            sorted(item['name'] for item in response.data['tags']),
            sorted(data['tags']))
示例#20
0
    def test_search_resources(self):
        create(ResourceFactory, title="Elm Crash-Course (Reactivate London)")
        create(ResourceFactory, title="elm Documentation")
        create(
            ResourceFactory,
            description=
            "The best place to start is the official guide. It will give you a solid foundation for creating applications with Elm. Once you have worked through that, the next place to look for documentation is on the packages you are using."
        )
        create(
            ResourceFactory,
            description=
            "Elm is a programming language targeted at the front end (runs in a browser, not on Node) that offers a different take on building dynamic web applications."
        )

        url = '/api/v1/resources/?search=Elm'
        response = self.client.get(url)
        self.assertEqual(response.status_code, status.HTTP_200_OK)
        self.assertEqual(response.data['count'], 4)
        self.assertContains(response, "Elm Crash-Course (Reactivate London)")
        self.assertContains(response, "or creating applications with Elm. ")
示例#21
0
def test_trackedmodel_get_description_create_url(factory):
    """Verify get_url() returns something for creating descriptions."""
    instance = factory.create()
    url = instance.get_url("description-create")

    assert url
示例#22
0
 def getattr(self, path):
     print 'UFS GETATTR C_F_S'
     return factory.create(FuseStat, os.stat(self._get_real_path(path)))
示例#23
0
def generate_mode(options):
    data = open_read_yaml(options.path[0])

    print pretty_xml(factory.create(parser.parse(data)))

    return 0
示例#24
0
def sub_task_instance(task_instance):
    return factory.create(klass=SubTaskFactory, task=task_instance)
示例#25
0
def date_frame_in_progress(task_instance):
    return factory.create(klass=DateFrameFactory, task=task_instance, end=None)
示例#26
0
 def create_object(self):
     factory = self.get_factory_class()
     return factory.create()
示例#27
0
 def test_create(self):
     obj = factory.create(FakeDjangoModel, foo='bar')
     self.assertEqual(obj.id, 1)
     self.assertEqual(obj.foo, 'bar')
示例#28
0
 def test_create(self):
     obj = factory.create(FakeModel, foo='bar')
     self.assertEqual(obj.id, 2)
     self.assertEqual(obj.foo, 'bar')
示例#29
0
    def test_delete_one_resource(self):
        new_resource = create(ResourceFactory)
        url = f'/api/v1/resources/{new_resource.guid}/'

        response = self.client.delete(url)
        self.assertEqual(response.status_code, status.HTTP_401_UNAUTHORIZED)
示例#30
0
    def test_patch_one_resource(self):
        new_resource = create(ResourceFactory)
        url = f'/api/v1/resources/{new_resource.guid}/'

        response = self.client.patch(url, {}, format='json')
        self.assertEqual(response.status_code, status.HTTP_401_UNAUTHORIZED)
示例#31
0
def date_frame_for_random_task(task_instance_for_random_project):
    return factory.create(klass=DateFrameFactory,
                          task=task_instance_for_random_project)
示例#32
0
 def test_create_custom_base(self):
     obj = factory.create(FakeModel, foo='bar', FACTORY_CLASS=factory.DjangoModelFactory)
     self.assertEqual(obj.id, 2)
     self.assertEqual(obj.foo, 'bar')
示例#33
0
def test_trackedmodel_get_create_url(factory):
    instance = factory.create()
    url = instance.get_url("create")

    assert url
示例#34
0
 def getattr(self, path):
     debug('UFS GETATTR C_F_S')
     return factory.create(FuseStat, os.stat(self._get_real_path(path)))
示例#35
0
import factory

fun = factory.create("operation.add")
print(fun.__name__)
print(fun(1, 2))
fun = factory.create("operation.minus")
print(fun.__name__)
print(fun(1, 2))
fun = factory.create("operation.multify")
示例#36
0
def date_frame_instance(task_instance):
    return factory.create(klass=DateFrameFactory, task=task_instance)
示例#37
0
def task_instance_for_random_project(project_instance_for_random_user):
    return factory.create(klass=TaskFactory,
                          project=project_instance_for_random_user)
示例#38
0
def sub_task_for_random_task(task_instance_for_random_project):
    return factory.create(klass=SubTaskFactory,
                          task=task_instance_for_random_project)
示例#39
0
 def coolstuff(self):
     create({"arg1": "coool", "arg2": "stuff"})
示例#40
0
def pause_in_progress(task_instance):
    return factory.create(klass=DateFrameFactory,
                          task=task_instance,
                          end=None,
                          frame_type=2)