Skip to content

Instantly share code, notes, and snippets.

View LarryKarani's full-sized avatar
😀
Life is too short to write bad code

Larry karani LarryKarani

😀
Life is too short to write bad code
View GitHub Profile
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 """
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();
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' } }
// 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
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 => {
{ type: ADD_TODO_SUCCESS, payload: { item: 'Todo item' } }
{ type: ADD_TODO_FAILURE, payload: {error: 'Bad item'} }
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;
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;
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};
#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