コード例 #1
0
    def test_get_week_post_does_not_save_event_ending_on_the_next_day(
        self, default_user
    ):
        self.__insert_week()

        wrong_end_event = {
            "event-id": -1,
            "title": "test_title",
            "description": "test_description",
            "location": "test_location",
            "start_date": "2020-10-20",
            "start_time": "02:00:00",
            "end_date": "2020-10-21",
            "end_time": "01:00:00",
            "business_hour": 1,
            "action": "Save",
            "guest-name": "",
        }

        r = self.client.post(f"/{YEAR}/{WEEK}", data=wrong_end_event)

        template, context = self.rendered_templates[0]

        AssertThat(template.name).IsEqualTo("event.html")
        AssertThat(r.data).Contains(b"Event ends on a different day!")
コード例 #2
0
    def test_create_app_sets_current_year(self):
        app = create_app()

        AssertThat(app.jinja_env.globals["current_year"]).IsEqualTo(
            datetime.now().isocalendar()[0])
        AssertThat(app.jinja_env.globals["current_week"]).IsEqualTo(
            datetime.now().isocalendar()[1])
コード例 #3
0
def test_brk_will_push_pc_and_ps_onto_the_stack(cpu):
    """BRKWillPushPCandPSOntoTheStack"""
    cpu.reset_to(0xFF00)
    cpu.Memory[0xFF00] = OpCodes.INS_BRK
    expected_cycles = 7
    cpu_copy = copy.copy(cpu)
    old_sp = cpu_copy.stack_pointer

    # When:
    cycles_used = cpu.execute(expected_cycles)

    # Then:
    AssertThat(expected_cycles).IsEqualTo(cycles_used)
    AssertThat(cpu.Memory[(0x100 | old_sp) - 0]).IsEqualTo(0xFF)
    """https://www.c64-wiki.com/wiki/BRK
    Note that since BRK increments the program counter by 
    2 instead of 1, it is advisable to use a NOP after it 
    to avoid issues"""
    AssertThat(cpu.Memory[(0x100 | old_sp) - 1]).IsEqualTo(0x02)
    AssertThat(cpu.Memory[(0x100 | old_sp) - 2]).IsEqualTo(
        cpu_copy.processor_status | ProcessorStatus.UnusedFlagBit | ProcessorStatus.BreakFlagBit
    )

    """https://wiki.nesdev.com/w/index.php/Status_flags
    Instruction	|Bits 5 and 4	| Side effects after pushing 
    BRK			|	11			| I is set to 1 """
    AssertThat(cpu.Flag.I).IsTruthy()
コード例 #4
0
async def test_get_playlist_info(response_get_mock: MagicMock, ) -> None:
    """Test get playlist info if everything is fine."""
    playlist_id: str = "test"
    expected_tracks: List[Dict[str, Any]] = [{"name": "test"}]
    expected_playlist: Dict[str, Any] = {
        "url": "test_url",
        "name": "test",
        "spotify_id": playlist_id,
    }
    response_data: Dict[str, Any] = {
        "external_urls": {
            "spotify": expected_playlist["url"]
        },
        "name": expected_playlist["name"],
        "tracks": {
            "items": expected_tracks
        },
    }
    response_get_mock.return_value = get_response_mock(
        method="POST",
        response_data=response_data,
        valid=True,
    )

    playlist_info, tracks = await get_playlist_info(playlist_id=playlist_id,
                                                    access_token="test")

    AssertThat(playlist_info).IsEqualTo(expected_playlist)
    AssertThat(tracks).IsEqualTo(expected_tracks)
コード例 #5
0
    def test_event_does_not_render_guest_registration(self, default_user):
        week = Week(year=2020, week_num=2)
        db.session.add(week)
        event = Event(
            event_type=1,
            title="test_event",
            start="2020-01-06 00:00:00",
            end="2020-01-06 01:00:00",
            week_id=week.id,
            user_id=default_user.id,
        )
        db.session.add(event)
        db.session.commit()

        r = self.client.post(
            "/event",
            data={
                "year": "2020",
                "week": "2",
                "hour": "0",
                "day": "0"
            },
        )

        template, context = self.rendered_templates[0]

        AssertThat(r.data).Contains(b'checked id="businesshour"')
        AssertThat(r.data).Contains(b'placeholder="Guest name here"')
コード例 #6
0
ファイル: share_test.py プロジェクト: kovrichard/mycalendar
    def test_get_share_link_creates_shareable_link_correctly(
        self, default_user
    ):
        r = self.client.get(
            "/get-share-link",
            query_string={
                "expiration": (datetime.now() + timedelta(days=7)).strftime(
                    "%Y-%m-%d"
                ),
                "share-content": "true",
            },
        )

        now = datetime.now().isocalendar()

        token = re.search(
            f"{current_app.config['CALENDAR_URL']}/{now[0]}/{now[1]}/shared-calendar/(.*)",
            r.json["token"],
        ).group(1)
        decoded_token = UserAccess(
            current_app.config["SHARING_TOKEN_SECRET"]
        ).decode(token)

        AssertThat(decoded_token["user_id"]).IsEqualTo(default_user.id)
        AssertThat(decoded_token["share_content"]).IsTrue()
コード例 #7
0
ファイル: share_test.py プロジェクト: kovrichard/mycalendar
    def test_share_renders_template(self, default_user):
        r = self.client.get("/share")

        template, context = self.rendered_templates[0]

        AssertThat(r.status_code).IsEqualTo(200)
        AssertThat(template.name).IsEqualTo("share.html")
コード例 #8
0
    def test_get_week_event_insertion_handles_wrongly_formatted_time(
        self, default_user
    ):
        self.__insert_week()

        wrong_time_event = {
            "event-id": -1,
            "title": "test_title",
            "description": "test_description",
            "location": "test_location",
            "start_date": "2020-10-20",
            "start_time": "02:00",
            "end_date": "2020-10-20",
            "end_time": "03:00",
            "business_hour": 1,
            "action": "Save",
            "guest-name": "",
        }

        r = self.client.post(f"/{YEAR}/{WEEK}", data=wrong_time_event)

        template, context = self.rendered_templates[0]

        AssertThat(template.name).IsEqualTo("week.html")
        AssertThat(r.data).Contains(wrong_time_event["title"].encode())
コード例 #9
0
ファイル: test_base.py プロジェクト: beatMeDev/beatMeBackend
async def test_base_auth_route_on_post_user_created(
    set_mock: MagicMock,
    user_fixture: User,
) -> None:
    """
    Check auth handler when AuthAccount is not exists, but User exists and logged in,
    AuthAccount should be created and added for user,
    tokens should be returned.
    """
    set_mock.return_value = asyncio.Future()
    set_mock.return_value.set_result(True)
    route = get_patched_route()
    route_handler = route.get_route_handler()
    request: Request = await get_auth_request(method="POST",
                                              user_id=str(user_fixture.id))

    response: ORJSONResponse = await route_handler(request)
    response_body = loads(response.body)
    auth_account: AuthAccount = await AuthAccount.get(_id=AUTH_ACCOUNT_ID,
                                                      user=user_fixture)
    user: User = await User.get(auth_accounts__in=[auth_account])

    AssertThat(AuthOut(**response_body).validate(response_body)).IsNotEmpty()
    AssertThat(auth_account).IsNotNone()
    AssertThat(user).IsNotNone()
コード例 #10
0
    def test_event_does_not_render_events_of_other_users(self, default_user):
        user2 = User(username="******", password="******")
        db.session.add(user2)

        event = Event(
            event_type=1,
            title="<title>",
            description="<desc>",
            location="<loc>",
            start="2020-10-20 00:00:00",
            end="2020-10-20 01:00:00",
            user_id=user2.id,
        )

        db.session.add(event)
        db.session.commit()

        r = self.client.post(
            "/event",
            data={
                "year": "2020",
                "week": "43",
                "hour": "0",
                "day": "1"
            },
        )

        AssertThat(r.status_code).IsEqualTo(200)
        template, context = self.rendered_templates[0]

        AssertThat(context["event"]).IsEqualTo(None)
コード例 #11
0
    def test_get_week_post_does_not_save_event_shorter_than_one_hour(
        self, default_user
    ):
        self.__insert_week()

        short_event = {
            "event-id": -1,
            "title": "test_title",
            "description": "test_description",
            "location": "test_location",
            "start_date": "2020-10-20",
            "start_time": "02:00:00",
            "end_date": "2020-10-20",
            "end_time": "02:59:00",
            "business_hour": 1,
            "action": "Save",
            "guest-name": "",
        }

        r = self.client.post(f"/{YEAR}/{WEEK}", data=short_event)

        template, context = self.rendered_templates[0]

        AssertThat(template.name).IsEqualTo("event.html")
        AssertThat(r.data).Contains(b"Event cannot be shorter, than 1 hour!")
コード例 #12
0
    def test_get_week_post_does_not_save_overlapping_event(
        self, start_time, end_time, default_user
    ):
        week = self.__insert_week()
        self.__insert_event(default_user.id, week.id)

        overlapping_event = {
            "event-id": -1,
            "title": "test_title",
            "description": "test_description",
            "location": "test_location",
            "start_date": "2020-10-20",
            "start_time": start_time,
            "end_date": "2020-10-20",
            "end_time": end_time,
            "business_hour": 1,
            "action": "Save",
            "guest-name": "",
        }

        r = self.client.post(f"/{YEAR}/{WEEK}", data=overlapping_event)

        template, context = self.rendered_templates[0]

        AssertThat(template.name).IsEqualTo("event.html")
        AssertThat(r.data).Contains(b"Overlapping event!")
コード例 #13
0
    def test_get_week_post_does_not_save_events_with_equal_end_and_start(
        self, default_user
    ):
        self.__insert_week()

        wrong_end_event = {
            "event-id": -1,
            "title": "test_title",
            "description": "test_description",
            "location": "test_location",
            "start_date": "2020-10-20",
            "start_time": "02:00:00",
            "end_date": "2020-10-20",
            "end_time": "02:00:00",
            "business_hour": 1,
            "action": "Save",
            "guest-name": "",
        }

        r = self.client.post(f"/{YEAR}/{WEEK}", data=wrong_end_event)

        template, context = self.rendered_templates[0]

        AssertThat(template.name).IsEqualTo("event.html")
        AssertThat(r.data).Contains(
            b"End of event cannot be earlier than (or equal to) its start!"
        )
コード例 #14
0
    def test_get_week_post_saves_event_to_db(self, default_user):
        self.__insert_week()
        r = self.client.post(f"/{YEAR}/{WEEK}", data=TEST_EVENT)

        AssertThat(r.status_code).IsEqualTo(200)
        event = Event.query.filter_by(title=TEST_EVENT["title"]).first()

        AssertThat(event.title).IsEqualTo(TEST_EVENT["title"])
        AssertThat(event.description).IsEqualTo(TEST_EVENT["description"])
        AssertThat(event.location).IsEqualTo(TEST_EVENT["location"])
        AssertThat(event.start).IsEqualTo(
            datetime.strptime(
                f"{TEST_EVENT['start_date']} {TEST_EVENT['start_time']}",
                "%Y-%m-%d %H:%M:%S",
            )
        )
        AssertThat(event.end).IsEqualTo(
            datetime.strptime(
                f"{TEST_EVENT['end_date']} {TEST_EVENT['end_time']}",
                "%Y-%m-%d %H:%M:%S",
            )
        )
        AssertThat(event.event_type).IsEqualTo(TEST_EVENT["business_hour"])

        week = Week.query.filter_by(year=YEAR, week_num=WEEK).first()

        AssertThat(len(week.events)).IsEqualTo(1)
        AssertThat(week.events[0].title).IsEqualTo(TEST_EVENT["title"])

        AssertThat(week.events[0].user_id).IsEqualTo(default_user.id)
コード例 #15
0
    def test_post_week_handles_invalid_week(
        self, year, week, expected_week, default_user
    ):
        r = self.client.post(f"/{year}/{week}", data=TEST_EVENT)

        AssertThat(r.status_code).IsEqualTo(200)
        AssertThat(r.data).Contains(f"Week - {expected_week}".encode())
コード例 #16
0
    def test_get_week_post_does_not_save_event_on_delete(self, default_user):
        self.__insert_week()
        r = self.client.post(f"/{YEAR}/{WEEK}", data=TEST_DELETE_EVENT)

        AssertThat(r.status_code).IsEqualTo(200)
        event = Event.query.filter_by(title=TEST_DELETE_EVENT["title"]).first()

        AssertThat(event).IsEqualTo(None)
コード例 #17
0
    def test_get_week_get_persists_week_into_db(self, default_user):
        r = self.client.get(f"/{YEAR}/{WEEK}")

        week = Week.query.filter_by(year=YEAR, week_num=WEEK).first()

        AssertThat(r.status_code).IsEqualTo(200)
        AssertThat(week.year).IsEqualTo(YEAR)
        AssertThat(week.week_num).IsEqualTo(WEEK)
コード例 #18
0
    def test_get_week_get_does_not_save_already_existing_week_again(
        self, default_user
    ):
        self.__insert_week()
        r = self.client.get(f"/{YEAR}/{WEEK}")

        weeks = Week.query.filter_by(year=YEAR, week_num=WEEK).all()

        AssertThat(r.status_code).IsEqualTo(200)
        AssertThat(len(weeks)).IsEqualTo(1)
コード例 #19
0
    def test_calculate_different_year_handles_anniversaries_correctly(
        self, year, week, expected_year, expected_week
    ):
        (
            calculated_year,
            calculated_week,
        ) = self.date_time_helper.calculate_different_year(year, week)

        AssertThat(calculated_year).IsEqualTo(expected_year)
        AssertThat(calculated_week).IsEqualTo(expected_week)
コード例 #20
0
ファイル: test_c_types.py プロジェクト: ghandic/6502Emulator
def validate_range(val, min, max):
    AssertThat(val).IsAtMost(max)
    AssertThat(val).IsAtLeast(min)
    AssertThat(val + 1).IsAtMost(max)
    AssertThat(val + 1).IsAtLeast(min)
    AssertThat(val - 1).IsAtMost(max)
    AssertThat(val - 1).IsAtLeast(min)
    AssertThat(val << 8).IsAtMost(max)
    AssertThat(val << 8).IsAtLeast(min)
    AssertThat(val >> 8).IsAtMost(max)
    AssertThat(val >> 8).IsAtLeast(min)
コード例 #21
0
ファイル: test_base.py プロジェクト: beatMeDev/beatMeBackend
async def test_base_auth_route_on_get() -> None:
    """
    Check auth handler on GET will return sign in link for external provider.
    """
    route = get_patched_route()
    route_handler = route.get_route_handler()
    request: Request = await get_auth_request(method="GET")

    response: ORJSONResponse = await route_handler(request)
    response_body = loads(response.body)

    AssertThat(response.status_code).IsEqualTo(200)
    AssertThat(response_body).IsEqualTo({"link": REDIRECT_LINK})
コード例 #22
0
def test_brk_will_push_3_bytes_onto_the_stack(cpu):
    """BRKWillPush3BytesOntoTheStack"""
    cpu.reset_to(0xFF00)
    cpu.Memory[0xFF00] = OpCodes.INS_BRK
    expected_cycles = 7
    cpu_copy = copy.copy(cpu)

    # When:
    cycles_used = cpu.execute(expected_cycles)

    # Then:
    AssertThat(expected_cycles).IsEqualTo(cycles_used)
    AssertThat(cpu.stack_pointer).IsEqualTo(cpu_copy.stack_pointer - 3)
コード例 #23
0
def test_brk_will_set_the_break_flag(cpu):
    """BRKWillSetTheBreakFlag"""
    # Given:
    cpu.reset_to(0xFF00)
    cpu.Flag.B = False
    cpu.Memory[0xFF00] = OpCodes.INS_BRK
    expected_cycles = 7

    # When:
    cycles_used = cpu.execute(expected_cycles)

    # Then:
    AssertThat(expected_cycles).IsEqualTo(cycles_used)
    AssertThat(cpu.Flag.B).IsTruthy()
コード例 #24
0
ファイル: db_week_test.py プロジェクト: kovrichard/mycalendar
    def test_week_and_event_can_be_inserted_and_queried(self):
        event = Event(
            event_type=0,
            title="<event>",
            description="<description>",
            location="<location>",
            start="2020-10-19 00:00:00",
            end="2020-10-19 01:00:00",
        )
        db.session.add(event)
        db.session.add(Week(year=2020, week_num=1, events=[event]))
        db.session.commit()

        AssertThat(len(
            Week.query.filter_by(week_num=1).first().events)).IsEqualTo(1)

        queried_week_event = Week.query.filter_by(week_num=1).first().events[0]

        AssertThat(queried_week_event.event_type).IsEqualTo(event.event_type)
        AssertThat(queried_week_event.title).IsEqualTo(event.title)
        AssertThat(queried_week_event.description).IsEqualTo(event.description)
        AssertThat(queried_week_event.location).IsEqualTo(event.location)
        AssertThat(queried_week_event.start).IsEqualTo(event.start)
        AssertThat(queried_week_event.end).IsEqualTo(event.end)
        AssertThat(queried_week_event.guest_name).IsEqualTo(event.guest_name)
コード例 #25
0
def test_case_RFID_2():
    with allure.step("Send requests to the MQTT"):
        mqtt.req83(ename="RFID_2", etype="text", evalue="99296465799940")
    with allure.step("Send GET request to the server"):
        r = requests.get(TD.url83() + "/get/status")
    with allure.step("LOGGER get info"):
        LOGGER.info(r.json())
        LOGGER.info(r.status_code)
    with allure.step("Assert Contains Item"):
        with allure.step("RFID_2 should have name САМОСВАЛ КАМАЗ 55102"):
            AssertThat(r.json()["result"]["guest"]).ContainsItem(
                "name", "САМОСВАЛ КАМАЗ 55102")
            AssertThat(r.json()["result"]["guest"]).ContainsItem(
                "card_uid", "99296465799940")
コード例 #26
0
def test_worker_parseDate1_generative(mocker, input_date):

    # given
    input_string = input_date.strftime(format="%d%b%Y")
    worker = Worker()

    # when 
    result = worker.parseDate(input_string)
    
    print(input_string, result)
    
    # then
    AssertThat(result).IsInstanceOf(str)
    AssertThat(result).HasSize(10)
    AssertThat(result.split('-')).HasSize(3)
コード例 #27
0
def test_brk_will_load_the_program_counter_from_the_interrupt_vector_2(cpu):
    """BRKWillLoadTheProgramCounterFromTheInterruptVector2"""
    # Given:
    cpu.reset_to(0xFF00)
    cpu.Memory[0xFF00] = OpCodes.INS_BRK
    cpu.Memory[0xFFFE] = 0x00
    cpu.Memory[0xFFFF] = 0x90
    expected_cycles = 7

    # When:
    cycles_used = cpu.execute(expected_cycles)

    # Then:
    AssertThat(expected_cycles).IsEqualTo(cycles_used)
    AssertThat(cpu.program_counter).IsEqualTo(0x9000)
コード例 #28
0
def test_state_machine_transition_invalid_raises_invalid_machine_error(transitions, initial_state, expected_error):
    vid = GenericVideo()
    if expected_error is None:
        vid.set_machine(transitions, initial_state)
    else:
        with AssertThat(expected_error).IsRaised():
            vid.set_machine(transitions, initial_state)
コード例 #29
0
def test_format_track() -> None:
    """Check formatted track has valid format"""
    formatted_track: Optional[Dict[str,
                                   Any]] = format_track(track_info=RAW_TRACK)

    AssertThat(TrackModel(**formatted_track).validate(
        formatted_track)).IsNotEmpty()  # type: ignore
コード例 #30
0
def test_state_change_triggered_on_play_errors_when_moving_from_play():
    vid = GoodVideo()
    assert vid.machine.state == vid.STOPPED
    vid.play()
    assert vid.machine.state == vid.PLAYING
    with AssertThat(MachineError).IsRaised():
        vid.play()