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)
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)
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())
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()
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
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])
def __get_topic_with_number(self, topic: FlexioTopic) -> FlexioTopic: return FlexioTopic.build_from_api( self.__flexio.get_record(record=topic))
def read_topic_by_number(self, number: int) -> Topic: return FlexioTopic.build_from_api( FlexioClient(self.config_handler).get_record( FlexioTopic().with_number(number)))
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)))