This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from rest_framework.test import APIClient | |
from rest_framework import status | |
from django.urls import reverse | |
from ..models import Blog | |
client = APIClient() | |
class GetSingleBlogTest(TestCase): | |
""" Test module for GET single Blog API """ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import configureMockStore from 'redux-mock-store'; | |
import thunk from 'redux-thunk'; | |
import axios from 'axios'; | |
import MockAdapter from 'axios-mock-adapter'; | |
import * as actions from './actions'; | |
const middleware = [thunk]; | |
const mockStore = configureMockStore(middleware); | |
const mock = new MockAdapter(axios); | |
const store = mockStore(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
describe('post Todos actions', () => { | |
beforeEach(() => { | |
store.clearActions(); | |
}); | |
it('dispatches POST_TODO_SUCCESS after a successfull API requets', () => { | |
mock.onPost('api/todos').reply(201, { response: { item: 'item1' } }) | |
store.dispatch(actions.getTodos()).then(() => { | |
let expectedActions = [ | |
{ type: 'API_REQUEST' }, | |
{ type: 'POST_TODOS_SUCCESS', payload: { item: 'item1' } } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ACTION TYPES | |
export const API_REQUEST = 'API_REQUEST'; | |
export const GET_TODO_SUCCESS = 'GET_TODO_SUCCESS'; | |
export const GET_TODO_FAIL = 'GET_TODO_FAIL'; | |
export const ADD_TODO_SUCCESS = 'ADD_TODO_SUCCESS'; | |
export const ADD_TODO_FAIL = 'ADD_TODO_FAIL'; | |
//ACTION CREATORS | |
export const apiRequestAction = () => ({ | |
type: API_REQUEST |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import axios from 'axios'; | |
import * as actions from './actions'; | |
export const getTodos = () => (dispatch) => { | |
dispatch(actions.apiRequest()); | |
axios.get('api/todos').then(res => { | |
dispatch(actions.getTodoSuccess(res.data)); | |
return res; | |
}) | |
.catch(error => { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ type: ADD_TODO_SUCCESS, payload: { item: 'Todo item' } } | |
{ type: ADD_TODO_FAILURE, payload: {error: 'Bad item'} } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React from 'react'; | |
import styled from 'styled-componets'; | |
const Button = styled.button` | |
cursor: pointer; | |
background: transparent; | |
font-size: 16px; | |
border-radius: 3px; | |
color: palevioletred; | |
border: 2px solid palevioletred; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React from 'react'; | |
import styled from 'styled-componets'; | |
const Button = styled.button` | |
background: ${props => props.primary ? 'blue': 'white'}; | |
color: ${props => props.primary ? 'white' : 'green} | |
cursor: pointer; | |
font-size: 16px; | |
border-radius: 3px; | |
border: 2px solid palevioletred; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React from 'react'; | |
import styled, { ThemeProvider } from 'styled-componets'; | |
const theme = { | |
text: '#ffff', | |
dark: '#0000' | |
} | |
const CustomButton = styled.button` | |
background-color: ${props => props.theme.dark}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#Witness of The Tall People | |
def witnesses(heights): | |
max_height = float('-inf') | |
total = 0 | |
for i in range(len(heights) - 1, -1, -1): | |
if heights[i] > max_height: | |
total += 1 | |
max_height = max(heights[i], max_height) | |
return total |
OlderNewer