示例#1
0
def _make_submission(id: int, **kwargs) -> SubmissionModel:
    """Make a SubmissionModel with default values overridable by kwargs."""
    return SubmissionModel(
        pk="fred_bloggs",
        sk=table.get_submission_sk(id),
        url=f"https://github.com/newtheatre/history-project/issues/{id}",
        target_id="00_01/romeo_and_juliet",
        target_name="Romeo and Juliet",
        target_type="show",
        message="The part of Romeo was played by a hamster.",
        created_at=dates.now(),
        submitter=SubmitterModel(
            id="fred_bloggs",
            name="Fred Bloggs",
            verified=True,
        ),
        github_issue=GitHubIssueModel(
            number=id,
            state="open",
            title="Romeo and Juliet",
            created_at=dates.now(),
            updated_at=dates.now(),
            closed_at=None,
            comments=0,
        ),
    ).copy(update=kwargs)
示例#2
0
def check_github() -> HealthCheckCondition:
    try:
        # Check if GitHub is available by grabbing the content repo
        lumina.github.connection.get_content_repo()
        return HealthCheckCondition(
            ok=True,
            timestamp=dates.now(),
        )
    except BadCredentialsException:
        return HealthCheckCondition(
            ok=False,
            timestamp=dates.now(),
            message="Bad credentials",
        )
    except botocore.exceptions.ClientError as e:
        log.error(e)
        return HealthCheckCondition(
            ok=False,
            timestamp=dates.now(),
            message="Cannot get credentials",
        )
    except Exception as e:
        log.error(e)
        return HealthCheckCondition(
            ok=False,
            timestamp=dates.now(),
            message="Unknown error",
        )
示例#3
0
def check_dynamodb() -> HealthCheckCondition:
    try:
        # Check if dynamodb is available by attempting fetch of a member
        try:
            operations.get_member("fred_bloggs")
        except ResultNotFound:
            # We don't expect member to exist
            pass
        return HealthCheckCondition(
            ok=True,
            timestamp=dates.now(),
        )
    except botocore.exceptions.ClientError as e:
        log.error(e)
        return HealthCheckCondition(
            ok=False,
            timestamp=dates.now(),
            message="ClientError",
        )
    except Exception as e:
        log.error(e)
        return HealthCheckCondition(
            ok=False,
            timestamp=dates.now(),
            message="Unknown error",
        )
示例#4
0
def check_ssm() -> HealthCheckCondition:
    try:
        # Check if the SSM service is available by grabbing a known key
        ssm.get_parameter("/lumina/jwt/public")
        return HealthCheckCondition(
            ok=True,
            timestamp=dates.now(),
        )
    except ValueError:
        return HealthCheckCondition(
            ok=False,
            timestamp=dates.now(),
            message="Parameter not found",
        )
    except botocore.exceptions.ClientError as e:
        log.error(e)
        return HealthCheckCondition(
            ok=False,
            timestamp=dates.now(),
            message="ClientError",
        )
    except Exception as e:
        log.error(e)
        return HealthCheckCondition(
            ok=False,
            timestamp=dates.now(),
            message="Unknown error",
        )
示例#5
0
def set_member_email_verified(id: str) -> None:
    get_member_table().update_item(
        Key={
            MEMBER_PARTITION_KEY: id,
            MEMBER_SORT_KEY: SK_PROFILE
        },
        UpdateExpression="set email_verified_at = :v",
        ExpressionAttributeValues={":v": dates.now().isoformat()},
    )
示例#6
0
 def test_move_anonymous_submissions(
         self, mock_move_anonymous_submissions_to_member, auth_fred_bloggs):
     auth_fred_bloggs.email_verified_at = dates.now()
     auth_fred_bloggs.anonymous_ids = [uuid.uuid4()]
     response = client.get("/member/fred_bloggs")
     # We don't call set_member_email_verified as email is already verified
     assert response.status_code == HTTPStatus.OK, response.json()
     assert mock_move_anonymous_submissions_to_member.called
     assert response.json() == {
         "email": "*****@*****.**",
         "emailVerified": True,
         "id": "fred_bloggs",
     }
示例#7
0
 def test_do_not_verify_if_already_verified(self,
                                            mock_set_member_email_verified,
                                            auth_fred_bloggs):
     auth_fred_bloggs.email_verified_at = dates.now()
     response = client.get("/member/fred_bloggs")
     assert response.status_code == HTTPStatus.OK, response.json()
     # We don't call set_member_email_verified as email is already verified
     assert not mock_set_member_email_verified.called
     assert response.json() == {
         "email": "*****@*****.**",
         "emailVerified": True,
         "id": "fred_bloggs",
     }
示例#8
0
def test_update_submission_github_issue():
    new_submission = operations.put_submission(_make_submission(101))
    assert new_submission.github_issue.state == GitHubIssueState.OPEN
    assert new_submission.github_issue.closed_at is None
    assert new_submission.github_issue.comments == 0
    to_close_at = dates.now()
    operations.update_submission_github_issue(
        101,
        new_submission.github_issue.copy(update=dict(
            state=GitHubIssueState.CLOSED, comments=5, closed_at=to_close_at)),
    )
    updated_submission = operations.get_submission(101)
    assert updated_submission.github_issue.state == GitHubIssueState.CLOSED
    assert updated_submission.github_issue.closed_at == to_close_at
    assert updated_submission.github_issue.comments == 5
示例#9
0
 def to_model(
     self,
     *,
     submission_id: int,
     submitter_id: Union[str, UUID],
     member: Optional[MemberModel],
     github_issue: Issue,
 ) -> SubmissionModel:
     return SubmissionModel(
         pk=str(submitter_id),
         sk=get_submission_sk(submission_id),
         url=self.target_url,
         target_id=self.target_id,
         target_type=self.target_type,
         target_name=self.target_name,
         created_at=dates.now(),
         message=self.message,
         submitter=member.to_submitter()
         if member else self.submitter.to_model(),
         github_issue=lumina.github.submissions.make_issue_model(
             github_issue),
     )