Beispiel #1
0
    def test_post_record(self):
        topic: FlexioTopic = FlexioTopic()
        topic.title = 'test'
        topic.body = 'dudu'
        topic.state = IssueState.OPEN

        print(topic.to_api_dict())

        r: Response = FlexioClient(
            self.config_handler).post_record(record=topic)

        topic_created: FlexioTopic = FlexioTopic.build_from_api(r.json())
        self.assertEqual(topic.title, topic_created.title)
        self.assertEqual(topic.body, topic_created.body)
        self.assertEqual(topic.state, topic_created.state)

        print(topic_created.__dict__())

        self.assertIs(r.status_code, 200)
        falsy_config_handler = ConfigHandler(CONFIG_DIR)
        falsy_config_handler.config = Config().with_flexio(
            ConfigFlexio(activate=True, user_token='dudu'))
        r: Response = FlexioClient(falsy_config_handler).post_record(
            record=topic)
        self.assertIsNot(r.status_code, 200)
Beispiel #2
0
    def test_get_topic_by_number(self):
        topic: FlexioTopic = FlexioTopic().with_number(11)
        r: dict = FlexioClient(self.config_handler).get_record(record=topic)

        self.assertIsNotNone(r)
        record: FlexioTopic = FlexioTopic.build_from_api(r)
        self.assertEqual(topic.number, record.number)

        topic2: FlexioTopic = FlexioTopic().with_number(-5)
        with self.assertRaises(FileNotFoundError):
            FlexioClient(self.config_handler).get_record(record=topic2)
Beispiel #3
0
 def test_get_total(self):
     topic: FlexioTopic = FlexioTopic()
     r: Range = FlexioClient(self.config_handler).get_total(resource=topic)
     print('accept_range : ' + str(r.accept_range))
     print('offset : ' + str(r.offset))
     print('limit : ' + str(r.limit))
     print('total : ' + str(r.total))
    def __attach(self) -> bool:

        topic_number: int
        if self.__would_attach_topics():

            for topic_number in self.__topics_number():

                request_topic: FlexioTopic = FlexioTopic().with_number(
                    topic_number)

                try:
                    Log.info('waiting... from Flexio... Topic : ' +
                             str(topic_number))
                    topic: FlexioTopic = self.__get_topic_with_number(
                        request_topic)
                    CommonTopic.print_resume_topic(topic)
                    self.__topics.append(topic)
                except FileNotFoundError:
                    Log.error(Fg.FAIL.value + 'Topic not found : retry' +
                              Fg.RESET.value)
                    self.__topics = []
                    return self.process()
            return True
        else:
            return False
Beispiel #5
0
 def build_from_api(cls, json: dict) -> FlexioIssue:
     issue: FlexioIssue = FlexioIssue()
     issue.id = json.get(cls.RECORD_ID)
     issue.github_number = json.get(cls.GITHUB_NUMBER_ID)
     issue.topic = FlexioTopic().with_id(json.get(cls.TOPIC_ID))
     issue.github_title = json.get(cls.GITHUB_TITLE_ID)
     issue.github_url = json.get(cls.GITHUB_URL_ID)
     return issue
    def __get_last_100_records(self) -> List[dict]:
        topic: FlexioTopic = FlexioTopic()
        r: Range = self.__flexio.get_total(resource=topic)

        range: Range = Range()
        range.limit = r.total
        range.offset = 0 if r.total < r.accept_range else r.total - r.accept_range

        resp_records: Response = self.__flexio.get_records(topic, range)

        return resp_records.json()
Beispiel #7
0
    def test_get_last_100_records(self):
        topic: FlexioTopic = FlexioTopic()
        r: Range = FlexioClient(self.config_handler).get_total(resource=topic)

        range: Range = Range()
        range.limit = r.total
        range.offset = 0 if r.total < r.accept_range else r.total - r.accept_range

        resp_records: Response = FlexioClient(self.config_handler).get_records(
            topic, range)

        print(resp_records.headers)
        print(resp_records.json())

        for t_d in resp_records.json():
            t: FlexioTopic
            t = FlexioTopic.build_from_api(t_d)
            print('{topic_number!s} : {topic_title!s}'.format(
                topic_number=t.number, topic_title=t.title))

        self.assertIn(resp_records.status_code, [200, 206])
Beispiel #8
0
    def test_get_last_record(self):
        topic: FlexioTopic = FlexioTopic()
        # topics.number = 2

        r: Response = FlexioClient(self.config_handler).get_records(
            record=topic, range=Range())

        print(r.headers)
        print(r.json())

        self.assertIn(r.status_code, [200, 206])

        expected_record_from_api: FlexioTopic = FlexioTopic.build_from_api(
            r.json()[0])

        r2: Response = FlexioClient(self.config_handler).get_records(
            record=expected_record_from_api, range=Range())

        record_from_api: FlexioTopic = FlexioTopic.build_from_api(r2.json()[0])

        self.assertDictEqual(record_from_api.to_api_dict(),
                             expected_record_from_api.to_api_dict())
Beispiel #9
0
    def __input_topic(self):
        issue: FlexioTopic = FlexioTopic()
        title: str = ''

        while not len(title) > 0:
            title = input(fg.red + '[required]' + fg.rs + ' Title : ')
        issue.title = title

        body: str = input('Description : ')
        if body:
            issue.body = body

        return issue
Beispiel #10
0
 def __list_topics(self, count: int):
     Log.info('waiting... Flexio... last 100 Topics')
     records: List[dict] = self.__get_last_100_records()
     for t_d in records:
         t: FlexioTopic
         t = FlexioTopic.build_from_api(t_d)
         print(
             '{fg_cyan}{topic_number!s} : {topic_title!s}{reset_fg}'.format(
                 fg_cyan=Fg.INFO.value,
                 reset_fg=Fg.RESET.value,
                 topic_number=t.number,
                 topic_title=t.title))
     return self.__topics_number()
Beispiel #11
0
    def process(self) -> Topic:
        self.__start_message()

        self.__start_message_topic()

        topic: FlexioTopic = self.__input_topic()

        r: Response = self.__post_topic(topic)

        if r.status_code == 200:
            topic_created: FlexioTopic = FlexioTopic.build_from_api(r.json())
            print(topic_created.to_api_dict())
            self.__resume_topic(topic_created)
            topic = topic_created
        else:
            raise FlexioRequestApiError(r)

        return topic
Beispiel #12
0
 def __get_topic_with_number(self, topic: FlexioTopic) -> FlexioTopic:
     return FlexioTopic.build_from_api(
         self.__flexio.get_record(record=topic))
Beispiel #13
0
 def read_topic_by_number(self, number: int) -> Topic:
     return FlexioTopic.build_from_api(
         FlexioClient(self.config_handler).get_record(
             FlexioTopic().with_number(number)))
Beispiel #14
0
 def from_default(self, default_topic: DefaultTopic) -> Topic:
     return FlexioTopic.build_from_api(
         FlexioClient(self.config_handler).get_record(
             FlexioTopic().with_number(default_topic.number)))
Beispiel #15
0
 def topic_builder(self) -> Topic:
     return FlexioTopic()